Form.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
  2. <div>
  3. <el-dialog :title="title" :close-on-click-modal="false" draggable width="50%" @close="close"
  4. @keyup.enter.native="" v-model="visible" @open="handleOpen">
  5. <el-form :model="inputForm" ref="inputForm" v-loading="loading" :class="method === 'view' ? 'readonly' : ''"
  6. :disabled="status === 'audit' || status === 'taskFormDetail' || method === 'view'" label-width="100px"
  7. @submit.native.prevent>
  8. <el-divider content-position="left"><i class="el-icon-document"></i>
  9. 上传附件
  10. </el-divider>
  11. <el-row :gutter="15">
  12. <el-col :span="24">
  13. <el-form-item label="收藏分类" prop="classification">
  14. <el-select v-model="inputForm.classification" clearable filterable @blur="selectMethod">
  15. <el-option v-for="(item, index) in dictList" :key="index" :label="item.label"
  16. :value="item.value" />
  17. </el-select>
  18. </el-form-item>
  19. </el-col>
  20. <el-col :span="24">
  21. <el-form-item label="文件描述" prop="fileDescription">
  22. <el-input maxlength="500" type="textarea" placeholder="请填写文件描述"
  23. v-model="inputForm.fileDescription" show-word-limit></el-input>
  24. </el-form-item>
  25. </el-col>
  26. <el-col :span="24">
  27. <UpLoadComponent ref="uploadComponent"></UpLoadComponent>
  28. </el-col>
  29. </el-row>
  30. </el-form>
  31. <template #footer>
  32. <span class="dialog-footer">
  33. <el-button @click="close()" icon="el-icon-circle-close">关闭</el-button>
  34. <el-button type="primary" v-if="method != 'view'" @click="doSubmit()" icon="el-icon-circle-check"
  35. v-noMoreClick>确定</el-button>
  36. </span>
  37. </template>
  38. </el-dialog>
  39. </div>
  40. </template>
  41. <script>
  42. import workCollectAccessoryService from "@/api/workCollectAccessory/index"
  43. import UpLoadComponent from '@/views/common/UpLoadComponentWorkCollect'
  44. import { ElDatePicker } from 'element-plus';
  45. // eslint-disable-next-line no-unused-vars
  46. import OSSSerivce from '@/api/sys/OSSService'
  47. import moment from 'moment'
  48. export default {
  49. props: {
  50. formReadOnly: {
  51. type: Boolean,
  52. default: false
  53. },
  54. status: {
  55. type: String,
  56. default: ''
  57. }
  58. },
  59. data() {
  60. return {
  61. title: '',
  62. method: '',
  63. loading: false,
  64. visible: false,
  65. inputForm: {
  66. classification: "",
  67. fileDescription: "",
  68. workAttachments: []
  69. },
  70. baseKey: '',
  71. keyWatch: '',
  72. dateList: [],
  73. dictList: [],
  74. ossService: null
  75. }
  76. },
  77. created() {
  78. this.ossService = new OSSSerivce()
  79. },
  80. mounted() {
  81. },
  82. activated() {
  83. },
  84. components: {
  85. ElDatePicker,
  86. UpLoadComponent
  87. },
  88. methods: {
  89. selectMethod(e) {
  90. if (e.target.value !== '') {
  91. this.inputForm.classification = e.target.value;
  92. this.$forceUpdate(); // 强制更新
  93. }
  94. },
  95. init(method, id) {
  96. this.method = method
  97. this.visible = true
  98. this.inputForm = {
  99. classification: "",
  100. fileDescription: "",
  101. workAttachments: []
  102. }
  103. if (method === 'add') {
  104. this.title = `上传附件`
  105. } else if (method === 'edit') {
  106. this.inputForm.id = id
  107. this.title = '修改附件'
  108. }
  109. this.loading = false
  110. this.visible = true
  111. this.$nextTick(() => {
  112. this.$refs.inputForm.resetFields()
  113. this.loading = true
  114. this.loading = false
  115. if (this.commonJS.isNotEmpty(this.inputForm.id)) {
  116. workCollectAccessoryService.queryById(this.inputForm.id).then((res) => {
  117. this.ossService.getFileSizeByUrl(res.url).then((data) => {
  118. let file = {
  119. lsUrl: data.url,
  120. size: data.size,
  121. createBy: {
  122. id: this.$store.state.user.id,
  123. name: this.$store.state.user.name,
  124. },
  125. createTime: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
  126. name: res.fileName,
  127. url: res.url
  128. }
  129. this.inputForm.workAttachments.push(file)
  130. this.inputForm.classification = res.classification
  131. this.inputForm.fileDescription = res.fileDescription
  132. console.log(this.inputForm.workAttachments);
  133. this.$refs.uploadComponent.newUpload(method, this.inputForm.workAttachments, 'workCollect')
  134. })
  135. })
  136. }
  137. })
  138. },
  139. // 表单提交
  140. async doSubmit() {
  141. let files = this.$refs.uploadComponent.getDataList()
  142. console.log(files);
  143. if (files.length <= 0) {
  144. this.loading = false
  145. this.$message.error(`请上传附件后提交`);
  146. return
  147. }
  148. if (this.$refs.uploadComponent.checkProgress()) {
  149. this.loading = false
  150. this.$message.error(`待附件上传完毕后提交`);
  151. return
  152. }
  153. this.loading = true
  154. this.$refs['inputForm'].validate((valid) => {
  155. if (valid) {
  156. this.inputForm.workAttachments = this.$refs.uploadComponent.getDataList()
  157. this.loading = true
  158. if (this.inputForm.id) {
  159. workCollectAccessoryService.updateById(this.inputForm).then((data) => {
  160. this.visible = false
  161. this.$emit('refreshList')
  162. }).catch(() => {
  163. this.$refs.inputForm.resetFields()
  164. this.loading = false
  165. })
  166. } else {
  167. workCollectAccessoryService.saveForm(this.inputForm).then((data) => {
  168. this.visible = false
  169. this.$emit('refreshList')
  170. }).catch(() => {
  171. this.$refs.inputForm.resetFields()
  172. this.loading = false
  173. })
  174. }
  175. } else {
  176. this.loading = false
  177. }
  178. })
  179. },
  180. close() {
  181. this.inputForm = {
  182. id: '',
  183. }
  184. this.visible = false
  185. this.$refs.uploadComponent.clearUpload()
  186. },
  187. async updateStatusById(type, callback) {
  188. this.loading = true
  189. workCollectAccessoryService.updateStatusById(param).then(() => {
  190. this.loading = false
  191. callback()
  192. })
  193. },
  194. }
  195. }
  196. </script>
  197. <style scoped>
  198. /deep/ .el-input-number .el-input__inner {
  199. text-align: left;
  200. }
  201. /deep/ .vxe-footer--row .vxe-footer--column:nth-child(1) .vxe-cell--item {
  202. font-weight: 700;
  203. }
  204. </style>