BaseForm.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="1200"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. @cancel="handleCancel"
  8. >
  9. <a-form :form="form">
  10. <a-form-item v-show="false">
  11. <a-input v-decorator="['id']" type="hidden"/>
  12. <a-input v-decorator="['sbId']" type="hidden"/>
  13. <a-input v-decorator="['part']" 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. v-decorator="['no', {rules: [{required: false, message: '检定单号不能为空'}]}]"/>
  24. </a-form-item>
  25. </row-item>
  26. <row-item>
  27. <a-form-item
  28. label="检定日期"
  29. :labelCol="BaseTool.Constant.labelCol"
  30. :wrapperCol="BaseTool.Constant.wrapperCol"
  31. >
  32. <a-date-picker
  33. style="width: 100%"
  34. :format="BaseTool.Date.PICKER_NORM_DATE_PATTERN"
  35. v-decorator="['lastDate', {rules: [{required: false, message: '检定日期不能为空'}]}]" />
  36. </a-form-item>
  37. </row-item>
  38. <!-- <row-item>
  39. <a-form-item
  40. label="检查部位"
  41. :labelCol="BaseTool.Constant.labelCol"
  42. :wrapperCol="BaseTool.Constant.wrapperCol"
  43. >
  44. <a-input
  45. disabled
  46. style="width: 80%"
  47. v-decorator="['partName', {rules: [{required: false, message: '检查部位不能为空'}]}]"/>
  48. <a-button type="primary" style="width: 20%" @click="handlePartSelect">选择</a-button>
  49. </a-form-item>
  50. </row-item>-->
  51. <row-item>
  52. <a-form-item
  53. label="检定人"
  54. :labelCol="BaseTool.Constant.labelCol"
  55. :wrapperCol="BaseTool.Constant.wrapperCol"
  56. >
  57. <a-input
  58. v-decorator="['name']"/>
  59. </a-form-item>
  60. </row-item>
  61. </row-list>
  62. <row-list :col="1">
  63. <row-item>
  64. <a-form-item
  65. label="备注"
  66. :labelCol="BaseTool.Constant.labelCol2"
  67. :wrapperCol="BaseTool.Constant.wrapperCol2"
  68. >
  69. <a-textarea
  70. :rows="4"
  71. v-decorator="['requirement', {rules: [{required: true, message: '备注不能为空'}]}]"/>
  72. </a-form-item>
  73. </row-item>
  74. </row-list>
  75. <row-list :col="2">
  76. <row-item>
  77. <a-form-item
  78. label="图片"
  79. :labelCol="BaseTool.Constant.labelCol"
  80. :wrapperCol="BaseTool.Constant.wrapperCol"
  81. >
  82. <a-upload
  83. :action="uploadUrl"
  84. :multiple="false"
  85. list-type="picture"
  86. accept="image/*"
  87. :file-list="this.defaultCheckImgList"
  88. @change="handleCheckImgChange"
  89. :headers="headers"
  90. >
  91. <a-button> <a-icon type="upload" /> 选择上传图片 </a-button>
  92. </a-upload>
  93. </a-form-item>
  94. </row-item>
  95. <row-item>
  96. <a-form-item
  97. label="文件"
  98. :labelCol="BaseTool.Constant.labelCol"
  99. :wrapperCol="BaseTool.Constant.wrapperCol"
  100. >
  101. <a-upload
  102. :action="uploadUrl"
  103. :multiple="true"
  104. :file-list="this.defaultCheckFileList"
  105. @change="handleCheckFileChange"
  106. :headers="headers"
  107. >
  108. <a-button> <a-icon type="upload" /> 选择上传文件 </a-button>
  109. </a-upload>
  110. </a-form-item>
  111. </row-item>
  112. </row-list>
  113. </a-form>
  114. <!-- <a-tabs type="card" default-active-key="1">
  115. <a-tab-pane key="1" tab="点检标准参数">
  116. <div class="table-operator">
  117. <a-button size="small" type="primary" @click="handleAdd">
  118. <a-icon type="plus"/>
  119. 添加
  120. </a-button>
  121. <a-button class="margin-left8" size="small" type="danger" @click="handleDel">
  122. <a-icon type="delete"/>
  123. 删除
  124. </a-button>
  125. </div>
  126. <a-table
  127. bordered
  128. :data-source="data"
  129. :columns="columns"
  130. tableLayout="auto"
  131. rowKey="id"
  132. :row-selection="rowSelection">
  133. <template
  134. slot="name"
  135. slot-scope="text, record, index"
  136. >
  137. <div>
  138. <a-input
  139. class="my-form-item-required"
  140. v-if="record.editable"
  141. style="margin: -5px 0"
  142. :value="text"
  143. @change="e => handleChange(e.target.value, record.id, 'name')"
  144. />
  145. <template v-else>
  146. {{ text }}
  147. </template>
  148. </div>
  149. </template>
  150. <template
  151. slot="type"
  152. slot-scope="text, record, index"
  153. >
  154. <div>
  155. <a-select
  156. v-if="record.editable"
  157. style="width: 80px"
  158. :defaultValue="1"
  159. @change="e => handleChange(e, record.id, 'type')"
  160. placeholder="请选择">
  161. <a-select-option
  162. v-for="(label,value) in paramTypeMap"
  163. :key="value"
  164. :label="label"
  165. :value="parseInt(value)">{{ label }}
  166. </a-select-option>
  167. </a-select>
  168. <template v-else>
  169. {{ BaseTool.Table.getMapText(paramTypeMap, text) }}
  170. </template>
  171. </div>
  172. </template>
  173. <template
  174. slot="upperLimit"
  175. slot-scope="text, record, index"
  176. >
  177. <div>
  178. <a-input
  179. v-if="record.editable"
  180. style="margin: -5px 0"
  181. :value="text"
  182. @change="e => handleChange(e.target.value, record.id, 'upperLimit')"
  183. />
  184. <template v-else>
  185. {{ text }}
  186. </template>
  187. </div>
  188. </template>
  189. <template
  190. slot="lowerrLimit"
  191. slot-scope="text, record, index"
  192. >
  193. <div>
  194. <a-input
  195. v-if="record.editable"
  196. style="margin: -5px 0"
  197. :value="text"
  198. @change="e => handleChange(e.target.value, record.id, 'lowerrLimit')"
  199. />
  200. <template v-else>
  201. {{ text }}
  202. </template>
  203. </div>
  204. </template>
  205. <template
  206. slot="referenceValue"
  207. slot-scope="text, record, index"
  208. >
  209. <div>
  210. <a-input
  211. v-if="record.editable"
  212. style="margin: -5px 0"
  213. :value="text"
  214. @change="e => handleChange(e.target.value, record.id, 'referenceValue')"
  215. />
  216. <template v-else>
  217. {{ text }}
  218. </template>
  219. </div>
  220. </template>
  221. <template
  222. slot="normalSelection"
  223. slot-scope="text, record, index"
  224. >
  225. <div>
  226. <a-input
  227. v-if="record.editable"
  228. style="margin: -5px 0"
  229. :value="text"
  230. @change="e => handleChange(e.target.value, record.id, 'normalSelection')"
  231. />
  232. <template v-else>
  233. {{ text }}
  234. </template>
  235. </div>
  236. </template>
  237. <template
  238. slot="instruction"
  239. slot-scope="text, record, index"
  240. >
  241. <div>
  242. <a-input
  243. v-if="record.editable"
  244. style="margin: -5px 0"
  245. :value="text"
  246. @change="e => handleChange(e.target.value, record.id, 'instruction')"
  247. />
  248. <template v-else>
  249. {{ text }}
  250. </template>
  251. </div>
  252. </template>
  253. <template slot="operation" slot-scope="text, record, index">
  254. <div class="editable-row-operations">
  255. <span v-if="record.editable">
  256. <a @click="() => saveParam(record.id)">保存</a>
  257. <a-divider type="vertical"/>
  258. <a-popconfirm title="确定取消吗?" @confirm="() => cancel(record.id)">
  259. <a>取消</a>
  260. </a-popconfirm>
  261. </span>
  262. <span v-else>
  263. <a :disabled="editingKey !== ''" @click="() => edit(record.id)">编辑</a>
  264. </span>
  265. </div>
  266. </template>
  267. </a-table>
  268. </a-tab-pane>
  269. </a-tabs>-->
  270. <template slot="footer">
  271. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  272. </template>
  273. <part-info-select-modal ref="partInfoSelectModal" @selected="handlePartSelected"/>
  274. </a-modal>
  275. </template>
  276. <script>
  277. import pick from 'lodash.pick'
  278. import { STable, Ellipsis } from '@/components'
  279. import { addCheckStandard, updateCheckStandard } from '@/api/sb/measurelog'
  280. import BaseTool from '../../../../utils/tool'
  281. import { queryUser } from '@/api/upms/user'
  282. import { uploadUrl } from '@/api/upms/file'
  283. import PartInfoSelectModal from '@/views/part/info/modules/PartInfoSelectModal'
  284. import Vue from 'vue'
  285. import { ACCESS_TOKEN } from '@/store/mutation-types'
  286. export default {
  287. name: 'BaseCheckStandard',
  288. components: {
  289. STable,
  290. Ellipsis,
  291. PartInfoSelectModal
  292. },
  293. data () {
  294. return {
  295. confirmLoading: false,
  296. modalTitle: null,
  297. form: this.$form.createForm(this),
  298. visible: false,
  299. // 下拉框map
  300. typeMap: {},
  301. actionTypeMap: {},
  302. paramTypeMap: {},
  303. enableMap: {},
  304. periodTypeMap: {},
  305. checkImgList: [], // 图片
  306. checkFileList: [], // 文档
  307. defaultCheckImgList: [],
  308. defaultCheckFileList: [],
  309. uploadUrl: uploadUrl,
  310. userList: {},
  311. editingKey: '',
  312. headers: {
  313. Authorization: 'Bearer ' + Vue.ls.get(ACCESS_TOKEN)
  314. },
  315. rowSelection: {
  316. onChange: (selectedRowKeys, selectedRows) => {
  317. this.selectedRowKeys = selectedRowKeys
  318. this.selectedRows = selectedRows
  319. }
  320. },
  321. // 表头
  322. columns: [
  323. {
  324. title: '序号',
  325. dataIndex: 'index',
  326. customRender: (text, record, index) => {
  327. return index + 1
  328. }
  329. },
  330. {
  331. title: '名称',
  332. dataIndex: 'name',
  333. scopedSlots: { customRender: 'name' }
  334. },
  335. {
  336. title: '类型',
  337. dataIndex: 'type',
  338. scopedSlots: { customRender: 'type' }
  339. },
  340. {
  341. title: '上限',
  342. dataIndex: 'upperLimit',
  343. scopedSlots: { customRender: 'upperLimit' }
  344. },
  345. {
  346. title: '下限',
  347. dataIndex: 'lowerrLimit',
  348. scopedSlots: { customRender: 'lowerrLimit' }
  349. },
  350. {
  351. title: '参考值',
  352. dataIndex: 'referenceValue',
  353. scopedSlots: { customRender: 'referenceValue' }
  354. },
  355. {
  356. title: '正常选型',
  357. dataIndex: 'normalSelection',
  358. scopedSlots: { customRender: 'normalSelection' }
  359. },
  360. {
  361. title: '说明',
  362. dataIndex: 'instruction',
  363. scopedSlots: { customRender: 'instruction' }
  364. },
  365. {
  366. title: '操作',
  367. dataIndex: 'operation',
  368. width: 150,
  369. scopedSlots: { customRender: 'operation' }
  370. }
  371. ],
  372. data: [],
  373. cacheData: [],
  374. selectedRowKeys: [],
  375. selectedRows: [],
  376. options: {
  377. rowSelection: {
  378. selectedRowKeys: this.selectedRowKeys
  379. }
  380. }
  381. }
  382. },
  383. props: {
  384. },
  385. created () {
  386. // 下拉框map
  387. this.paramTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_STANDARD_PARAM_TYPE)
  388. this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_STANDARD_TYPE)
  389. this.periodTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_PERIOD_TYPE)
  390. this.actionTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_ACTION_TYPE)
  391. this.enableMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
  392. },
  393. methods: {
  394. base (record, sbId) {
  395. this.visible = true
  396. queryUser({}).then(res => {
  397. this.userList = res.data
  398. })
  399. // 如果是空标识添加
  400. if (this.BaseTool.Object.isBlank(record)) {
  401. this.modalTitle = '添加'
  402. this.data = []
  403. this.cacheData = []
  404. if (sbId != null) {
  405. const { form: { setFieldsValue } } = this
  406. // 日期处理
  407. this.$nextTick(() => {
  408. setFieldsValue({ sbId: sbId })
  409. })
  410. }
  411. return
  412. }
  413. this.modalTitle = '编辑'
  414. if (this.BaseTool.Object.isBlank(record.id)) {
  415. this.modalTitle = '复制'
  416. }
  417. this.checkImgList = record.checkImgList
  418. this.checkFileList = record.checkFileList
  419. this.defaultCheckImgList = this.BaseTool.UPLOAD.transImg(this.checkImgList)
  420. this.defaultCheckFileList = this.BaseTool.UPLOAD.transImg(this.checkFileList)
  421. const { form: { setFieldsValue } } = this
  422. if (record.lastDate != null) {
  423. record.lastDate = this.BaseTool.Moment(record.lastDate, this.BaseTool.Date.PICKER_NORM_DATE_PATTERN)
  424. this.$nextTick(() => {
  425. setFieldsValue(Object.assign(pick(record, [
  426. 'lastDate'
  427. ])))
  428. })
  429. }
  430. // 日期处理
  431. this.$nextTick(() => {
  432. setFieldsValue(Object.assign(pick(record, [
  433. 'id',
  434. 'sbId',
  435. 'name',
  436. 'no',
  437. 'type',
  438. 'period',
  439. 'part',
  440. 'partName',
  441. 'checkUserId',
  442. 'periodType',
  443. 'actionType',
  444. 'enable',
  445. 'requirement',
  446. 'remark'
  447. ])))
  448. })
  449. this.data = BaseTool.Object.copy(record.paramList)
  450. this.cacheData = BaseTool.Object.copy(record.paramList)
  451. this.editingKey = ''
  452. },
  453. save () {
  454. const { form: { validateFieldsAndScroll } } = this
  455. this.confirmLoading = true
  456. validateFieldsAndScroll((errors, values) => {
  457. if (errors) {
  458. this.confirmLoading = false
  459. return
  460. }
  461. values.paramList = this.data
  462. // 上传文件
  463. values.checkImgList = this.checkImgList
  464. values.checkFileList = this.checkFileList
  465. // 日期数据的处理
  466. values.lastDate = BaseTool.Date.formatter(values.lastDate, BaseTool.Date.PICKER_NORM_DATE_PATTERN)
  467. if (this.BaseTool.String.isBlank(values.id)) {
  468. addCheckStandard(values)
  469. .then(() => {
  470. this.handleCancel(values)
  471. }).catch(() => {
  472. this.confirmLoading = false
  473. })
  474. } else {
  475. updateCheckStandard(values)
  476. .then(() => {
  477. this.handleCancel(values)
  478. }).catch(() => {
  479. this.confirmLoading = false
  480. })
  481. }
  482. })
  483. },
  484. handleCancel (values) {
  485. this.visible = false
  486. this.confirmLoading = false
  487. this.form.resetFields()
  488. if (this.BaseTool.Object.isNotBlank(values)) {
  489. this.$emit('ok', values)
  490. }
  491. },
  492. handleChange (value, key, column) {
  493. const newData = [...this.data]
  494. const target = newData.filter(item => key === item.id)[0]
  495. if (target) {
  496. target[column] = value
  497. this.data = newData
  498. }
  499. },
  500. edit (key) {
  501. const newData = [...this.data]
  502. const target = newData.filter(item => key === item.id)[0]
  503. this.editingKey = key
  504. if (target) {
  505. target.editable = true
  506. this.data = newData
  507. }
  508. },
  509. saveParam (key) {
  510. const newData = [...this.data]
  511. const newCacheData = [...this.cacheData]
  512. const target = newData.filter(item => key === item.id)[0]
  513. // 校验数据
  514. if (!this.checkParams(target)) {
  515. return false
  516. }
  517. const targetCache = newCacheData.filter(item => key === item.id)[0]
  518. console.log(targetCache, 686688)
  519. if (target && targetCache) {
  520. delete target.editable
  521. this.data = newData
  522. Object.assign(targetCache, target)
  523. this.cacheData = newCacheData
  524. }
  525. this.editingKey = ''
  526. },
  527. checkParams (param) {
  528. if (BaseTool.Object.isBlank(param.name)) {
  529. this.$message.error('参数名称不能为空')
  530. return false
  531. }
  532. return true
  533. },
  534. cancel (key) {
  535. const newData = [...this.data]
  536. const target = newData.filter(item => key === item.id)[0]
  537. this.editingKey = ''
  538. if (!this.checkParams(target)) {
  539. const data = [...this.data]
  540. const cacheData = [...this.cacheData]
  541. this.data = data.filter(item => item.id !== key)
  542. this.cacheData = cacheData.filter(item => item.id !== key)
  543. return
  544. }
  545. if (target) {
  546. Object.assign(target, this.cacheData.filter(item => key === item.id)[0])
  547. console.log(target, 'target')
  548. delete target.editable
  549. this.data = newData
  550. }
  551. },
  552. handleAdd () {
  553. if (this.editingKey !== '') {
  554. this.$message.error('请保存后再添加')
  555. return false
  556. }
  557. const { data, cacheData } = this
  558. console.log(this.data, this.cacheData)
  559. const newParam = this.getNewParam()
  560. const newCache = { ...newParam }
  561. data.push(newParam)
  562. cacheData.push(newCache)
  563. },
  564. handleDel () {
  565. const data = [...this.data]
  566. const cacheData = [...this.cacheData]
  567. this.data = data.filter(item => !this.selectedRowKeys.includes(item.id))
  568. this.cacheData = cacheData.filter(item => !this.selectedRowKeys.includes(item.id))
  569. if (this.selectedRowKeys.includes(this.editingKey)) {
  570. this.editingKey = ''
  571. }
  572. },
  573. getNewParam () {
  574. const newParam = {
  575. name: '',
  576. type: '1',
  577. upperLimit: '',
  578. lowerrLimit: '',
  579. referenceValue: '',
  580. normalSelection: '',
  581. instruction: ''
  582. }
  583. newParam.id = new Date().getTime()
  584. newParam.editable = true
  585. this.editingKey = newParam.id
  586. console.log(newParam, 'newparam')
  587. return newParam
  588. },
  589. handlePartSelect () {
  590. const sbId = this.form.getFieldValue('sbId')
  591. this.$refs.partInfoSelectModal.base({ sbId })
  592. },
  593. handlePartSelected (keys, rows) {
  594. const [ key ] = keys
  595. const [ row ] = rows
  596. const { form: { setFieldsValue } } = this
  597. this.$nextTick(() => {
  598. setFieldsValue(Object.assign({
  599. 'part': key,
  600. 'partName': row.name
  601. }))
  602. })
  603. },
  604. handleCheckImgChange (info) {
  605. this.defaultCheckImgList = info.fileList
  606. this.checkImgList = this.setFileList(info, 31)
  607. },
  608. handleCheckFileChange (info) {
  609. this.defaultCheckFileList = info.fileList
  610. this.checkFileList = this.setFileList(info, 32)
  611. },
  612. setFileList (info, type) {
  613. const file = info.file
  614. const fileList = info.fileList
  615. if (file.status === 'done') {
  616. return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
  617. } else if (file.status === 'removed') {
  618. return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
  619. } else if (file.status === 'error') {
  620. this.$message.error('上传失败')
  621. return null
  622. }
  623. }
  624. }
  625. }
  626. </script>