TaskReport.vue 10 KB

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