FinishForm.vue 10 KB

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