Report.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. <template>
  2. <div class="create-container">
  3. <div class="create-body">
  4. <el-form :model="report" :rules="rules" ref="report" label-width="12%" class="demo-report">
  5. <el-form-item label="报告名称" prop="name">
  6. <el-input v-if="isModifyMode" v-model="report.name"></el-input>
  7. <span v-if="!isModifyMode">{{report.name}}</span>
  8. </el-form-item>
  9. <el-form-item label="报告类型" prop="type">
  10. <el-radio-group v-if="isModifyMode" v-model="report.type">
  11. <el-radio :label="0" name="type">{{ serviceType[0] }}</el-radio>
  12. <el-radio :label="1" name="type">{{ serviceType[1] }}</el-radio>
  13. <el-radio :label="2" name="type">{{ serviceType[2] }}</el-radio>
  14. <el-radio :label="3" name="type">{{ serviceType[3] }}</el-radio>
  15. <el-radio :label="4" name="type">{{ serviceType[4] }}</el-radio>
  16. <el-radio :label="5" name="type">{{ serviceType[5] }}</el-radio>
  17. </el-radio-group>
  18. <span v-if="!isModifyMode" class="badge">{{serviceType[report.type]}}</span>
  19. </el-form-item>
  20. <el-form-item label="摘要" prop="abstract">
  21. <div>
  22. <el-row :gutter="2">
  23. <el-col :span="2">
  24. <span>测试对象</span>
  25. </el-col>
  26. <el-col :span="10">
  27. <el-input v-if="isModifyMode" type="textarea" v-model="report.target"></el-input>
  28. <span v-if="!isModifyMode">{{report.target}}</span>
  29. </el-col>
  30. </el-row>
  31. <el-row :gutter="2">
  32. <el-col :span="2">
  33. <span>测试内容</span>
  34. </el-col>
  35. <el-col :span="10">
  36. <el-input v-if="isModifyMode" type="textarea" v-model="report.content"></el-input>
  37. <span v-if="!isModifyMode">{{report.content}}</span>
  38. </el-col>
  39. </el-row>
  40. </div>
  41. </el-form-item>
  42. <el-form-item prop="file" label="报告文件">
  43. <el-upload
  44. v-if="isModifyMode"
  45. drag
  46. class="upload-demo"
  47. action=""
  48. :on-remove="handleRemove"
  49. :before-remove="beforeRemove"
  50. multiple
  51. :limit="1"
  52. :on-exceed="handleExceed"
  53. :before-upload="beforeFileUpload"
  54. :file-list="report.file"
  55. :http-request="uploadReportFile"
  56. >
  57. <i class="el-icon-upload"></i>
  58. <div class="el-upload__text">
  59. 将文件拖到此处,或
  60. <em>点击上传</em>
  61. </div>
  62. <div class="el-upload__tip" slot="tip">请上传报告文件</div>
  63. </el-upload>
  64. <div v-if="!isModifyMode">
  65. <span v-if="report.fileUrl==null">暂无文件</span>
  66. <a :href="report.fileUrl" v-if="report.fileUrl!=null"><i class="fa fa-file-text-o"></i>
  67. {{report.fileUrl}}</a>
  68. </div>
  69. </el-form-item>
  70. <el-form-item label="结论" prop="conclusion">
  71. <el-input v-if="isModifyMode" type="textarea" v-model="report.conclusion"></el-input>
  72. <span v-if="!isModifyMode">{{report.conclusion}}</span>
  73. </el-form-item>
  74. <el-form-item v-if="!isModifyMode">
  75. <div class="btn btn-medium btn-info" @click="modifyForm()">修改</div>
  76. <div class="btn btn-medium" @click="back()">返回</div>
  77. </el-form-item>
  78. <el-form-item v-if="isModifyMode">
  79. <div class="btn btn-primary btn-info" @click="submitForm('report')">确认修改</div>
  80. <div class="btn btn-primary" @click="resetForm('report')">重置</div>
  81. <div class="btn btn-primary" @click="cancelCreate('report')">取消</div>
  82. </el-form-item>
  83. </el-form>
  84. </div>
  85. </div>
  86. </template>
  87. <script>
  88. import Http from '@/js/http.js'
  89. import Apis from '@/js/api.js'
  90. import ServiceType from '@/constants/enum/service-type'
  91. import {notify} from '@/constants/index'
  92. export default {
  93. name: 'Report-Create',
  94. components: {},
  95. data () {
  96. return {
  97. reportId: 0,
  98. projectId: '',
  99. taskId: '',
  100. isModifyMode: false,
  101. serviceType: ServiceType,
  102. report: {
  103. name: '',
  104. type: '',
  105. description: '',
  106. target: '',
  107. content: '',
  108. file: [],
  109. fileUrl: '',
  110. conclusion: ''
  111. },
  112. rules: {
  113. // name: [
  114. // {required: true, message: '请输入报告名称', trigger: 'blur'}
  115. // // { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" }
  116. // ],
  117. // abstract: [
  118. // {
  119. // required: true,
  120. // message: '请输入摘要信息',
  121. // trigger: 'change'
  122. // }
  123. // ],
  124. // type: [
  125. // {required: true, message: '请选择报告类型', trigger: 'change'}
  126. // ],
  127. // conclusion: [
  128. // {required: true, message: '请输入报告结论', trigger: 'blur'}
  129. // ]
  130. }
  131. }
  132. },
  133. mounted () {
  134. this.$nextTick(() => {
  135. this.init()
  136. })
  137. },
  138. methods: {
  139. init () {
  140. this.reportId = this.$route.params.reportId
  141. this.projectId = this.$route.params.projectId
  142. this.taskId = this.$route.params.taskId
  143. this.loadData()
  144. },
  145. modifyForm () {
  146. this.isModifyMode = true
  147. },
  148. submitForm (formName) {
  149. const newReport = {
  150. name: this.report.name,
  151. scope: this.taskId == null ? 0 : 1,
  152. type: this.report.type,
  153. dependencyCode: this.taskId == null ? this.projectId : this.taskId,
  154. target: this.report.target,
  155. content: this.report.content,
  156. file: '123.pdf',
  157. conclusion: this.report.conclusion
  158. }
  159. console.log(newReport)
  160. if (this.taskId == null) {
  161. Http.put(Apis.REPORT.UPDATE_PROJECT_REPORT.replace('{projectId}', this.projectId).replace('{reportId}', this.reportId), newReport).then((res) => {
  162. console.log(res)
  163. })
  164. } else {
  165. Http.put(Apis.REPORT.UPDATE_TASK_REPORT.replace('{projectId}', this.projectId).replace('{taskId}', this.taskId).replace('{reportId}', this.reportId), newReport).then((res) => {
  166. console.log(res)
  167. })
  168. }
  169. // this.$refs[formName].validate(valid => {
  170. // if (valid) {
  171. // this.isModifyMode = false
  172. //
  173. // //提交 report
  174. // } else {
  175. // console.log('error submit!!')
  176. // return false
  177. // }
  178. // })
  179. },
  180. resetForm (formName) {
  181. this.$refs[formName].resetFields()
  182. this.report.name = ''
  183. this.report.target = ''
  184. this.report.content = ''
  185. this.report.file = ''
  186. this.report.type = ''
  187. this.report.conclusion = ''
  188. },
  189. cancelCreate () {
  190. this.isModifyMode = false
  191. //请求 report
  192. },
  193. handleRemove (file, fileList) {
  194. console.log(file, fileList)
  195. },
  196. handleExceed (files, fileList) {
  197. this.$message.warning(
  198. `当前限制选择 1 个文件,本次选择了 ${
  199. files.length
  200. } 个文件,共选择了 ${files.length + fileList.length} 个文件`
  201. )
  202. },
  203. beforeRemove (file, fileList) {
  204. //return this.$confirm(`确定移除 ${file.name}?`)
  205. },
  206. beforeFileUpload (file) {
  207. console.log(file)
  208. const isPDF = file.type === 'application/pdf'
  209. const isDOC = file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
  210. const isEXCEL = file.type === 'application/vnd.ms-excel'
  211. const isXLS = file.type === 'application/x-xls'
  212. const isTXT = file.type === 'text/plain'
  213. const isXLSX = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  214. //console.log(file)
  215. if (!(isDOC || isEXCEL || isPDF || isTXT || isXLS || isXLSX)) {
  216. this.$message.error('上传文件只能是 PDF 、 DOC 、DOCX 、XLS、TXT、XLSX 格式!')
  217. }
  218. return isDOC || isEXCEL || isPDF || isTXT || isXLS || isXLSX
  219. },
  220. back () {
  221. if (window.history.length <= 1) {
  222. this.$router.push({path: '/'})
  223. return false
  224. } else {
  225. this.$router.go(-1)
  226. }
  227. },
  228. loadData () {
  229. //pro1564487183259
  230. //pro1564487183259_task1564487274060
  231. //pro1564487183259pro1564487183259_task1564487274060_rep1564488510500
  232. console.log('***')
  233. console.log(this.projectId)
  234. console.log(this.taskId)
  235. console.log(this.reportId)
  236. console.log('***')
  237. if (this.taskId == null) {
  238. Http.get(Apis.REPORT.GET_PROJECT_REPORT.replace('{projectId}', this.projectId).replace('{reportId}', this.reportId)).then((res) => {
  239. console.log(res)
  240. this.report.name = res.crowdReportVO.name
  241. this.report.crowdTestTaskId = res.crowdReportVO.crowdTestTaskId
  242. this.report.scope = res.crowdReportVO.scope
  243. this.report.type = res.crowdReportVO.type
  244. this.report.description = res.crowdReportVO.description
  245. this.report.content = res.crowdReportVO.content
  246. this.report.fileUrl = res.crowdReportVO.file
  247. this.report.conclusion = res.crowdReportVO.conclusion
  248. this.report.target = res.crowdReportVO.target
  249. })
  250. } else {
  251. Http.get(Apis.REPORT.GET_TASK_REPORT.replace('{projectId}', this.projectId).replace('{taskId}', this.taskId).replace('{reportId}', this.reportId)).then((res) => {
  252. console.log(res)
  253. this.report.name = res.crowdReportVO.name
  254. this.report.crowdTestTaskId = res.crowdReportVO.crowdTestTaskId
  255. this.report.scope = res.crowdReportVO.scope
  256. this.report.type = res.crowdReportVO.type
  257. this.report.description = res.crowdReportVO.description
  258. this.report.content = res.crowdReportVO.content
  259. this.report.fileUrl = res.crowdReportVO.file
  260. this.report.conclusion = res.crowdReportVO.conclusion
  261. this.report.target = res.crowdReportVO.target
  262. })
  263. }
  264. },
  265. uploadReportFile (param) {
  266. const formData = new FormData()
  267. let config = {
  268. //添加请求头
  269. headers: {'Content-Type': 'multipart/form-data'},
  270. }
  271. formData.append('file', param.file)
  272. Http.upload(Apis.FILE.UPLOAD_REPORT_FILE.replace('{userId}', 3), formData, config).then((res) => {
  273. console.log('上传成功')
  274. this.report.fileUrl = res.data
  275. console.log(res)
  276. })
  277. }
  278. }
  279. }
  280. </script>
  281. <style lang="less" scoped>
  282. .el-radio {
  283. margin: 10px 20px 10px 0;
  284. }
  285. .el-form-item /deep/ .el-tabs__content {
  286. max-height: 120px !important;
  287. overflow: auto;
  288. }
  289. .el-row {
  290. margin-bottom: 10px;
  291. }
  292. </style>