|
|
|
@ -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 }; |
|
|
|
}, |
|
|
|
|
|
|
|
// 直接获取表单数据,不做校验 |
|
|
|
|