ProjectReportCreate.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <div class="create-container" v-loading="loading">
  3. <div class="title h1">创建报告</div>
  4. <div class="create-body">
  5. <el-form :model="report" :rules="rules" ref="report" label-width="12%" class="demo-report">
  6. <el-form-item label="报告名称" prop="name">
  7. <el-input size="small" v-model="report.name"></el-input>
  8. </el-form-item>
  9. <el-form-item label="报告类型" prop="type">
  10. <el-radio-group 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. </el-form-item>
  16. <el-form-item label="测试对象" prop="name">
  17. <el-input autosize style="width: 400px" type="textarea" v-model="report.target"></el-input>
  18. </el-form-item>
  19. <el-form-item label="测试内容" prop="name">
  20. <el-input autosize style="width: 400px" type="textarea" v-model="report.content"></el-input>
  21. </el-form-item>
  22. <!--<el-form-item label="摘要" prop="abstract">-->
  23. <!--<div>-->
  24. <!--<el-row :gutter="2">-->
  25. <!--<el-col :span="2">-->
  26. <!--<span>测试对象</span>-->
  27. <!--</el-col>-->
  28. <!--<el-col :span="10">-->
  29. <!--<el-input type="textarea" v-model="report.target"></el-input>-->
  30. <!--</el-col>-->
  31. <!--</el-row>-->
  32. <!--<el-row :gutter="2">-->
  33. <!--<el-col :span="2">-->
  34. <!--<span>测试内容</span>-->
  35. <!--</el-col>-->
  36. <!--<el-col :span="10">-->
  37. <!--<el-input type="textarea" v-model="report.content"></el-input>-->
  38. <!--</el-col>-->
  39. <!--</el-row>-->
  40. <!--</div>-->
  41. <!--</el-form-item>-->
  42. <el-form-item prop="file" label="报告文件">
  43. <el-upload
  44. style="width: 400px"
  45. drag
  46. class="upload-demo"
  47. action="https://jsonplaceholder.typicode.com/posts/"
  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. </el-upload>
  63. </el-form-item>
  64. <el-form-item label="结论" prop="conclusion">
  65. <el-input autosize style="width: 400px" type="textarea" v-model="report.conclusion"></el-input>
  66. </el-form-item>
  67. <el-form-item>
  68. <div class="btn btn-medium btn-info" @click="submitForm('report')">提交</div>
  69. <!--<div class="btn btn-medium" @click="resetForm('report')">重置</div>-->
  70. <div class="btn btn-medium" @click="cancelCreate('report')">取消</div>
  71. </el-form-item>
  72. </el-form>
  73. </div>
  74. </div>
  75. </template>
  76. <script>
  77. import Http from '@/js/http.js'
  78. import Apis from '@/js/api.js'
  79. import {notify} from '@/constants/index'
  80. import {getAllReportTypes, storageGet} from '@/js/index'
  81. export default {
  82. name: 'ProjectReportCreate',
  83. components: {},
  84. data () {
  85. return {
  86. user: {},
  87. reportType: [],
  88. loading: false,
  89. scope: 0,
  90. projectId: '',
  91. taskId: '',
  92. dependencyCode: '',
  93. report: {
  94. name: '',
  95. target: '',
  96. content: '',
  97. file: [],
  98. fileUrl: '',
  99. type: '',
  100. conclusion: ''
  101. },
  102. rules: {
  103. name: [
  104. {required: true, message: '任务名称不可为空', trigger: 'blur'},
  105. {min: 5, max: 50, message: '报告名称长度在 5 到 50 个字符', trigger: 'blur'}
  106. ],
  107. type: [
  108. {required: true, message: '报告类型不可为空'},
  109. ],
  110. target: [
  111. {required: true, message: '测试对象不可为空', trigger: 'blur'}
  112. ],
  113. content: [
  114. {required: true, message: '测试内容不可为空', trigger: 'blur'}
  115. ],
  116. conclusion: [
  117. {required: true, message: '结论不可为空', trigger: 'blur'}
  118. ]
  119. }
  120. }
  121. },
  122. mounted () {
  123. this.$nextTick(() => {
  124. this.init()
  125. })
  126. },
  127. methods: {
  128. init () {
  129. this.scope = this.$route.params.scope
  130. this.dependencyCode = this.$route.params.dependencyCode
  131. this.projectId = this.$route.params.projectId
  132. this.taskId = this.$route.params.taskId
  133. this.setUserInfo()
  134. this.setReportType()
  135. },
  136. submitForm (formName) {
  137. this.$refs['report'].validate(valid => {
  138. if (valid) {
  139. this.showLoading()
  140. const newReport = {
  141. name: this.report.name,
  142. scope: this.scope,
  143. type: this.report.type,
  144. dependencyCode: this.dependencyCode,
  145. target: this.report.target,
  146. content: this.report.content,
  147. file: this.report.fileUrl,
  148. conclusion: this.report.conclusion
  149. }
  150. console.log(newReport)
  151. Http.post(Apis.REPORT.CREATE_PROJECT_REPORT.replace('{projectId}', this.projectId), newReport).then((res) => {
  152. this.hideLoading()
  153. this.createReportSuccess(res.crowdReportVO.code)
  154. }).catch((error) => {
  155. this.hideLoading()
  156. notify('error', '报告创建失败:' + error.data)
  157. })
  158. //提交 report
  159. } else {
  160. notify('error', '表单填写有误')
  161. return false
  162. }
  163. })
  164. },
  165. resetForm (formName) {
  166. this.$refs[formName].resetFields()
  167. this.report.name = ''
  168. this.report.abstract.target = ''
  169. this.report.abstract.content = ''
  170. this.report.file = []
  171. this.report.type = ''
  172. this.report.conclusion = ''
  173. },
  174. cancelCreate () {
  175. if (window.history.length <= 1) {
  176. this.$router.push({path: '/'})
  177. return false
  178. } else {
  179. this.$router.go(-1)
  180. }
  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. console.log(file)
  197. const isPDF = file.type === 'application/pdf'
  198. const isDOC = file.type === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
  199. const isEXCEL = file.type === 'application/vnd.ms-excel'
  200. const isXLS = file.type === 'application/x-xls'
  201. const isTXT = file.type === 'text/plain'
  202. const isXLSX = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  203. //console.log(file)
  204. if (!(isDOC || isEXCEL || isPDF || isTXT || isXLS || isXLSX)) {
  205. this.$message.error('上传文件只能是 PDF 、 DOC 、DOCX 、XLS、TXT、XLSX 格式!')
  206. }
  207. return isDOC || isEXCEL || isPDF || isTXT || isXLS || isXLSX
  208. },
  209. loadData () {
  210. },
  211. uploadReportFile (param) {
  212. const formData = new FormData()
  213. let config = {
  214. //添加请求头
  215. headers: {'Content-Type': 'multipart/form-data'},
  216. }
  217. formData.append('file', param.file)
  218. Http.upload(Apis.FILE.UPLOAD_REPORT_FILE.replace('{userId}', this.user.userVO.id), formData, config).then((res) => {
  219. console.log('上传成功')
  220. this.report.fileUrl = res.data
  221. console.log(res)
  222. })
  223. },
  224. setReportType () {
  225. this.reportType = getAllReportTypes().then((res) => {
  226. this.reportType = res
  227. }).catch((error) => {
  228. notify('error', '获取报告类型列表失败')
  229. })
  230. },
  231. setUserInfo () {
  232. this.user = storageGet('user')
  233. },
  234. createReportSuccess (reportId) {
  235. this.$alert('报告创建成功', '创建成功', {
  236. confirmButtonText: '确定',
  237. callback: action => {
  238. this.$router.push({
  239. name: 'ProjectReport',
  240. params: {reportId: reportId, projectId: this.projectId}
  241. })
  242. }
  243. })
  244. },
  245. showLoading () {
  246. this.loading = true
  247. },
  248. hideLoading () {
  249. this.loading = false
  250. }
  251. },
  252. watch: {
  253. reportType (val) {
  254. this.reportType = val
  255. }
  256. }
  257. }
  258. </script>
  259. <style lang="scss" scoped>
  260. .el-radio {
  261. margin: 10px 20px 10px 0;
  262. }
  263. .el-form-item /deep/ .el-tabs__content {
  264. /*max-height: 120px !important;*/
  265. overflow: auto;
  266. }
  267. .el-row {
  268. margin-bottom: 10px;
  269. }
  270. .el-input {
  271. width: 400px;
  272. }
  273. </style>