FinishForm.vue 9.0 KB

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