ProjectReportCreate.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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. drag
  45. class="upload-demo"
  46. action="https://jsonplaceholder.typicode.com/posts/"
  47. :on-remove="handleRemove"
  48. :before-remove="beforeRemove"
  49. multiple
  50. :limit="1"
  51. :on-exceed="handleExceed"
  52. :before-upload="beforeFileUpload"
  53. :file-list="report.file"
  54. :http-request="uploadReportFile"
  55. >
  56. <i class="el-icon-upload"></i>
  57. <div class="el-upload__text">
  58. 将文件拖到此处,或
  59. <em>点击上传</em>
  60. </div>
  61. </el-upload>
  62. </el-form-item>
  63. <el-form-item label="结论" prop="conclusion">
  64. <el-input autosize style="width: 400px" type="textarea" v-model="report.conclusion"></el-input>
  65. </el-form-item>
  66. <el-form-item>
  67. <div class="btn btn-medium btn-info" @click="submitForm('report')">提交</div>
  68. <div class="btn btn-medium" @click="resetForm('report')">重置</div>
  69. <div class="btn btn-medium" @click="cancelCreate('report')">取消</div>
  70. </el-form-item>
  71. </el-form>
  72. </div>
  73. </div>
  74. </template>
  75. <script>
  76. import Http from '@/js/http.js'
  77. import Apis from '@/js/api.js'
  78. import {notify} from '@/constants/index'
  79. import {getAllReportTypes, storageGet} from '@/js/index'
  80. export default {
  81. name: 'ProjectReportCreate',
  82. components: {},
  83. data () {
  84. return {
  85. user: {},
  86. reportType: [],
  87. loading: false,
  88. scope: 0,
  89. projectId: '',
  90. taskId: '',
  91. dependencyCode: '',
  92. report: {
  93. name: '',
  94. target: '',
  95. content: '',
  96. file: [],
  97. fileUrl: '',
  98. type: '',
  99. conclusion: ''
  100. },
  101. rules: {
  102. // name: [
  103. // {required: true, message: '请输入报告名称', trigger: 'blur'}
  104. // // { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" }
  105. // ],
  106. // abstract: [
  107. // {
  108. // required: true,
  109. // message: '请输入摘要信息',
  110. // trigger: 'change'
  111. // }
  112. // ],
  113. // type: [
  114. // {required: true, message: '请选择报告类型', trigger: 'change'}
  115. // ],
  116. // file: [
  117. // {required: true, message: '请上传报告文件', trigger: 'change'}
  118. // ],
  119. // conclusion: [
  120. // {required: true, message: '请输入报告结论', trigger: 'blur'}
  121. // ]
  122. }
  123. }
  124. },
  125. mounted () {
  126. this.$nextTick(() => {
  127. this.init()
  128. })
  129. },
  130. methods: {
  131. init () {
  132. this.scope = this.$route.params.scope
  133. this.dependencyCode = this.$route.params.dependencyCode
  134. this.projectId = this.$route.params.projectId
  135. this.taskId = this.$route.params.taskId
  136. this.setUserInfo()
  137. this.setReportType()
  138. },
  139. submitForm (formName) {
  140. this.showLoading()
  141. const newReport = {
  142. name: this.report.name,
  143. scope: this.scope,
  144. type: this.report.type,
  145. dependencyCode: this.dependencyCode,
  146. target: this.report.target,
  147. content: this.report.content,
  148. file: this.report.fileUrl,
  149. conclusion: this.report.conclusion
  150. }
  151. console.log(newReport)
  152. Http.post(Apis.REPORT.CREATE_PROJECT_REPORT.replace('{projectId}', this.projectId), newReport).then((res) => {
  153. this.hideLoading()
  154. this.createReportSuccess(res.crowdReportVO.code)
  155. }).catch((error) => {
  156. this.hideLoading()
  157. notify('error', '报告创建失败:' + error.data)
  158. })
  159. // this.$refs[formName].validate(valid => {
  160. // if (valid) {
  161. //
  162. // //提交 report
  163. // } else {
  164. // console.log('error submit!!')
  165. // return false
  166. // }
  167. // })
  168. },
  169. resetForm (formName) {
  170. this.$refs[formName].resetFields()
  171. this.report.name = ''
  172. this.report.abstract.target = ''
  173. this.report.abstract.content = ''
  174. this.report.file = []
  175. this.report.type = ''
  176. this.report.conclusion = ''
  177. },
  178. cancelCreate () {
  179. if (window.history.length <= 1) {
  180. this.$router.push({path: '/'})
  181. return false
  182. } else {
  183. this.$router.go(-1)
  184. }
  185. },
  186. handleRemove (file, fileList) {
  187. console.log(file, fileList)
  188. },
  189. handleExceed (files, fileList) {
  190. this.$message.warning(
  191. `当前限制选择 1 个文件,本次选择了 ${
  192. files.length
  193. } 个文件,共选择了 ${files.length + fileList.length} 个文件`
  194. )
  195. },
  196. beforeRemove (file, fileList) {
  197. //return this.$confirm(`确定移除 ${file.name}?`)
  198. },
  199. beforeFileUpload (file) {
  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. loadData () {
  214. },
  215. uploadReportFile (param) {
  216. const formData = new FormData()
  217. let config = {
  218. //添加请求头
  219. headers: {'Content-Type': 'multipart/form-data'},
  220. }
  221. formData.append('file', param.file)
  222. Http.upload(Apis.FILE.UPLOAD_REPORT_FILE.replace('{userId}', this.user.userVO.id), formData, config).then((res) => {
  223. console.log('上传成功')
  224. this.report.fileUrl = res.data
  225. console.log(res)
  226. })
  227. },
  228. setReportType () {
  229. this.reportType = getAllReportTypes().then((res) => {
  230. this.reportType = res
  231. }).catch((error) => {
  232. notify('error', '获取报告类型列表失败')
  233. })
  234. },
  235. setUserInfo () {
  236. this.user = storageGet('user')
  237. },
  238. createReportSuccess (reportId) {
  239. this.$alert('报告创建成功', '创建成功', {
  240. confirmButtonText: '确定',
  241. callback: action => {
  242. this.$router.push({
  243. name: 'ProjectReport',
  244. params: {reportId: reportId, projectId: this.projectId}
  245. })
  246. }
  247. })
  248. },
  249. showLoading () {
  250. this.loading = true
  251. },
  252. hideLoading () {
  253. this.loading = false
  254. }
  255. },
  256. watch: {
  257. reportType (val) {
  258. this.reportType = val
  259. }
  260. }
  261. }
  262. </script>
  263. <style lang="less" scoped>
  264. .el-radio {
  265. margin: 10px 20px 10px 0;
  266. }
  267. .el-form-item /deep/ .el-tabs__content {
  268. max-height: 120px !important;
  269. overflow: auto;
  270. }
  271. .el-row {
  272. margin-bottom: 10px;
  273. }
  274. .el-input {
  275. width: 400px;
  276. }
  277. </style>