diff --git a/src/components/Template/Step.vue b/src/components/Template/Step.vue index 8543642..ffbda5e 100644 --- a/src/components/Template/Step.vue +++ b/src/components/Template/Step.vue @@ -341,15 +341,104 @@ export default { } }) }, - getSjResource(){ + getStepResource(){ + const sj = []; + let yq = []; const stepData = this.steps.map((step, index) => { const stepComponentRef = this.$refs[`stepCompRef_${index}`]; if(stepComponentRef && stepComponentRef.length > 0){ const {sjResource,yqResource} = this.$refs[`stepCompRef_${index}`][0]?.getSjResource(); - return { type: step.type, sjResource, yqResource } + if(sjResource && sjResource.length > 0){ + sj.push(...sjResource); + } + if(yqResource && yqResource.length > 0){ + yq.push(...yqResource); + } } }) - console.log(stepData,"steps") + + // 对sj数组根据type和value值去重,并将yl按单位换算后累加 + const uniqueSj = []; + const sjMap = new Map(); + + // 体积单位转换为基本单位L的倍数 + const volumeUnits = { + 'pL': 1e-12, + 'nL': 1e-9, + 'uL': 1e-6, + 'mL': 1e-3, + 'L': 1 + }; + + // 质量单位转换为基本单位g的倍数 + const massUnits = { + 'pg': 1e-12, + 'ng': 1e-9, + 'ug': 1e-6, + 'mg': 1e-3, + 'g': 1, + 'kg': 1e3 + }; + + for(const item of sj) { + const key = `${item.type}_${item.value}`; + console.log(item,"item") + if(sjMap.has(key)) { + // 如果已存在相同type和value的项,累加yl值 + const existingItem = sjMap.get(key); + console.log(existingItem,"existingItem") + // 根据类型选择合适的单位转换 + let currentItemYlInBaseUnit, existingItemYlInBaseUnit; + if(item.type === 'sj') { + // 体积单位转换 + const currentItemYl = isNaN(parseFloat(item.yl)) ? 0 : parseFloat(item.yl); + const existingItemYl = isNaN(parseFloat(existingItem.yl)) ? 0 : parseFloat(existingItem.yl); + currentItemYlInBaseUnit = currentItemYl * volumeUnits[item.dw] || 0; + existingItemYlInBaseUnit = existingItemYl * volumeUnits[existingItem.dw] || 0; + } else if(item.type === 'gsp') { + // 质量单位转换 + const currentItemYl = isNaN(parseFloat(item.yl)) ? 0 : parseFloat(item.yl); + const existingItemYl = isNaN(parseFloat(existingItem.yl)) ? 0 : parseFloat(existingItem.yl); + currentItemYlInBaseUnit = currentItemYl * massUnits[item.dw] || 0; + existingItemYlInBaseUnit = existingItemYl * massUnits[existingItem.dw] || 0; + } else { + // 其他类型暂不处理单位转换,直接相加 + const currentItemYl = isNaN(parseFloat(item.yl)) ? 0 : parseFloat(item.yl); + const existingItemYl = isNaN(parseFloat(existingItem.yl)) ? 0 : parseFloat(existingItem.yl); + currentItemYlInBaseUnit = currentItemYl || 0; + existingItemYlInBaseUnit = existingItemYl || 0; + } + + // 计算总和 + const totalYlInBaseUnit = currentItemYlInBaseUnit + existingItemYlInBaseUnit; + + // 更新existingItem的yl值,保持使用第一个项目的单位作为基准单位 + if(item.type === 'sj') { + existingItem.yl = (totalYlInBaseUnit / volumeUnits[existingItem.dw]).toString(); + } else if(item.type === 'gsp') { + existingItem.yl = (totalYlInBaseUnit / massUnits[existingItem.dw]).toString(); + } else { + existingItem.yl = totalYlInBaseUnit.toString(); + } + } else { + // 如果不存在,添加新项 + sjMap.set(key, {...item}); + } + } + + // 将Map中的值转换回数组 + sj.length = 0; // 清空原数组 + for(const value of sjMap.values()) { + sj.push(value); + } + + // 对yq数组根据value去重 + yq = yq.filter((item, index, self) => + self.findIndex(obj => obj.value === item.value) === index + ); + + console.log(sj,yq,"stepsResource") + return { sjResource: sj, yqResource: yq }; }, // 直接获取表单数据,不做校验 diff --git a/src/components/Template/StepFormPackage.vue b/src/components/Template/StepFormPackage.vue index 015bae3..fca5752 100644 --- a/src/components/Template/StepFormPackage.vue +++ b/src/components/Template/StepFormPackage.vue @@ -121,19 +121,30 @@ export default { for(const key in allFieldsConfig){ const item = allFieldsConfig[key]; if(item.type === "xb" || item.type === "regent" || item.type === "gsp" || item.type === "mix"){ - sjResource.push({ - type:item.selectType, - value:formFields[key], - yl:formFields[item.ylCode],//用量 - dw:formFields[item.dwCode],//单位 - }); + if(formFields[key]){ + this.formFields[`selectType_${key}`] = item.sjSelectType; + let o = { + type:item.sjSelectType || formFields[`selectType_${key}`] , + value:formFields[key], + } + if(item.ylCode){ + o.yl = formFields[item.ylCode];//用量 + } + if(item.dwCode){ + o.dw = formFields[item.dwCode];//单位 + } + sjResource.push(o); + } }else if(item.type === "instrument"){ - yqResource.push({ - type:item.type, - value:formFields[key], - }); + if(formFields[key]){ + yqResource.push({ + type:item.type, + value:formFields[key], + }); + } } } + console.log(sjResource,"sjResource") return { sjResource, yqResource, diff --git a/src/views/business/comps/template/comps/sp/SWYPBQGZYZBB.vue b/src/views/business/comps/template/comps/sp/SWYPBQGZYZBB.vue index ce0d486..bd51624 100644 --- a/src/views/business/comps/template/comps/sp/SWYPBQGZYZBB.vue +++ b/src/views/business/comps/template/comps/sp/SWYPBQGZYZBB.vue @@ -498,6 +498,9 @@ export default { EventBus.$emit('onModifyRecord', params,) }) }, + getStepResource(){ + return this.$refs.stepRef.getStepResource() + }, //获取已填写的表单数据 getFilledFormData() { return this.getFilledFormDataByRefs(["baseInfoRef", "stepFormPackageRef", "stepRef", "remarkRef", "stepTableRef"]) diff --git a/src/views/business/comps/template/comps/sp/SWYPFXCBYPZB.vue b/src/views/business/comps/template/comps/sp/SWYPFXCBYPZB.vue index 42ea0b8..56476b9 100644 --- a/src/views/business/comps/template/comps/sp/SWYPFXCBYPZB.vue +++ b/src/views/business/comps/template/comps/sp/SWYPFXCBYPZB.vue @@ -269,6 +269,9 @@ export default { EventBus.$emit('showTagPrintDialog', { printConfig }) }, + getStepResource(){ + return this.$refs.stepRef.getStepResource() + }, //获取目标溶液编号 async getCode() { const result = await getLatestSn({ diff --git a/src/views/business/comps/template/comps/sp/SWYPFXFFXZKPZB.vue b/src/views/business/comps/template/comps/sp/SWYPFXFFXZKPZB.vue index 8d2924a..2503434 100644 --- a/src/views/business/comps/template/comps/sp/SWYPFXFFXZKPZB.vue +++ b/src/views/business/comps/template/comps/sp/SWYPFXFFXZKPZB.vue @@ -311,6 +311,9 @@ export default { } } }, + getStepResource(){ + return this.$refs.stepRef.getStepResource() + }, //获取已填写的表单数据 getFilledFormData(){ return this.getFilledFormDataByRefs(["baseInfoRef", "storageConditionRef", "stepFormPackageRef", "tableRef","stepRef", "remarkRef"]) diff --git a/src/views/business/comps/template/comps/sp/SWYPFXRYPZB.vue b/src/views/business/comps/template/comps/sp/SWYPFXRYPZB.vue index 5303246..cf41d2b 100644 --- a/src/views/business/comps/template/comps/sp/SWYPFXRYPZB.vue +++ b/src/views/business/comps/template/comps/sp/SWYPFXRYPZB.vue @@ -277,6 +277,9 @@ export default { this.$refs.stepFormPackageRef.updateFormData("targetCodeSn", result.data[0]) } }, + getStepResource(){ + return this.$refs.stepRef.getStepResource() + }, //获取已填写的表单数据 getFilledFormData() { return this.getFilledFormDataByRefs(["baseInfoRef", "storageConditionRef", "stepFormPackageRef", "stepRef", "remarkRef"]) @@ -310,7 +313,8 @@ export default { return content; }, onSave(){ - this.$refs.stepRef.getSjResource() + const result = this.getStepResource() + console.log(result) } } };