BaseForm.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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-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-input
  22. disabled
  23. style="width: 80%"
  24. v-decorator="['cardNo']"/>
  25. <a-button type="primary" style="width: 20%" @click="handleSbSelect">选择</a-button>
  26. </a-form-item>
  27. </row-item>
  28. <row-item>
  29. <a-form-item
  30. label="检定设备名称"
  31. :labelCol="BaseTool.Constant.labelCol"
  32. :wrapperCol="BaseTool.Constant.wrapperCol"
  33. >
  34. <a-input
  35. disabled
  36. v-decorator="['sbName', {rules: [{required: false, message: '检定设备不能为空'}]}]"/>
  37. </a-form-item>
  38. </row-item>
  39. <row-item>
  40. <a-form-item
  41. label="型号"
  42. :labelCol="BaseTool.Constant.labelCol"
  43. :wrapperCol="BaseTool.Constant.wrapperCol"
  44. >
  45. <a-input
  46. disabled
  47. v-decorator="['sbModel']"/>
  48. </a-form-item>
  49. </row-item>
  50. <row-item>
  51. <a-form-item
  52. label="检定周期"
  53. :labelCol="BaseTool.Constant.labelCol"
  54. :wrapperCol="BaseTool.Constant.wrapperCol"
  55. >
  56. <a-input
  57. disabled
  58. suffix="月"
  59. v-decorator="['checkPeriod']"/>
  60. </a-form-item>
  61. </row-item>
  62. <row-item>
  63. <a-form-item
  64. label="检定单号"
  65. :labelCol="BaseTool.Constant.labelCol"
  66. :wrapperCol="BaseTool.Constant.wrapperCol"
  67. >
  68. <a-input
  69. v-decorator="['no', {rules: [{required: true, message: '检定单号不能为空'}]}]"/>
  70. </a-form-item>
  71. </row-item>
  72. <row-item>
  73. <a-form-item
  74. label="检定日期"
  75. :labelCol="BaseTool.Constant.labelCol"
  76. :wrapperCol="BaseTool.Constant.wrapperCol"
  77. >
  78. <a-date-picker
  79. style="width: 100%"
  80. :format="BaseTool.Date.PICKER_NORM_DATE_PATTERN"
  81. v-decorator="['lastDate', {rules: [{required: true, message: '检定日期不能为空'}]}]" />
  82. </a-form-item>
  83. </row-item>
  84. <row-item>
  85. <a-form-item
  86. label="检定人"
  87. :labelCol="BaseTool.Constant.labelCol"
  88. :wrapperCol="BaseTool.Constant.wrapperCol"
  89. >
  90. <a-input
  91. v-decorator="['name']"/>
  92. </a-form-item>
  93. </row-item>
  94. <row-item>
  95. <a-form-item
  96. label="检定单位"
  97. :labelCol="BaseTool.Constant.labelCol"
  98. :wrapperCol="BaseTool.Constant.wrapperCol"
  99. >
  100. <a-input
  101. v-decorator="['requirement', {rules: [{required: false, message: '备注不能为空'}]}]"/>
  102. </a-form-item>
  103. </row-item>
  104. <row-item>
  105. <a-form-item
  106. label="准确度等级"
  107. :labelCol="BaseTool.Constant.labelCol"
  108. :wrapperCol="BaseTool.Constant.wrapperCol"
  109. >
  110. <a-input
  111. disabled
  112. v-decorator="['fdjxh']" />
  113. </a-form-item>
  114. </row-item>
  115. <row-item>
  116. <a-form-item
  117. label="备注"
  118. :labelCol="BaseTool.Constant.labelCol"
  119. :wrapperCol="BaseTool.Constant.wrapperCol"
  120. >
  121. <a-input
  122. v-decorator="['remark']" />
  123. </a-form-item>
  124. </row-item>
  125. <row-item>
  126. <a-form-item
  127. label="管理状态"
  128. :labelCol="BaseTool.Constant.labelCol"
  129. :wrapperCol="BaseTool.Constant.wrapperCol"
  130. >
  131. <a-select v-decorator="['sbStatus', {rules: [{required: true, message: '管理状态不能为空'}]}]" placeholder="请选择">
  132. <a-select-option
  133. v-for="(label,value) in statusMap"
  134. :key="value"
  135. :label="label"
  136. :value="parseInt(value)">{{ label }}
  137. </a-select-option>
  138. </a-select>
  139. </a-form-item>
  140. </row-item>
  141. </row-list>
  142. <row-list :col="2">
  143. <row-item>
  144. <a-form-item
  145. label="图片"
  146. :labelCol="BaseTool.Constant.labelCol"
  147. :wrapperCol="BaseTool.Constant.wrapperCol"
  148. >
  149. <a-upload
  150. :action="uploadUrl"
  151. :multiple="false"
  152. list-type="picture"
  153. accept="image/*"
  154. :file-list="this.defaultCheckImgList"
  155. @change="handleCheckImgChange"
  156. :headers="headers"
  157. >
  158. <a-button> <a-icon type="upload" /> 选择上传图片 </a-button>
  159. </a-upload>
  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. :file-list="this.defaultCheckFileList"
  172. @change="handleCheckFileChange"
  173. :headers="headers"
  174. >
  175. <a-button> <a-icon type="upload" /> 选择上传文件 </a-button>
  176. </a-upload>
  177. </a-form-item>
  178. </row-item>
  179. </row-list>
  180. </a-form>
  181. <template slot="footer">
  182. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  183. </template>
  184. <measure-sb-info-select-modal ref="sbInfoSelectModal" @selected="handleSbSelectd"/>
  185. </a-modal>
  186. </template>
  187. <script>
  188. import pick from 'lodash.pick'
  189. import { STable, Ellipsis } from '@/components'
  190. import { addCheckStandard, updateCheckStandard } from '@/api/sb/measurelog'
  191. import BaseTool from '../../../../utils/tool'
  192. import { queryUser } from '@/api/upms/user'
  193. import { uploadUrl } from '@/api/upms/file'
  194. import MeasureSbInfoSelectModal from '@/views/sb/measure/modules/MeasureSbInfoSelectModal'
  195. import Vue from 'vue'
  196. import { ACCESS_TOKEN } from '@/store/mutation-types'
  197. export default {
  198. name: 'BaseCheckStandard',
  199. components: {
  200. STable,
  201. Ellipsis,
  202. MeasureSbInfoSelectModal
  203. },
  204. data () {
  205. return {
  206. confirmLoading: false,
  207. modalTitle: null,
  208. form: this.$form.createForm(this),
  209. visible: false,
  210. // 下拉框map
  211. statusMap: {},
  212. checkImgList: [], // 图片
  213. checkFileList: [], // 文档
  214. defaultCheckImgList: [],
  215. defaultCheckFileList: [],
  216. uploadUrl: uploadUrl,
  217. userList: {},
  218. editingKey: '',
  219. headers: {
  220. Authorization: 'Bearer ' + Vue.ls.get(ACCESS_TOKEN)
  221. },
  222. data: [],
  223. cacheData: []
  224. }
  225. },
  226. props: {
  227. },
  228. created () {
  229. // 下拉框map
  230. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SB_MEASURE_STATUS)
  231. },
  232. methods: {
  233. base (record, sbInfo) {
  234. this.visible = true
  235. queryUser({}).then(res => {
  236. this.userList = res.data
  237. })
  238. // 如果是空标识添加
  239. if (this.BaseTool.Object.isBlank(record)) {
  240. this.modalTitle = '添加'
  241. this.data = []
  242. this.cacheData = []
  243. if (sbInfo != null) {
  244. const { form: { setFieldsValue } } = this
  245. // 日期处理
  246. this.$nextTick(() => {
  247. setFieldsValue({ sbId: sbInfo.id, fdjxh: sbInfo.fdjxh, cardNo: sbInfo.cardNo, sbStatus: sbInfo.status, sbModel: sbInfo.model, sbName: sbInfo.name, checkPeriod: sbInfo.checkPeriod })
  248. })
  249. }
  250. return
  251. }
  252. this.modalTitle = '编辑'
  253. if (this.BaseTool.Object.isBlank(record.id)) {
  254. this.modalTitle = '复制'
  255. }
  256. this.checkImgList = record.checkImgList
  257. this.checkFileList = record.checkFileList
  258. this.defaultCheckImgList = this.BaseTool.UPLOAD.transImg(this.checkImgList)
  259. this.defaultCheckFileList = this.BaseTool.UPLOAD.transImg(this.checkFileList)
  260. const { form: { setFieldsValue } } = this
  261. if (record.lastDate != null) {
  262. record.lastDate = this.BaseTool.Moment(record.lastDate, this.BaseTool.Date.PICKER_NORM_DATE_PATTERN)
  263. this.$nextTick(() => {
  264. setFieldsValue(Object.assign(pick(record, [
  265. 'lastDate'
  266. ])))
  267. })
  268. }
  269. // 日期处理
  270. this.$nextTick(() => {
  271. setFieldsValue(Object.assign(pick(record, [
  272. 'id',
  273. 'sbId',
  274. 'name',
  275. 'no',
  276. 'type',
  277. 'period',
  278. 'sbStatus',
  279. 'sbName',
  280. 'sbModel',
  281. 'sbNo',
  282. 'checkDate',
  283. 'nextCheckDate',
  284. 'cardNo',
  285. 'checkPeriod',
  286. 'checkUserId',
  287. 'periodType',
  288. 'actionType',
  289. 'enable',
  290. 'requirement',
  291. 'fdjxh',
  292. 'remark'
  293. ])))
  294. })
  295. this.data = BaseTool.Object.copy(record.paramList)
  296. this.cacheData = BaseTool.Object.copy(record.paramList)
  297. this.editingKey = ''
  298. },
  299. save () {
  300. const { form: { validateFieldsAndScroll } } = this
  301. this.confirmLoading = true
  302. validateFieldsAndScroll((errors, values) => {
  303. if (errors) {
  304. this.confirmLoading = false
  305. return
  306. }
  307. values.paramList = this.data
  308. // 上传文件
  309. values.checkImgList = this.checkImgList
  310. values.checkFileList = this.checkFileList
  311. // 日期数据的处理
  312. values.lastDate = BaseTool.Date.formatter(values.lastDate, BaseTool.Date.PICKER_NORM_DATE_PATTERN)
  313. if (this.BaseTool.String.isBlank(values.id)) {
  314. addCheckStandard(values)
  315. .then(() => {
  316. this.handleCancel(values)
  317. }).catch(() => {
  318. this.confirmLoading = false
  319. })
  320. } else {
  321. updateCheckStandard(values)
  322. .then(() => {
  323. this.handleCancel(values)
  324. }).catch(() => {
  325. this.confirmLoading = false
  326. })
  327. }
  328. })
  329. },
  330. handleCancel (values) {
  331. this.visible = false
  332. this.confirmLoading = false
  333. this.form.resetFields()
  334. if (this.BaseTool.Object.isNotBlank(values)) {
  335. this.$emit('ok', values)
  336. }
  337. },
  338. handleChange (value, key, column) {
  339. const newData = [...this.data]
  340. const target = newData.filter(item => key === item.id)[0]
  341. if (target) {
  342. target[column] = value
  343. this.data = newData
  344. }
  345. },
  346. cancel (key) {
  347. const newData = [...this.data]
  348. const target = newData.filter(item => key === item.id)[0]
  349. this.editingKey = ''
  350. if (!this.checkParams(target)) {
  351. const data = [...this.data]
  352. const cacheData = [...this.cacheData]
  353. this.data = data.filter(item => item.id !== key)
  354. this.cacheData = cacheData.filter(item => item.id !== key)
  355. return
  356. }
  357. if (target) {
  358. Object.assign(target, this.cacheData.filter(item => key === item.id)[0])
  359. console.log(target, 'target')
  360. delete target.editable
  361. this.data = newData
  362. }
  363. },
  364. handleCheckImgChange (info) {
  365. this.defaultCheckImgList = info.fileList
  366. this.checkImgList = this.setFileList(info, 31)
  367. },
  368. handleCheckFileChange (info) {
  369. this.defaultCheckFileList = info.fileList
  370. this.checkFileList = this.setFileList(info, 32)
  371. },
  372. setFileList (info, type) {
  373. const file = info.file
  374. const fileList = info.fileList
  375. if (file.status === 'done') {
  376. return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
  377. } else if (file.status === 'removed') {
  378. return this.BaseTool.UPLOAD.getUploadFileDTO(fileList, type)
  379. } else if (file.status === 'error') {
  380. this.$message.error('上传失败')
  381. return null
  382. }
  383. },
  384. handleSbSelect () {
  385. this.$refs.sbInfoSelectModal.base()
  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. 'sbModel': row.model,
  397. 'checkPeriod': row.checkPeriod,
  398. 'cardNo': row.cardNo
  399. }))
  400. })
  401. }
  402. }
  403. }
  404. </script>