diff --git a/src/components/charge/AssociationIdCode.vue b/src/components/charge/AssociationIdCode.vue index 0d5ef18..d9cc40d 100644 --- a/src/components/charge/AssociationIdCode.vue +++ b/src/components/charge/AssociationIdCode.vue @@ -82,7 +82,6 @@ const tableData = ref([]); const init = (newIdCode: any, newTableDate: any) => { traceabilityCode.value = newIdCode; tableData.value = newTableDate; - console.log(tableData) show.value = true; } const selected = ref() @@ -105,78 +104,13 @@ const addIdCode = ()=>{ if(!selectedItem){ return } - addTraceabilityCode(selectedItem) + addTraceabilityCodeDo(selectedItem) } -const getGatherNumber=(item:any)=>{ - let gatherNumber = 0; - for (let subItem of item.traceAbilityCodeList){ - gatherNumber+=subItem.number; - } - item.gatherNumber = gatherNumber; -} -const emit = defineEmits(["addIdCode"]) -const addTraceabilityCode = (item: any) => { - if (!item.traceAbilityCodeList) { - item.traceAbilityCodeList = [] - } - if (item.retailNumber == item.gatherNumber) { - ElMessage({ - message: '采集数量已满', - type: 'warning', - }) - return - } - const index = item.traceAbilityCodeList.findIndex((codeObj: any) => codeObj.code === traceabilityCode.value); - if (index == -1 && item.selectedUnit == item.packagingUnit){ - item.traceAbilityCodeList.push({ - code: traceabilityCode.value, - number: 1 - }) - traceabilityCode.value = ""; - getGatherNumber(item) - emit("addIdCode") - return; - } - if (index == -1&& item.selectedUnit == item.minPackagingUnit){ - let needCodeCount = item.retailNumber - item.gatherNumber; - let number = 1; - if (needCodeCount >= item.minPackagingNumber){ - number = item.minPackagingNumber; - } - if (needCodeCount < item.minPackagingNumber){ - number = needCodeCount; - } - item.traceAbilityCodeList.push({ - code: traceabilityCode.value, - number: number - }) - traceabilityCode.value = ""; - getGatherNumber(item) - emit("addIdCode") - return; - } - if(item.selectedUnit == item.packagingUnit){ - //没拆零 追溯码只能用一次 - ElMessage({ - message: '该追溯码已达到最大使用限制', - type: 'warning', - }) - return; - }else { - //拆零每一个追溯码最多使用minPackagingNumber次 - if (item.traceAbilityCodeList[index].number == item.minPackagingNumber) { - ElMessage({ - message: '该追溯码已达到最大使用限制', - type: 'warning', - }) - return; - } - item.traceAbilityCodeList[index].number += 1; - } - traceabilityCode.value = ""; - getGatherNumber(item) - emit("addIdCode") + +const emit = defineEmits(["addIdCode","addTraceabilityCode"]) +const addTraceabilityCodeDo = (item: any) => { + emit("addTraceabilityCode",item,traceabilityCode.value) }