FinishForm.vue 11 KB

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