TaskReport.vue 10 KB

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