FinishForm.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. import Vue from 'vue'
  135. import { ACCESS_TOKEN } from '@/store/mutation-types'
  136. export default {
  137. name: 'BaseRepairApplicationForm',
  138. data () {
  139. return {
  140. model: null,
  141. confirmLoading: false,
  142. modalTitle: null,
  143. form: this.$form.createForm(this),
  144. visible: false,
  145. // 下拉框map
  146. treeData: [],
  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. userList: []
  159. }
  160. },
  161. components: {
  162. SparePartUsedSelectModal
  163. },
  164. props: {
  165. },
  166. created () {
  167. // 下拉框map
  168. this.sourceMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_SOURCE)
  169. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_LEVEL)
  170. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_STATUS)
  171. this.needStopMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
  172. this.descripitionMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIRE_ACTION)
  173. },
  174. methods: {
  175. base (record) {
  176. this.setTree()
  177. this.visible = true
  178. this.model = record
  179. // 如果是空标识添加
  180. if (this.BaseTool.Object.isBlank(record)) {
  181. this.modalTitle = '添加'
  182. return
  183. }
  184. this.modalTitle = '维修完成'
  185. const { form: { setFieldsValue } } = this
  186. // 日期处理
  187. record.applyTime = this.BaseTool.Moment(record.applyTime, this.BaseTool.Date.PICKER_NORM_DATETIME_PATTERN)
  188. this.$nextTick(() => {
  189. setFieldsValue(Object.assign(pick(record, [
  190. 'id',
  191. 'needStop',
  192. 'level',
  193. 'repairErrorTypeId'
  194. ])))
  195. })
  196. },
  197. getUsers () {
  198. queryUser({ status: 1 }).then(res => {
  199. this.userList = res.data
  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. values.repairFileList = this.repairFileList
  228. finish(values).then(() => {
  229. this.handleCancel(values)
  230. }).catch(() => {
  231. this.confirmLoading = false
  232. })
  233. })
  234. },
  235. handleCancel (values) {
  236. this.visible = false
  237. this.confirmLoading = false
  238. this.form.resetFields()
  239. if (this.BaseTool.Object.isNotBlank(values)) {
  240. this.$emit('ok')
  241. }
  242. },
  243. handleSbSelect () {
  244. this.$refs.sbInfoSelectModal.base({}, { filter: 0, status: 2 })
  245. },
  246. handleSbSelectd (keys, rows) {
  247. const [ key ] = keys
  248. const [ row ] = rows
  249. const { form: { setFieldsValue } } = this
  250. // 日期处理
  251. this.$nextTick(() => {
  252. setFieldsValue(Object.assign({
  253. 'sbId': key,
  254. 'sbName': row.name
  255. }))
  256. })
  257. },
  258. handlePartSelect () {
  259. const sbId = this.form.getFieldValue('sbId')
  260. this.$refs.partInfoSelectModal.base({ sbId })
  261. },
  262. handlePartSelected (keys, rows) {
  263. const [ key ] = keys
  264. const [ row ] = rows
  265. const { form: { setFieldsValue } } = this
  266. this.$nextTick(() => {
  267. setFieldsValue(Object.assign({
  268. 'partId': key,
  269. 'partName': row.name
  270. }))
  271. })
  272. },
  273. /**
  274. * 设置类别树
  275. */
  276. setTree (record = {}) {
  277. fetchErrorTypeTree({ id: record.id }).then(res => {
  278. this.treeData = res.data
  279. })
  280. },
  281. handleAddPartUsed () {
  282. /* const modal = this.$refs.repairFeeModal
  283. modal.base(null, record) */
  284. this.$refs.sparePartUsedSelectModal.base(this.model, { sbId: this.model.sbId, modelId: this.model.modelId })
  285. }
  286. }
  287. }
  288. </script>