Form.vue 6.0 KB

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