BaseForm.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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="设备id"
  18. :labelCol="BaseTool.Constant.labelCol"
  19. :wrapperCol="BaseTool.Constant.wrapperCol"
  20. v-show="false"
  21. >
  22. <a-input
  23. v-decorator="['sbId', {rules: [{required: true, message: '设备id不能为空'}]}]" />
  24. </a-form-item>
  25. <a-form-item
  26. label="设备名称"
  27. :labelCol="BaseTool.Constant.labelCol"
  28. :wrapperCol="BaseTool.Constant.wrapperCol"
  29. >
  30. <a-input
  31. style="width: 70%"
  32. disabled
  33. v-decorator="['sbName', {rules: [{required: true, message: '设备名称不能为空'}]}]" />
  34. <a-button style="width: 30%" type="primary" @click="handleSbSelect">选择</a-button>
  35. </a-form-item>
  36. </row-item>
  37. <!--<row-item>
  38. <a-form-item
  39. label="部件id"
  40. :labelCol="BaseTool.Constant.labelCol"
  41. :wrapperCol="BaseTool.Constant.wrapperCol"
  42. v-show="false"
  43. >
  44. <a-input
  45. v-decorator="['partId', {rules: [{required: false, message: '设备id不能为空'}]}]" />
  46. </a-form-item>
  47. <a-form-item
  48. label="部件名称"
  49. :labelCol="BaseTool.Constant.labelCol"
  50. :wrapperCol="BaseTool.Constant.wrapperCol"
  51. >
  52. <a-input
  53. disabled
  54. style="width: 70%"
  55. v-decorator="['partName', {rules: [{required: false, message: '部件名称不能为空'}]}]" />
  56. <a-button :disabled="!BaseTool.Object.isNotBlank(this.form.getFieldValue('sbId'))" style="width: 30%" type="primary" @click="handlePartSelect">选择</a-button>
  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-select v-decorator="['needStop', {initialValue: DictCache.VALUE.YES_NO.NO,rules: [{required: true, message: '是否停机不能为空'}]}]" placeholder="请选择">
  66. <a-select-option
  67. v-for="(label,value) in needStopMap"
  68. :key="value"
  69. :label="label"
  70. :value="parseInt(value)">{{ label }}
  71. </a-select-option>
  72. </a-select>
  73. </a-form-item>
  74. </row-item>
  75. <!--<row-item>
  76. <a-form-item
  77. label="报修人"
  78. :labelCol="BaseTool.Constant.labelCol"
  79. :wrapperCol="BaseTool.Constant.wrapperCol"
  80. >
  81. <a-select v-decorator="['repairUserId', {rules: [{required: true, message: '报修人不能为空'}]}]" placeholder="请选择">
  82. <a-select-option
  83. v-for="item in userList"
  84. :key="item.userId"
  85. :label="item.realName"
  86. :value="item.userId">{{ item.realName }}
  87. </a-select-option>
  88. </a-select>
  89. </a-form-item>
  90. </row-item>-->
  91. <row-item>
  92. <a-form-item
  93. label="报修单号"
  94. :labelCol="BaseTool.Constant.labelCol"
  95. :wrapperCol="BaseTool.Constant.wrapperCol"
  96. >
  97. <a-input
  98. disabled
  99. v-decorator="['no', {rules: [{required: false, message: '报修单号不能为空'}]}]" />
  100. </a-form-item>
  101. </row-item>
  102. <row-item>
  103. <a-form-item
  104. label="报修来源"
  105. :labelCol="BaseTool.Constant.labelCol"
  106. :wrapperCol="BaseTool.Constant.wrapperCol"
  107. >
  108. <a-select v-decorator="['source', {initialValue: DictCache.VALUE.REPAIR_APPLICATION_FORM_SOURCE.CHECK,rules: [{required: true, message: '报修来源不能为空'}]}]" placeholder="请选择">
  109. <a-select-option
  110. v-for="(label,value) in sourceMap"
  111. :key="value"
  112. :label="label"
  113. :value="parseInt(value)">{{ label }}
  114. </a-select-option>
  115. </a-select>
  116. </a-form-item>
  117. </row-item>
  118. <row-item>
  119. <a-form-item
  120. label="报修人"
  121. :labelCol="BaseTool.Constant.labelCol"
  122. :wrapperCol="BaseTool.Constant.wrapperCol"
  123. >
  124. <a-input
  125. v-decorator="['actualUser', {initialValue: userInfo.realName, rules: [{required: false, message: '报修人不能为空'}]}]"/>
  126. </a-form-item>
  127. </row-item>
  128. <row-item>
  129. <a-form-item
  130. label="紧急等级"
  131. :labelCol="BaseTool.Constant.labelCol"
  132. :wrapperCol="BaseTool.Constant.wrapperCol"
  133. >
  134. <a-select v-decorator="['level', {initialValue: 1, rules: [{required: true, message: '紧急等级不能为空'}]}]" placeholder="请选择">
  135. <a-select-option
  136. v-for="(label,value) in levelMap"
  137. :key="value"
  138. :label="label"
  139. :value="parseInt(value)">{{ label }}
  140. </a-select-option>
  141. </a-select>
  142. </a-form-item>
  143. </row-item>
  144. <row-item>
  145. <a-form-item
  146. label="异常类别"
  147. :labelCol="BaseTool.Constant.labelCol"
  148. :wrapperCol="BaseTool.Constant.wrapperCol"
  149. >
  150. <a-tree-select
  151. style="width: 100%"
  152. :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
  153. :treeData="treeData"
  154. :treeNodeFilterProp="'title'"
  155. :showSearch="true"
  156. v-decorator="['repairErrorTypeId', {rules: [{required: true, message: '故障类别不能为空'}]}]"
  157. placeholder="请选择"
  158. >
  159. </a-tree-select>
  160. </a-form-item>
  161. </row-item>
  162. <row-item>
  163. <a-form-item
  164. label="报修图片"
  165. :labelCol="BaseTool.Constant.labelCol"
  166. :wrapperCol="BaseTool.Constant.wrapperCol"
  167. >
  168. <a-upload
  169. :action="uploadUrl"
  170. :multiple="true"
  171. list-type="picture"
  172. :file-list="this.defaultApplicationFileList"
  173. @change="handleApplicationFileChange"
  174. accept="image/*"
  175. :headers="headers"
  176. >
  177. <a-button> <a-icon type="upload" /> 上传图片 </a-button>
  178. </a-upload>
  179. </a-form-item>
  180. </row-item>
  181. </row-list>
  182. <row-list :col="1">
  183. <row-item v-if="false">
  184. <a-form-item
  185. label="报修状态"
  186. :labelCol="BaseTool.Constant.labelCol"
  187. :wrapperCol="BaseTool.Constant.wrapperCol"
  188. >
  189. <a-select disabled v-decorator="['status', {initialValue: DictCache.VALUE.REPAIR_APPLICATION_FORM_STATUS.NOT_ALLOCATED,rules: [{required: true, message: '报修状态不能为空'}]}]" placeholder="请选择">
  190. <a-select-option
  191. v-for="(label,value) in statusMap"
  192. :key="value"
  193. :label="label"
  194. :value="parseInt(value)">{{ label }}
  195. </a-select-option>
  196. </a-select>
  197. </a-form-item>
  198. </row-item>
  199. <!-- <row-item>
  200. <a-form-item
  201. label="故障描述"
  202. :labelCol="BaseTool.Constant.labelCol2"
  203. :wrapperCol="BaseTool.Constant.wrapperCol2"
  204. >
  205. <a-select v-decorator="['content']" placeholder="请选择">
  206. <a-select-option
  207. v-for="(label,value) in questionMap"
  208. :key="value"
  209. :label="label"
  210. :value="parseInt(value)">{{ label }}
  211. </a-select-option>
  212. </a-select>
  213. </a-form-item>
  214. </row-item>-->
  215. <row-item>
  216. <a-form-item
  217. label="备注"
  218. :labelCol="BaseTool.Constant.labelCol2"
  219. :wrapperCol="BaseTool.Constant.wrapperCol2"
  220. >
  221. <a-textarea
  222. :rows="4"
  223. v-decorator="['remark']"/>
  224. </a-form-item>
  225. </row-item>
  226. </row-list>
  227. </a-form>
  228. <template slot="footer">
  229. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  230. </template>
  231. <sb-info-select-modal ref="sbInfoSelectModal" @selected="handleSbSelectd"/>
  232. <part-info-select-modal ref="partInfoSelectModal" @selected="handlePartSelected"/>
  233. </a-modal>
  234. </template>
  235. <script>
  236. import pick from 'lodash.pick'
  237. import BaseTool from '../../../../utils/tool'
  238. import { addRepairApplicationForm, updateRepairApplicationForm } from '@/api/repair/application-form'
  239. import PartInfoSelectModal from '@/views/part/info/modules/PartInfoSelectModal'
  240. import SbInfoSelectModal from '@/views/sb/info/modules/SbInfoSelectModal'
  241. import { queryUser } from '@/api/upms/user'
  242. import { uploadUrl } from '@/api/upms/file'
  243. import Vue from 'vue'
  244. import { ACCESS_TOKEN } from '@/store/mutation-types'
  245. import { fetchErrorTypeTree } from '@/api/repair/errortype'
  246. export default {
  247. name: 'BaseRepairApplicationForm',
  248. data () {
  249. return {
  250. confirmLoading: false,
  251. modalTitle: null,
  252. form: this.$form.createForm(this),
  253. visible: false,
  254. // 下拉框map
  255. sourceMap: {},
  256. levelMap: {},
  257. questionMap: {},
  258. treeData: [],
  259. needStopMap: {},
  260. statusMap: {},
  261. userInfo: this.$store.getters.userInfo,
  262. userList: [],
  263. uploadUrl: uploadUrl,
  264. defaultRepairFileList: [],
  265. defaultApplicationFileList: [],
  266. defaultCheckFileList: [],
  267. applicationFileList: [], // 报修图片
  268. checkFileList: [], // 验收图片
  269. repairFileList: [], // 维修图片,
  270. headers: {
  271. Authorization: 'Bearer ' + Vue.ls.get(ACCESS_TOKEN)
  272. }
  273. }
  274. },
  275. components: {
  276. SbInfoSelectModal,
  277. PartInfoSelectModal
  278. },
  279. props: {
  280. },
  281. created () {
  282. // 下拉框map
  283. this.sourceMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_SOURCE)
  284. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_LEVEL)
  285. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_APPLICATION_FORM_STATUS)
  286. this.questionMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.REPAIR_QUESTION)
  287. this.needStopMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
  288. this.getUsers()
  289. },
  290. methods: {
  291. base (record) {
  292. this.visible = true
  293. fetchErrorTypeTree().then(res => {
  294. this.treeData = res.data
  295. })
  296. // 如果是空标识添加
  297. if (this.BaseTool.Object.isBlank(record)) {
  298. this.modalTitle = '添加'
  299. if (!this.BaseTool.Object.isBlank(record) && !this.BaseTool.Object.isBlank(record.sbId)) {
  300. console.log('111record.sbId: ' + record.sbId)
  301. console.log('111record.sbName: ' + record.sbName)
  302. const { form: { setFieldsValue } } = this
  303. this.$nextTick(() => {
  304. setFieldsValue(Object.assign(pick(record, [
  305. 'sbId',
  306. 'sbName'
  307. ])))
  308. })
  309. }
  310. return
  311. }
  312. this.modalTitle = '编辑'
  313. this.applicationFileList = record.applicationFileList
  314. this.repairFileList = record.repairFileList
  315. this.checkFileList = record.checkFileList
  316. this.defaultApplicationFileList = this.BaseTool.UPLOAD.transImg(this.applicationFileList)
  317. this.defaultRepairFileList = this.BaseTool.UPLOAD.transImg(this.repairFileList)
  318. this.defaultCheckFileList = this.BaseTool.UPLOAD.transImg(this.checkFileList)
  319. const { form: { setFieldsValue } } = this
  320. // 日期处理
  321. record.applyTime = this.BaseTool.Moment(record.applyTime, this.BaseTool.Date.PICKER_NORM_DATETIME_PATTERN)
  322. this.$nextTick(() => {
  323. setFieldsValue(Object.assign(pick(record, [
  324. 'id',
  325. 'sbId',
  326. 'partId',
  327. 'repairUserId',
  328. 'no',
  329. 'source',
  330. 'level',
  331. 'content',
  332. 'status',
  333. 'sbName',
  334. 'partName',
  335. 'remark'
  336. ])))
  337. })
  338. },
  339. getUsers () {
  340. queryUser({ status: 1 }).then(res => {
  341. this.userList = res.data
  342. })
  343. },
  344. save () {
  345. const { form: { validateFieldsAndScroll } } = this
  346. this.confirmLoading = true
  347. validateFieldsAndScroll((errors, values) => {
  348. if (errors) {
  349. this.confirmLoading = false
  350. return
  351. }
  352. // 日期处理
  353. values.applyTime = this.BaseTool.Date.formatter(values.applyTime, this.BaseTool.Date.PICKER_NORM_DATETIME_PATTERN)
  354. // 上传文件
  355. values.repairFileList = this.repairFileList
  356. values.applicationFileList = this.applicationFileList
  357. values.checkFileList = this.checkFileList
  358. if (this.BaseTool.String.isBlank(values.id)) {
  359. addRepairApplicationForm(values)
  360. .then(() => {
  361. this.handleCancel(values)
  362. }).catch(() => {
  363. this.confirmLoading = false
  364. })
  365. } else {
  366. updateRepairApplicationForm(values)
  367. .then(() => {
  368. this.handleCancel(values)
  369. }).catch(() => {
  370. this.confirmLoading = false
  371. })
  372. }
  373. })
  374. },
  375. handleCancel (values) {
  376. this.visible = false
  377. this.confirmLoading = false
  378. this.form.resetFields()
  379. if (this.BaseTool.Object.isNotBlank(values)) {
  380. this.$emit('ok', values)
  381. }
  382. },
  383. handleSbSelect () {
  384. this.$refs.sbInfoSelectModal.base({}, { filter: -1, status: 2 })
  385. },
  386. handleSbSelectd (keys, rows) {
  387. const [ key ] = keys
  388. const [ row ] = rows
  389. const { form: { setFieldsValue } } = this
  390. // 日期处理
  391. this.$nextTick(() => {
  392. setFieldsValue(Object.assign({
  393. 'sbId': key,
  394. 'sbName': row.name
  395. }))
  396. })
  397. },
  398. handlePartSelect () {
  399. const sbId = this.form.getFieldValue('sbId')
  400. this.$refs.partInfoSelectModal.base({ sbId })
  401. },
  402. handlePartSelected (keys, rows) {
  403. const [ key ] = keys
  404. const [ row ] = rows
  405. const { form: { setFieldsValue } } = this
  406. this.$nextTick(() => {
  407. setFieldsValue(Object.assign({
  408. 'partId': key,
  409. 'partName': row.name
  410. }))
  411. })
  412. },
  413. handleApplicationFileChange (info) {
  414. this.defaultApplicationFileList = info.fileList
  415. this.applicationFileList = this.setFileList(info, 11)
  416. },
  417. setFileList (info, type) {
  418. const file = info.file
  419. const fileList = info.fileList
  420. if (file.status === 'done') {
  421. return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
  422. } else if (file.status === 'removed') {
  423. return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
  424. } else if (file.status === 'error') {
  425. this.$message.error('上传失败')
  426. return []
  427. }
  428. }
  429. }
  430. }
  431. </script>