diff --git a/src/api/part/quicklyCreateBom.js b/src/api/part/quicklyCreateBom.js index aadd9e5..17ba346 100644 --- a/src/api/part/quicklyCreateBom.js +++ b/src/api/part/quicklyCreateBom.js @@ -17,6 +17,7 @@ export const resetNodePartInfo = data => createAPI(`/part/quicklyBom/resetNodePa export const getPartInfoByNo = data => createAPI(`/part/quicklyBom/getPartInfoByNo`,'post',data) export const saveMainPartInfo = data => createAPI(`/part/quicklyBom/saveMainPartInfo`,'post',data) export const templateAdd = data => createAPI(`/part/quicklyBom/templateAdd`,'post',data) +export const templateUpdate = data => createAPI(`/part/quicklyBom/templateUpdate`,'post',data) export const getTemplateList = data => createAPI(`/part/quicklyBom/getTemplateList`,'post',data) export const chooseTemplate = data => createAPI(`/part/quicklyBom/chooseTemplate`,'post',data) export const getBomAndRoutingRevision = data => createAPI(`/part/quicklyBom/getBomAndRoutingRevision`,'post',data) diff --git a/src/views/modules/part/part_create.vue b/src/views/modules/part/part_create.vue index ba8b462..51e9e7c 100644 --- a/src/views/modules/part/part_create.vue +++ b/src/views/modules/part/part_create.vue @@ -41,9 +41,11 @@ - - 模板(新增) - + + + 模板({{ modalData.tempNo ? '编辑' : '新增' }}) + + - + @@ -883,7 +885,7 @@ import partUploadFile from "./part_upload_file" import {updateInquiryDetailStatusAndPart} from "../../../api/inquiry/inquiryDetail"; import {EventBus} from "../../../main"; import {getChooselist1} from "../../../api/chooselist/chooselist"; -import {chooseTemplate, getTemplateList, templateAdd} from "../../../api/part/quicklyCreateBom"; +import {chooseTemplate, getTemplateList, templateAdd, templateUpdate} from "../../../api/part/quicklyCreateBom"; export default { name: 'partCreate', components: { @@ -1106,6 +1108,7 @@ export default { copyAttributeList: [], fileList: [], templateList: [], + templateEditMode: false, // 模板编辑模式标记(true=编辑, false=新增) // ======== 列表表头 ======== columnList: [ { @@ -3470,12 +3473,31 @@ export default { this.$message.warning("请填写模板名称!") return } - templateAdd(this.tempData).then(({data}) => { + + // 确保 buNo 字段正确填充(可能需要从 bu 中提取) + if (!this.tempData.buNo || this.tempData.buNo === '') { + // 如果 bu 是 "site_buNo" 格式,提取 buNo + if (this.tempData.bu && this.tempData.bu.includes('_')) { + this.tempData.buNo = this.tempData.bu.split('_')[1] + } else { + // 否则 bu 本身就是 buNo + this.tempData.buNo = this.tempData.bu + } + } + + console.log('保存模板数据:', this.tempData) + console.log('保存模式:', this.templateEditMode ? '编辑' : '新增') + + // 根据模式选择调用新增还是更新API + const apiMethod = this.templateEditMode ? templateUpdate : templateAdd + const actionText = this.templateEditMode ? '更新' : '新增' + + apiMethod(this.tempData).then(({data}) => { if (data&&data.code===0){ this.getTemplateList() this.templateAddFlag = false this.$message({ - message: '操作成功', + message: actionText + '成功', type: 'success', duration: 1500, onClose: () => {} @@ -3485,6 +3507,8 @@ export default { confirmButtonText: '确定' }) } + }).catch(error => { + this.$message.error(actionText + '失败: ' + error.message) }) }, @@ -3498,10 +3522,14 @@ export default { }, chooseTemplate(){ + // 保存当前选中的模板编号,防止被覆盖 + const selectedTempNo = this.modalData.tempNo + chooseTemplate(this.modalData).then(({data}) => { if (data&&data.code===0) { Object.keys(data.data).forEach(key => { - if (key !== 'templateNo') { + // 跳过 templateNo 和 tempNo,避免覆盖用户选择的模板 + if (key !== 'templateNo' && key !== 'tempNo') { this.modalData[key] = data.data[key]; } }); @@ -3511,6 +3539,9 @@ export default { this.modalData.templateNo = data.data.bomTemplateNo this.modalData.templateName = data.data.bomTemplateName } + + // 恢复用户选择的模板编号 + this.modalData.tempNo = selectedTempNo } }) }, @@ -3536,8 +3567,88 @@ export default { }, handleTemplateAdd() { - this.tempData.templateNo = 'TEMPLATE' + Date.now() - this.templateAddFlag = true + // 判断是否选择了模板 + if (this.modalData.tempNo && this.modalData.tempNo !== '') { + // 编辑模式:加载选中模板的数据 + this.templateEditMode = true + + // 从 templateList 中找到对应的模板名称 + const selectedTemplate = this.templateList.find(t => t.templateNo === this.modalData.tempNo) + const templateName = selectedTemplate ? selectedTemplate.templateName : '' + + // 调用API获取模板详情(传递整个 modalData 对象) + chooseTemplate(this.modalData).then(({data}) => { + console.log('获取模板数据返回:', data) + if (data && data.code === 0 && data.data) { + console.log('模板详情数据:', data.data) + + // 处理 BU 数据 + let buValue = data.data.buNo || this.modalData.buNo || '' + let buNoValue = buValue + + // 如果 buValue 包含下划线,说明是 "site_buNo" 格式,需要提取 + if (buValue && buValue.includes('_')) { + buNoValue = buValue.split('_')[1] + } + + // 将模板数据填充到 tempData + this.tempData = { + site: this.$store.state.user.site, + bu: buValue, + buNo: buNoValue, + templateNo: this.modalData.tempNo, + templateName: templateName || data.data.templateName || '', + umId: data.data.umId || '', + umName: data.data.umName || '', + familyId: data.data.familyId || '', + familyName: data.data.familyName || '', + productGroupId1: data.data.productGroupId1 || '', + productGroupName1: data.data.productGroupName1 || '', + productGroupId2: data.data.productGroupId2 || '', + productGroupName2: data.data.productGroupName2 || '', + productGroupId3: data.data.productGroupId3 || '', + productGroupName3: data.data.productGroupName3 || '', + codeNo: data.data.codeNo || '', + codeDesc: data.data.codeDesc || '', + bomTemplateNo: data.data.bomTemplateNo || '', + bomTemplateName: data.data.bomTemplateName || '', + } + console.log('填充到 tempData 的数据:', this.tempData) + this.templateAddFlag = true + } else { + console.error('获取模板数据失败,返回数据:', data) + this.$message.error('获取模板数据失败: ' + (data ? data.msg : '未知错误')) + } + }).catch(error => { + console.error('获取模板数据异常:', error) + this.$message.error('获取模板数据异常: ' + error.message) + }) + } else { + // 新增模式:清空数据并生成新编码 + this.templateEditMode = false + this.tempData = { + site: this.$store.state.user.site, + bu: '', + buNo: '', + templateNo: 'TEMPLATE' + Date.now(), + templateName: '', + umId: '', + umName: '', + familyId: '', + familyName: '', + productGroupId1: '', + productGroupName1: '', + productGroupId2: '', + productGroupName2: '', + productGroupId3: '', + productGroupName3: '', + codeNo: '', + codeDesc: '', + bomTemplateNo: '', + bomTemplateName: '', + } + this.templateAddFlag = true + } } } }