diff --git a/src/api/EquipmentEntryApply/index.js b/src/api/EquipmentEntryApply/index.js index 4b70308b..33f9d364 100644 --- a/src/api/EquipmentEntryApply/index.js +++ b/src/api/EquipmentEntryApply/index.js @@ -124,7 +124,7 @@ export const addInterDevice = (data = {}) => { // 修改装备 新接口 export const equipmentEditApiNew = (data = {}) => { return request({ - url: '/material-mall/order/editDevice', + url: '/material-mall/order/updateDevice', method: 'POST', data }) diff --git a/src/views/EquipmentEntryApply/equipmentInput/add.vue b/src/views/EquipmentEntryApply/equipmentInput/add.vue index ef32ab73..b5d81a86 100644 --- a/src/views/EquipmentEntryApply/equipmentInput/add.vue +++ b/src/views/EquipmentEntryApply/equipmentInput/add.vue @@ -1,12 +1,15 @@ @@ -335,7 +299,9 @@ import { getEquipmentAddIdApi, firstLevel, secondAndThirdLevel, - fourthToSixthLevel + fourthToSixthLevel, + getDeviceApi, + equipmentEditApiNew, } from '@/api/EquipmentEntryApply' import { getManufacturerSelectApi } from '@/api/EquipmentLedger/index.js' import ImageUpload from '@/components/ImageUpload' @@ -346,6 +312,9 @@ export default { emits: ['update:isVisible', 'submit', 'getOrderId'], // 声明事件 data() { return { + isSubmit: false, + query: {}, + pageTitle: '新增装备', // 下拉列表数据 majorList: [], processList: [], @@ -353,8 +322,8 @@ export default { manufacturerList: [], form: { major: '', // 专业 - process: '', // 工序 - category: '', // 类目 + process: [], // 工序 + category: [], // 类目 name: '', // 装备名称 specificationModel: '', // 规格型号 originalValue: '', // 资产原值 @@ -373,73 +342,72 @@ export default { // deviceTypeList: [], // 装备类型列表 mainFileList: [], // 展示图 certificateList: [], // 合格证 - inspectionList: [] // 检测证书 + inspectionList: [], // 检测证书 }, // 表单校验规则(所有字段均为必填) equipRules: { - major: [ - { required: true, message: '请选择专业', trigger: 'change' } - ], - process: [ - { required: true, message: '请选择工序', trigger: 'change' } - ], - category: [ - { required: true, message: '请选择装备类目', trigger: 'change' } - ], - name: [ - { required: true, message: '请输入装备名称', trigger: 'blur' } - ], - specificationModel: [ - { required: true, message: '请输入规格型号', trigger: 'blur' } - ], - originalValue: [ - { required: true, message: '请输入资产原值', trigger: 'blur' } - ], - productionDate: [ - { required: true, message: '请选择出厂日期', trigger: 'change' } - ], - manufacturerId: [ - { required: true, message: '请输入生产厂家', trigger: 'blur' } - ], - originalCode: [ - { required: true, message: '请输入装备原始编码', trigger: 'blur' } - ], - nextMaintenanceDate: [ - { required: true, message: '请选择下次维保日期', trigger: 'change' } - ], - maxServiceLifeYears: [ - { required: true, message: '请输入装备寿命', trigger: 'blur' } - ], - manageType: [ - { required: true, message: '请选择管理方式', trigger: 'change' } - ], - count: [ - { required: true, message: '请输入装备数量', trigger: 'blur' } - - ], - unit: [ - { required: true, message: '请输入计数单位', trigger: 'blur' } - ], - purchaseDate: [ - { required: true, message: '请选择采购日期', trigger: 'change' } - ], - // deviceTypeList: [ - // { required: true, message: '请选择装备类型', trigger: 'change' } - // ], - /* certificateList: [ - { required: true, message: '请上传合格证', trigger: 'change' } - ], - inspectionList: [ - { required: true, message: '请上传检测证书', trigger: 'change' } - ] */ - } + major: [{ required: true, message: '请选择专业', trigger: 'change' }], + process: [{ required: true, message: '请选择工序', trigger: 'change' }], + category: [{ required: true, message: '请选择装备类目', trigger: 'change' }], + name: [{ required: true, message: '请输入装备名称', trigger: 'blur' }], + specificationModel: [{ required: true, message: '请输入规格型号', trigger: 'blur' }], + originalValue: [{ required: true, message: '请输入资产原值', trigger: 'blur' }], + productionDate: [{ required: true, message: '请选择出厂日期', trigger: 'change' }], + manufacturerId: [{ required: true, message: '请输入生产厂家', trigger: 'blur' }], + originalCode: [{ required: true, message: '请输入装备原始编码', trigger: 'blur' }], + nextMaintenanceDate: [{ required: true, message: '请选择下次维保日期', trigger: 'change' }], + maxServiceLifeYears: [{ required: true, message: '请输入装备寿命', trigger: 'blur' }], + manageType: [{ required: true, message: '请选择管理方式', trigger: 'change' }], + count: [{ required: true, message: '请输入装备数量', trigger: 'blur' }], + unit: [{ required: true, message: '请输入计数单位', trigger: 'blur' }], + purchaseDate: [{ required: true, message: '请选择采购日期', trigger: 'change' }], + }, } }, created() { this.firstLevel() this.getManufacturerSelectList() + this.query = this.$route.query + if (this.query && this.query.maId) { + this.pageTitle = '编辑装备' + this.orderId = this.query.orderId + this.getInfo() + } }, methods: { + // 获取详情 + async getInfo() { + try { + const res = await getDeviceApi(this.query.maId) + console.log('🚀 ~ getInfo ~ res:', res) + this.form = res.data + this.form.mainFileList = res.data.appearanceImages + ? res.data.appearanceImages.map((item) => item.fileUrl).join(',') + : [] + this.form.certificateList = res.data.certificates + ? res.data.certificates.map((item) => item.fileUrl).join(',') + : [] + this.form.inspectionList = res.data.inspectionReports + ? res.data.inspectionReports.map((item) => item.fileUrl).join(',') + : [] + this.form.purchaseInvoices = res.data.purchaseInvoices + ? res.data.purchaseInvoices.map((item) => item.fileUrl).join(',') + : [] + this.form.process = [String(res.data.mainProcessId), String(res.data.subProcessId)].filter(Boolean) + console.log('🚀 ~ getInfo ~ this.form.process:', this.form.process) + this.form.category = [ + String(res.data.mainCategoryId), + String(res.data.subCategoryId), + String(res.data.branchId), + ].filter(Boolean) + const res2 = await secondAndThirdLevel({ firstLevelId: this.form.majorId }) + this.processList = this.convertToSubTree(res2.data) + const res3 = await fourthToSixthLevel({ thirdLevelId: this.form.subProcessId }) + this.categoryList = this.convertToSubTree(res3.data) + } catch (error) { + console.log('🚀 ~ getInfo ~ error:', error) + } + }, // 获取厂家 getManufacturerSelectList() { getManufacturerSelectApi().then((res) => { @@ -453,7 +421,7 @@ export default { * 获取一级类型 */ firstLevel() { - firstLevel().then(res => { + firstLevel().then((res) => { if (res.code === 200) { this.majorList = res.data } @@ -462,9 +430,9 @@ export default { majorChange(item) { if (!item) { this.processList = [] - this.form.process = '' + this.form.process = [] } else { - secondAndThirdLevel({ firstLevelId: item }).then(res => { + secondAndThirdLevel({ firstLevelId: item }).then((res) => { if (res.code === 200) { this.processList = this.convertToSubTree(res.data) } @@ -472,24 +440,23 @@ export default { } }, processChange(item) { + console.log('🚀 ~ processChange ~ item:', item) if (item.length === 0) { this.categoryList = [] - this.form.category = '' + this.form.category = [] } else { - fourthToSixthLevel({ thirdLevelId: item[item.length - 1] }).then(res => { + fourthToSixthLevel({ thirdLevelId: item[item.length - 1] }).then((res) => { if (res.code === 200) { this.categoryList = this.convertToSubTree(res.data) } }) } }, - categoryChange(item) { - - }, + categoryChange(item) {}, // 返回上一页 goBack() { - // this.$router.go(-1) - this.$router.push({ path: '/equipment/equipment-input/index' }) + this.$router.go(-1) + // this.$router.push({ path: '/equipment/equipment-input/index' }) }, deviceTypeChange(val) { if (val === 0) { @@ -525,11 +492,17 @@ export default { */ async handleSubmit() { console.log('🚀 ~ handleSubmit ~ this.form:', this.form) - this.$refs['formRef'].validate(async valid => { - if (valid) { - const result = await getEquipmentAddIdApi() - this.orderId = result.data.id - this.form.orderId = this.orderId + this.$refs['formRef'].validate(async (valid) => { + if (valid) { + if (this.isSubmit) return + this.isSubmit = true + const loading = this.$loading() + try { + if (!this.query.maId) { + const result = await getEquipmentAddIdApi() + this.orderId = result.data.id + this.form.orderId = this.orderId + } // 获取数组最后一个元素(最末级分类ID) // this.form.typeId = this.form.deviceTypeList[this.form.deviceTypeList.length - 1] // 获取类目的最后一个值 @@ -541,22 +514,22 @@ export default { if (this.form.mainFileList) { const arr = this.form.mainFileList.split(',') console.log('🚀 ~ 提交 ~ arr:', arr) - appearanceImages = arr.map(item => { + appearanceImages = arr.map((item) => { const parts = item.split('/') return { fileName: parts[parts.length - 1], - fileUrl: item + fileUrl: item, } }) console.log('🚀 ~ handleSubmit ~ appearanceImages:', appearanceImages) } if (this.form.certificateList) { const arr = this.form.certificateList.split(',') - certificates = arr.map(item => { + certificates = arr.map((item) => { const parts = item.split('/') return { fileName: parts[parts.length - 1], - fileUrl: item + fileUrl: item, } }) console.log('🚀 ~ handleSubmit ~ certificates:', certificates) @@ -567,11 +540,11 @@ export default { } if (this.form.inspectionList) { const arr = this.form.inspectionList.split(',') - inspectionReports = arr.map(item => { + inspectionReports = arr.map((item) => { const parts = item.split('/') return { fileName: parts[parts.length - 1], - fileUrl: item + fileUrl: item, } }) console.log('🚀 ~ handleSubmit ~ inspectionReports:', inspectionReports) @@ -582,17 +555,24 @@ export default { } if (this.form.purchaseInvoices) { const arr = this.form.purchaseInvoices.split(',') - purchaseInvoices = arr.map(item => { + purchaseInvoices = arr.map((item) => { const parts = item.split('/') return { fileName: parts[parts.length - 1], - fileUrl: item + fileUrl: item, } }) console.log('🚀 ~ handleSubmit ~ purchaseInvoices:', purchaseInvoices) } - const res = await addInterDevice({ ...this.form, appearanceImages, certificates, inspectionReports, purchaseInvoices }) + let res = null + const params = { ...this.form, appearanceImages, certificates, inspectionReports, purchaseInvoices } + if (this.query && this.query.maId) { + params.maId = this.query.maId + res = await equipmentEditApiNew(params) + } else { + res = await addInterDevice(params) + } if (res.code === 200) { // this.goBack() this.$router.push({ @@ -600,13 +580,18 @@ export default { query: { orderId: this.orderId, isAddVisible: false, - isApprovalVisible: false - } + isApprovalVisible: false, + }, }) } + } catch (error) { + console.log('🚀 ~ handleSubmit ~ error:', error) + } finally { + this.isSubmit = false + loading.close() } } - ) + }) }, /** * 转换类型数据为树形结构(适用于级联选择器) @@ -616,15 +601,15 @@ export default { const tree = [] // 构建节点映射 - list.forEach(item => { + list.forEach((item) => { map[item.value] = { value: item.value.toString(), - label: item.label + label: item.label, } }) // 构建树形关系 - list.forEach(item => { + list.forEach((item) => { const current = map[item.value] const parent = map[item.parentId] @@ -639,8 +624,8 @@ export default { }) return tree - } - } + }, + }, } diff --git a/src/views/EquipmentEntryApply/equipmentInput/index.vue b/src/views/EquipmentEntryApply/equipmentInput/index.vue index a257e9cb..da56febe 100644 --- a/src/views/EquipmentEntryApply/equipmentInput/index.vue +++ b/src/views/EquipmentEntryApply/equipmentInput/index.vue @@ -254,13 +254,13 @@ 查看 - + { if (res.code === 200) { this.$message({ @@ -515,6 +519,9 @@ export default { // this.goBack() this.$router.push({ path: '/equipment/equipmentEntry/equipment-entry-apply' }) } + }).finally(() => { + this.isSubmit = false + loading.close() }) }, @@ -559,10 +566,17 @@ export default { }, //编辑 - editRowInfo(orderId) { - this.orderId = orderId.toString() - this.isViewMode = false // 编辑模式 - this.isEditVisible = true + editRowInfo(row) { + // this.orderId = orderId.toString() + // this.isViewMode = false // 编辑模式 + // this.isEditVisible = true + this.$router.push({ + path: '/equipment/equipment-input/add', + query: { + maId: row.maId, + orderId: this.orderId + } + }) }, // 修改查看方法