ProjectReport.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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-medium btn-info" @click="submitForm('report')">确认修改</div>
  78. <div class="btn btn-medium" @click="resetForm('report')">重置</div>
  79. <div class="btn btn-medium" @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: 'ProjectReport',
  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_PROJECT_REPORT.replace('{projectId}', this.projectId).replace('{reportId}', this.reportId), newReport).then((res) => {
  164. console.log(res)
  165. notify('success', '修改成功')
  166. this.hideLoading()
  167. this.isModifyMode = false
  168. }).catch((error) => {
  169. this.hideLoading()
  170. notify('error', error.data)
  171. })
  172. // this.$refs[formName].validate(valid => {
  173. // if (valid) {
  174. // this.isModifyMode = false
  175. //
  176. // //提交 report
  177. // } else {
  178. // console.log('error submit!!')
  179. // return false
  180. // }
  181. // })
  182. },
  183. resetForm (formName) {
  184. this.$refs[formName].resetFields()
  185. this.report.name = ''
  186. this.report.target = ''
  187. this.report.content = ''
  188. this.report.file = ''
  189. this.report.type = ''
  190. this.report.conclusion = ''
  191. },
  192. cancelCreate () {
  193. this.isModifyMode = false
  194. //请求 report
  195. },
  196. handleRemove (file, fileList) {
  197. console.log(file, fileList)
  198. },
  199. handleExceed (files, fileList) {
  200. this.$message.warning(
  201. `当前限制选择 1 个文件,本次选择了 ${
  202. files.length
  203. } 个文件,共选择了 ${files.length + fileList.length} 个文件`
  204. )
  205. },
  206. beforeRemove (file, fileList) {
  207. //return this.$confirm(`确定移除 ${file.name}?`)
  208. },
  209. beforeFileUpload (file) {
  210. console.log(file)
  211. const isPDF = file.type === 'application/pdf'
  212. const isDOC = file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
  213. const isEXCEL = file.type === 'application/vnd.ms-excel'
  214. const isXLS = file.type === 'application/x-xls'
  215. const isTXT = file.type === 'text/plain'
  216. const isXLSX = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  217. //console.log(file)
  218. if (!(isDOC || isEXCEL || isPDF || isTXT || isXLS || isXLSX)) {
  219. this.$message.error('上传文件只能是 PDF 、 DOC 、DOCX 、XLS、TXT、XLSX 格式!')
  220. }
  221. return isDOC || isEXCEL || isPDF || isTXT || isXLS || isXLSX
  222. },
  223. back () {
  224. if (window.history.length <= 1) {
  225. this.$router.push({path: '/'})
  226. return false
  227. } else {
  228. this.$router.go(-1)
  229. }
  230. },
  231. loadData () {
  232. //pro1564487183259
  233. //pro1564487183259_task1564487274060
  234. //pro1564487183259pro1564487183259_task1564487274060_rep1564488510500
  235. this.showLoading()
  236. Http.get(Apis.REPORT.GET_PROJECT_REPORT.replace('{projectId}', this.projectId).replace('{reportId}', this.reportId)).then((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. //notify('success', '修改成功')
  248. }).catch((error) => {
  249. this.hideLoading()
  250. notify('error', '打开报告失败:' + error.data)
  251. })
  252. },
  253. uploadReportFile (param) {
  254. this.showLoading()
  255. const formData = new FormData()
  256. let config = {
  257. //添加请求头
  258. headers: {'Content-Type': 'multipart/form-data'},
  259. }
  260. formData.append('file', param.file)
  261. Http.upload(Apis.FILE.UPLOAD_REPORT_FILE.replace('{userId}', this.user.userVO.id), formData, config).then((res) => {
  262. console.log('上传成功')
  263. this.report.fileUrl = res.data
  264. console.log(res)
  265. this.hideLoading()
  266. }).catch((error) => {
  267. this.hideLoading()
  268. notify('error', '文件上传失败:' + error.data)
  269. })
  270. },
  271. setReportType () {
  272. getAllReportTypes().then((res) => {
  273. this.reportType = res
  274. }).catch((error) => {
  275. notify('error', '加载报告类型失败')
  276. })
  277. },
  278. setUserInfo () {
  279. this.user = storageGet('user')
  280. },
  281. updateReportSuccess () {
  282. },
  283. showLoading () {
  284. this.loading = true
  285. },
  286. hideLoading () {
  287. this.loading = false
  288. }
  289. },
  290. watch: {
  291. reportType (val) {
  292. this.reportType = val
  293. }
  294. }
  295. }
  296. </script>
  297. <style lang="less" scoped>
  298. .el-radio {
  299. margin: 10px 20px 10px 0;
  300. }
  301. .el-form-item /deep/ .el-tabs__content {
  302. max-height: 120px !important;
  303. overflow: auto;
  304. }
  305. .el-row {
  306. margin-bottom: 10px;
  307. }
  308. </style>