BaseForm.vue 15 KB

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