EditForm.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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-input v-decorator="['sbId']" type="hidden"/>
  14. </a-form-item>
  15. <row-list :col="2">
  16. <row-item>
  17. <a-form-item
  18. label="工单类别"
  19. :labelCol="BaseTool.Constant.labelCol"
  20. :wrapperCol="BaseTool.Constant.wrapperCol"
  21. >
  22. <a-select @change="changePlanFlag" v-decorator="['category', {rules: [{required: true, message: '计划性维修不能为空'}]}]" placeholder="请选择">
  23. <a-select-option
  24. v-for="(label,value) in planFlagMap"
  25. :key="value"
  26. :label="label"
  27. :value="parseInt(value)">{{ label }}
  28. </a-select-option>
  29. </a-select>
  30. </a-form-item>
  31. </row-item>
  32. <row-item>
  33. <a-form-item
  34. label="接收时间"
  35. :labelCol="BaseTool.Constant.labelCol"
  36. :wrapperCol="BaseTool.Constant.wrapperCol"
  37. >
  38. <a-date-picker
  39. showTime
  40. v-decorator="['repairStartTime']"
  41. style="width: 100%"
  42. :format="BaseTool.Date.PICKER_NORM_DATETIME_PATTERN"
  43. />
  44. </a-form-item>
  45. </row-item>
  46. <row-item>
  47. <a-form-item
  48. label="完成时间"
  49. :labelCol="BaseTool.Constant.labelCol"
  50. :wrapperCol="BaseTool.Constant.wrapperCol"
  51. >
  52. <a-date-picker
  53. v-decorator="['repairEndTime']"
  54. showTime
  55. style="width: 100%"
  56. :format="BaseTool.Date.PICKER_NORM_DATETIME_PATTERN"
  57. />
  58. </a-form-item>
  59. </row-item>
  60. </row-list>
  61. </a-form>
  62. <spare-part-used-select-modal ref="sparePartUsedSelectModal" />
  63. <template slot="footer">
  64. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  65. </template>
  66. </a-modal>
  67. </template>
  68. <script>
  69. import pick from 'lodash.pick'
  70. import { changeApplicationForm } from '@/api/repair/application-form'
  71. import { fetchErrorTypeTree } from '@/api/repair/errortype'
  72. import SparePartUsedSelectModal from '@/views/sqarepartmanage/sparepartused/modules/SparePartUsedSelectModal'
  73. import Vue from 'vue'
  74. import { ACCESS_TOKEN } from '@/store/mutation-types'
  75. export default {
  76. name: 'BaseRepairApplicationForm',
  77. data () {
  78. return {
  79. model: null,
  80. confirmLoading: false,
  81. modalTitle: null,
  82. form: this.$form.createForm(this),
  83. visible: false,
  84. category: 0,
  85. planFlagMap: {},
  86. // 下拉框map
  87. treeData: [],
  88. descripitionMap: {},
  89. headers: {
  90. Authorization: 'Bearer ' + Vue.ls.get(ACCESS_TOKEN)
  91. },
  92. sourceMap: {},
  93. levelMap: {},
  94. needStopMap: {},
  95. statusMap: {}
  96. }
  97. },
  98. components: {
  99. SparePartUsedSelectModal
  100. },
  101. props: {
  102. },
  103. created () {
  104. // 下拉框map
  105. this.sourceMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_SOURCE)
  106. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_LEVEL)
  107. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_STATUS)
  108. this.needStopMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
  109. this.descripitionMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIRE_ACTION)
  110. this.planFlagMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_CATEGORY)
  111. },
  112. methods: {
  113. base (record) {
  114. this.setTree()
  115. this.visible = true
  116. this.model = record
  117. // 如果是空标识添加
  118. if (this.BaseTool.Object.isBlank(record)) {
  119. this.modalTitle = '添加'
  120. return
  121. }
  122. this.modalTitle = '修改工单'
  123. const { form: { setFieldsValue } } = this
  124. // 日期处理
  125. record.repairStartTime = this.BaseTool.Date.formatter(record.repairStartTime, this.BaseTool.Date.PICKER_NORM_DATETIME_PATTERN)
  126. record.repairEndTime = this.BaseTool.Date.formatter(record.repairEndTime, this.BaseTool.Date.PICKER_NORM_DATETIME_PATTERN)
  127. this.$nextTick(() => {
  128. setFieldsValue(Object.assign(pick(record, [
  129. 'id',
  130. 'sbId',
  131. 'needStop',
  132. 'level',
  133. 'repairContent',
  134. 'category',
  135. 'repairErrorTypeId',
  136. 'repairEndTime',
  137. 'repairStartTime'
  138. ])))
  139. })
  140. },
  141. getUsers () {
  142. },
  143. changePlanFlag (value) {
  144. this.category = value
  145. const { form: { setFieldsValue } } = this
  146. if (this.category === 1) {
  147. this.$nextTick(() => {
  148. setFieldsValue({ needStop: 1 })
  149. })
  150. } else {
  151. this.$nextTick(() => {
  152. setFieldsValue({ needStop: 0 })
  153. })
  154. }
  155. },
  156. save () {
  157. const { form: { validateFieldsAndScroll } } = this
  158. this.confirmLoading = true
  159. validateFieldsAndScroll((errors, values) => {
  160. if (errors) {
  161. this.confirmLoading = false
  162. return
  163. }
  164. // 日期处理
  165. values.repairFileList = this.repairFileList
  166. values.repairStartTime = this.BaseTool.Date.formatter(values.repairStartTime, this.BaseTool.Date.PICKER_NORM_DATETIME_PATTERN)
  167. values.repairEndTime = this.BaseTool.Date.formatter(values.repairEndTime, this.BaseTool.Date.PICKER_NORM_DATETIME_PATTERN)
  168. changeApplicationForm(values).then(() => {
  169. this.$message.info('工单已修改。')
  170. this.handleCancel(values)
  171. }).catch(() => {
  172. this.confirmLoading = false
  173. })
  174. })
  175. },
  176. handleCancel (values) {
  177. this.visible = false
  178. this.confirmLoading = false
  179. this.form.resetFields()
  180. if (this.BaseTool.Object.isNotBlank(values)) {
  181. this.$emit('ok')
  182. }
  183. },
  184. handleSbSelect () {
  185. this.$refs.sbInfoSelectModal.base({}, { filter: 0, status: 2 })
  186. },
  187. handleSbSelectd (keys, rows) {
  188. const [ key ] = keys
  189. const [ row ] = rows
  190. const { form: { setFieldsValue } } = this
  191. // 日期处理
  192. this.$nextTick(() => {
  193. setFieldsValue(Object.assign({
  194. 'sbId': key,
  195. 'sbName': row.name
  196. }))
  197. })
  198. },
  199. handlePartSelect () {
  200. const sbId = this.form.getFieldValue('sbId')
  201. this.$refs.partInfoSelectModal.base({ sbId })
  202. },
  203. handlePartSelected (keys, rows) {
  204. const [ key ] = keys
  205. const [ row ] = rows
  206. const { form: { setFieldsValue } } = this
  207. this.$nextTick(() => {
  208. setFieldsValue(Object.assign({
  209. 'partId': key,
  210. 'partName': row.name
  211. }))
  212. })
  213. },
  214. /**
  215. * 设置类别树
  216. */
  217. setTree (record = {}) {
  218. fetchErrorTypeTree({ id: record.id }).then(res => {
  219. this.treeData = res.data
  220. })
  221. },
  222. handleAddPartUsed () {
  223. /* const modal = this.$refs.repairFeeModal
  224. modal.base(null, record) */
  225. this.$refs.sparePartUsedSelectModal.base(this.model, { sbId: this.model.sbId, modelId: this.model.modelId })
  226. }
  227. }
  228. }
  229. </script>