ProjectReport.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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: 'ProjectReport',
  79. components: {},
  80. data () {
  81. return {
  82. user: {},
  83. loading: false,
  84. reportId: 0,
  85. projectId: '',
  86. taskId: '',
  87. isModifyMode: false,
  88. reportType: [],
  89. report: {
  90. name: '',
  91. type: '',
  92. description: '',
  93. target: '',
  94. content: '',
  95. file: [],
  96. fileUrl: '',
  97. conclusion: ''
  98. },
  99. operational:'',
  100. rules: {
  101. name: [
  102. {required: true, message: '任务名称不可为空', trigger: 'blur'},
  103. {min: 5, max: 50, message: '报告名称长度在 5 到 50 个字符', trigger: 'blur'}
  104. ],
  105. type: [
  106. {required: true, message: '报告类型不可为空'},
  107. ],
  108. target: [
  109. {required: true, message: '测试对象不可为空', trigger: 'blur'}
  110. ],
  111. content: [
  112. {required: true, message: '测试内容不可为空', trigger: 'blur'}
  113. ],
  114. conclusion: [
  115. {required: true, message: '结论不可为空', trigger: 'blur'}
  116. ]
  117. }
  118. }
  119. },
  120. mounted () {
  121. this.$nextTick(() => {
  122. this.init()
  123. })
  124. },
  125. methods: {
  126. init () {
  127. this.reportId = this.$route.params.reportId
  128. this.projectId = this.$route.params.projectId
  129. this.taskId = this.$route.params.taskId
  130. this.setReportType()
  131. this.setUserInfo()
  132. this.loadData()
  133. },
  134. modifyForm () {
  135. this.isModifyMode = true
  136. },
  137. submitForm (formName) {
  138. this.$refs['report'].validate(valid => {
  139. if (valid) {
  140. this.isModifyMode = false
  141. this.showLoading()
  142. const newReport = {
  143. name: this.report.name,
  144. scope: this.taskId == null ? 0 : 1,
  145. type: this.report.type,
  146. dependencyCode: this.taskId == null ? this.projectId : this.taskId,
  147. target: this.report.target,
  148. content: this.report.content,
  149. file: '123.pdf',
  150. conclusion: this.report.conclusion
  151. }
  152. console.log(newReport)
  153. Http.put(Apis.REPORT.UPDATE_PROJECT_REPORT.replace('{projectId}', this.projectId).replace('{reportId}', this.reportId), newReport).then((res) => {
  154. console.log(res)
  155. notify('success', '修改成功')
  156. this.hideLoading()
  157. this.isModifyMode = false
  158. }).catch((error) => {
  159. this.hideLoading()
  160. notify('error', error.data)
  161. })
  162. //提交 report
  163. } else {
  164. notify('error', '表单填写有误')
  165. return false
  166. }
  167. })
  168. },
  169. resetForm (formName) {
  170. this.$refs[formName].resetFields()
  171. this.report.name = ''
  172. this.report.target = ''
  173. this.report.content = ''
  174. this.report.file = ''
  175. this.report.type = ''
  176. this.report.conclusion = ''
  177. },
  178. cancelCreate () {
  179. this.isModifyMode = false
  180. //请求 report
  181. },
  182. handleRemove (file, fileList) {
  183. console.log(file, fileList)
  184. },
  185. handleExceed (files, fileList) {
  186. this.$message.warning(
  187. `当前限制选择 1 个文件,本次选择了 ${
  188. files.length
  189. } 个文件,共选择了 ${files.length + fileList.length} 个文件`
  190. )
  191. },
  192. beforeRemove (file, fileList) {
  193. //return this.$confirm(`确定移除 ${file.name}?`)
  194. },
  195. beforeFileUpload (file) {
  196. /*
  197. console.log(file)
  198. const isPDF = file.type === 'application/pdf'
  199. const isDOC = file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
  200. const isEXCEL = file.type === 'application/vnd.ms-excel'
  201. const isXLS = file.type === 'application/x-xls'
  202. const isTXT = file.type === 'text/plain'
  203. const isXLSX = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  204. //console.log(file)
  205. if (!(isDOC || isEXCEL || isPDF || isTXT || isXLS || isXLSX)) {
  206. this.$message.error('上传文件只能是 PDF 、 DOC 、DOCX 、XLS、TXT、XLSX 格式!')
  207. }
  208. return isDOC || isEXCEL || isPDF || isTXT || isXLS || isXLSX
  209. */
  210. },
  211. back () {
  212. this.$router.push({
  213. name: 'Project',
  214. params: {projectId: this.projectId}
  215. })
  216. },
  217. loadData () {
  218. //pro1564487183259
  219. //pro1564487183259_task1564487274060
  220. //pro1564487183259pro1564487183259_task1564487274060_rep1564488510500
  221. this.showLoading()
  222. Http.get(Apis.REPORT.GET_PROJECT_REPORT.replace('{projectId}', this.projectId).replace('{reportId}', this.reportId)).then((res) => {
  223. this.report.name = res.crowdReportVO.name
  224. this.report.crowdTestTaskId = res.crowdReportVO.crowdTestTaskId
  225. this.report.scope = res.crowdReportVO.scope
  226. this.report.type = res.crowdReportVO.type
  227. this.report.description = res.crowdReportVO.description
  228. this.report.content = res.crowdReportVO.content
  229. this.report.fileUrl = res.crowdReportVO.file
  230. this.report.conclusion = res.crowdReportVO.conclusion
  231. this.report.target = res.crowdReportVO.target
  232. this.operational = res.operational
  233. this.hideLoading()
  234. //notify('success', '修改成功')
  235. }).catch((error) => {
  236. this.hideLoading()
  237. notify('error', '打开报告失败:' + error.data)
  238. })
  239. },
  240. uploadReportFile (param) {
  241. this.showLoading()
  242. const formData = new FormData()
  243. let config = {
  244. //添加请求头
  245. headers: {'Content-Type': 'multipart/form-data'},
  246. }
  247. formData.append('file', param.file)
  248. Http.upload(Apis.FILE.UPLOAD_REPORT_FILE.replace('{userId}', this.user.userVO.id), formData, config).then((res) => {
  249. console.log('上传成功')
  250. this.report.fileUrl = res.data
  251. console.log(res)
  252. this.hideLoading()
  253. }).catch((error) => {
  254. this.hideLoading()
  255. notify('error', '文件上传失败:' + error.data)
  256. })
  257. },
  258. setReportType () {
  259. getAllReportTypes().then((res) => {
  260. this.reportType = res
  261. }).catch((error) => {
  262. notify('error', '加载报告类型失败')
  263. })
  264. },
  265. setUserInfo () {
  266. this.user = storageGet('user')
  267. },
  268. updateReportSuccess () {
  269. },
  270. showLoading () {
  271. this.loading = true
  272. },
  273. hideLoading () {
  274. this.loading = false
  275. }
  276. },
  277. watch: {
  278. reportType (val) {
  279. this.reportType = val
  280. }
  281. }
  282. }
  283. </script>
  284. <style lang="less" scoped>
  285. .el-radio {
  286. margin: 10px 20px 10px 0;
  287. }
  288. .el-form-item /deep/ .el-tabs__content {
  289. max-height: 120px !important;
  290. overflow: auto;
  291. }
  292. .el-row {
  293. margin-bottom: 10px;
  294. }
  295. </style>