FinishForm.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="800"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. class="ant-modal2"
  8. @cancel="handleCancel"
  9. >
  10. <a-form :form="form">
  11. <a-form-item v-show="false" >
  12. <a-input v-decorator="['id']" type="hidden"/>
  13. </a-form-item>
  14. <row-list :col="2">
  15. <row-item>
  16. <a-form-item
  17. label="工单类别"
  18. :labelCol="BaseTool.Constant.labelCol"
  19. :wrapperCol="BaseTool.Constant.wrapperCol"
  20. >
  21. <a-select
  22. disabled
  23. @change="changePlanFlag"
  24. v-decorator="['category', {rules: [{required: true, message: '计划性维修不能为空'}]}]"
  25. placeholder="请选择">
  26. <a-select-option
  27. v-for="(label,value) in planFlagMap"
  28. :key="value"
  29. :label="label"
  30. :value="parseInt(value)">{{ label }}
  31. </a-select-option>
  32. </a-select>
  33. </a-form-item>
  34. </row-item>
  35. <row-item>
  36. <a-form-item
  37. label="所属工程师"
  38. :labelCol="BaseTool.Constant.labelCol"
  39. :wrapperCol="BaseTool.Constant.wrapperCol"
  40. >
  41. <a-select
  42. v-decorator="['dispatchUserId', {rules: [{required: true, message: '所属工程师不能为空'}]}]"
  43. placeholder="请选择">
  44. <a-select-option
  45. v-for="item in dispatchList"
  46. :key="item.userId"
  47. :label="item.realName"
  48. :value="item.userId">{{ item.realName }}
  49. </a-select-option>
  50. </a-select>
  51. </a-form-item>
  52. </row-item>
  53. <row-item>
  54. <a-form-item
  55. label="完成时间"
  56. :labelCol="BaseTool.Constant.labelCol"
  57. :wrapperCol="BaseTool.Constant.wrapperCol"
  58. >
  59. <a-date-picker
  60. disabled="disabled"
  61. showTime
  62. v-decorator="['repairEndTime']"
  63. style="width: 100%"
  64. :format="BaseTool.Date.PICKER_NORM_DATETIME_PATTERN"
  65. />
  66. </a-form-item>
  67. </row-item>
  68. </row-list>
  69. <row-list :col="1">
  70. <row-item>
  71. <a-form-item
  72. label="维修图片"
  73. :labelCol="BaseTool.Constant.labelCol2"
  74. :wrapperCol="BaseTool.Constant.wrapperCol2"
  75. >
  76. <a-upload
  77. :action="uploadUrl"
  78. :multiple="true"
  79. list-type="picture"
  80. :file-list="defaultRepairFileList"
  81. @change="handleRepairFileChange"
  82. accept="image/*"
  83. :headers="headers"
  84. >
  85. <a-button> <a-icon type="upload" /> 上传图片 </a-button>
  86. </a-upload>
  87. </a-form-item>
  88. </row-item>
  89. <row-item>
  90. <a-form-item
  91. label="维修文件"
  92. :labelCol="BaseTool.Constant.labelCol2"
  93. :wrapperCol="BaseTool.Constant.wrapperCol2"
  94. >
  95. <a-upload
  96. :action="uploadUrl"
  97. :multiple="true"
  98. :file-list="defaultFileList"
  99. @change="handleFileChange"
  100. :headers="headers"
  101. >
  102. <a-button> <a-icon type="upload" /> 上传文件 </a-button>
  103. </a-upload>
  104. </a-form-item>
  105. </row-item>
  106. <row-item>
  107. <a-form-item
  108. label="维修描述"
  109. :labelCol="BaseTool.Constant.labelCol2"
  110. :wrapperCol="BaseTool.Constant.wrapperCol2"
  111. >
  112. <a-textarea v-decorator="['remark']"/>
  113. </a-form-item>
  114. </row-item>
  115. </row-list>
  116. </a-form>
  117. <spare-part-used-select-modal ref="sparePartUsedSelectModal" />
  118. <template slot="footer">
  119. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  120. </template>
  121. </a-modal>
  122. </template>
  123. <script>
  124. import pick from 'lodash.pick'
  125. import { finish } from '@/api/repair/application-form'
  126. import { queryUser } from '@/api/upms/user'
  127. import { fetchErrorTypeTree } from '@/api/repair/errortype'
  128. import SparePartUsedSelectModal from '@/views/sqarepartmanage/sparepartused/modules/SparePartUsedSelectModal'
  129. import { uploadUrl } from '@/api/upms/file'
  130. import Vue from 'vue'
  131. import { ACCESS_TOKEN } from '@/store/mutation-types'
  132. import { queryRepairUser } from '@/api/upms/user-dept'
  133. export default {
  134. name: 'BaseRepairApplicationForm',
  135. data () {
  136. return {
  137. model: null,
  138. confirmLoading: false,
  139. modalTitle: null,
  140. form: this.$form.createForm(this),
  141. visible: false,
  142. category: 0,
  143. planFlagMap: {},
  144. // 下拉框map
  145. treeData: [],
  146. dispatchList: [],
  147. descripitionMap: {},
  148. headers: {
  149. Authorization: 'Bearer ' + Vue.ls.get(ACCESS_TOKEN)
  150. },
  151. sourceMap: {},
  152. levelMap: {},
  153. needStopMap: {},
  154. statusMap: {},
  155. uploadUrl: uploadUrl,
  156. defaultRepairFileList: [],
  157. repairFileList: [], // 维修图片,
  158. defaultFileList: [], // 维修文件
  159. fileList: [],
  160. userList: []
  161. }
  162. },
  163. components: {
  164. SparePartUsedSelectModal
  165. },
  166. props: {
  167. },
  168. created () {
  169. // 下拉框map
  170. this.sourceMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_SOURCE)
  171. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_LEVEL)
  172. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_STATUS)
  173. this.needStopMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
  174. this.descripitionMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIRE_ACTION)
  175. this.planFlagMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_CATEGORY)
  176. },
  177. methods: {
  178. base (record) {
  179. this.setTree()
  180. this.visible = true
  181. this.model = record
  182. const params = { roleType: 2, deptId: record.repairDeptId, queryType: 1 }
  183. this.getUsers(params)
  184. this.defaultFileList = []
  185. this.repairFileList = []
  186. // 如果是空标识添加
  187. if (this.BaseTool.Object.isBlank(record)) {
  188. this.modalTitle = '添加'
  189. return
  190. }
  191. this.modalTitle = '维修完成'
  192. this.repairFileList = record.repairFileList
  193. this.defaultRepairFileList = this.BaseTool.UPLOAD.transImg(this.repairFileList)
  194. const { form: { setFieldsValue } } = this
  195. // 日期处理
  196. if (record.repairEndTime !== null) {
  197. record.repairEndTime = this.BaseTool.Date.formatter(record.repairEndTime, this.BaseTool.Date.PICKER_NORM_DATETIME_PATTERN)
  198. } else {
  199. record.repairEndTime = this.BaseTool.Date.formatter(new Date(), this.BaseTool.Date.PICKER_NORM_DATETIME_PATTERN)
  200. }
  201. this.$nextTick(() => {
  202. setFieldsValue(Object.assign(pick(record, [
  203. 'id',
  204. 'needStop',
  205. 'level',
  206. 'category',
  207. 'repairErrorTypeId',
  208. 'repairEndTime',
  209. 'dispatchUserId'
  210. ])))
  211. })
  212. },
  213. getUsers (params) {
  214. queryRepairUser(params).then(res => {
  215. this.dispatchList = res.data
  216. })
  217. },
  218. changePlanFlag (value) {
  219. this.category = value
  220. const { form: { setFieldsValue } } = this
  221. if (this.category === 1) {
  222. this.$nextTick(() => {
  223. setFieldsValue({ needStop: 1 })
  224. })
  225. } else {
  226. this.$nextTick(() => {
  227. setFieldsValue({ needStop: 0 })
  228. })
  229. }
  230. },
  231. handleFileChange (info) {
  232. this.defaultFileList = info.fileList
  233. this.fileList = this.setFileList(info, 19)
  234. },
  235. handleRepairFileChange (info) {
  236. this.defaultRepairFileList = info.fileList
  237. this.repairFileList = this.setFileList(info, 12)
  238. },
  239. setFileList (info, type) {
  240. const file = info.file
  241. const fileList = info.fileList
  242. if (file.status === 'done') {
  243. return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
  244. } else if (file.status === 'removed') {
  245. return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
  246. } else if (file.status === 'error') {
  247. this.$message.error('上传失败')
  248. return []
  249. }
  250. },
  251. save () {
  252. const { form: { validateFieldsAndScroll } } = this
  253. this.confirmLoading = true
  254. validateFieldsAndScroll((errors, values) => {
  255. if (errors) {
  256. this.confirmLoading = false
  257. return
  258. }
  259. // 日期处理
  260. values.category = this.model.category
  261. values.repairFileList = this.repairFileList
  262. values.opinionFileList = this.fileList // 维修文件
  263. values.repairEndTime = this.BaseTool.Date.formatter(values.repairEndTime, this.BaseTool.Date.PICKER_NORM_DATETIME_PATTERN)
  264. finish(values).then(() => {
  265. this.$message.info('维修已提交,等待工程师审核')
  266. this.handleCancel(values)
  267. }).catch(() => {
  268. this.confirmLoading = false
  269. })
  270. })
  271. },
  272. handleCancel (values) {
  273. this.visible = false
  274. this.confirmLoading = false
  275. this.form.resetFields()
  276. if (this.BaseTool.Object.isNotBlank(values)) {
  277. this.$emit('ok')
  278. } else {
  279. this.$emit('ok')
  280. }
  281. },
  282. handleSbSelect () {
  283. this.$refs.sbInfoSelectModal.base({}, { filter: 0, status: 2 })
  284. },
  285. handleSbSelectd (keys, rows) {
  286. const [ key ] = keys
  287. const [ row ] = rows
  288. const { form: { setFieldsValue } } = this
  289. // 日期处理
  290. this.$nextTick(() => {
  291. setFieldsValue(Object.assign({
  292. 'sbId': key,
  293. 'sbName': row.name
  294. }))
  295. })
  296. },
  297. handlePartSelect () {
  298. const sbId = this.form.getFieldValue('sbId')
  299. this.$refs.partInfoSelectModal.base({ sbId })
  300. },
  301. handlePartSelected (keys, rows) {
  302. const [ key ] = keys
  303. const [ row ] = rows
  304. const { form: { setFieldsValue } } = this
  305. this.$nextTick(() => {
  306. setFieldsValue(Object.assign({
  307. 'partId': key,
  308. 'partName': row.name
  309. }))
  310. })
  311. },
  312. /**
  313. * 设置类别树
  314. */
  315. setTree (record = {}) {
  316. fetchErrorTypeTree({ id: record.id }).then(res => {
  317. this.treeData = res.data
  318. })
  319. },
  320. handleAddPartUsed () {
  321. /* const modal = this.$refs.repairFeeModal
  322. modal.base(null, record) */
  323. this.$refs.sparePartUsedSelectModal.base(this.model, { sbId: this.model.sbId, modelId: this.model.modelId })
  324. }
  325. }
  326. }
  327. </script>