| | |
| | | </div> |
| | | <PIMTable :isShowPagination="false" rowKey="id" :column="tableColumn" :tableData="tableData"> |
| | | <template #unQuantity="{ row }"> |
| | | {{ calcAlreadyReturned(row) }} |
| | | {{ row.unQuantity ?? 0 }} |
| | | </template> |
| | | <template #returnQuantity="{ row }"> |
| | | <el-input |
| | |
| | | const { form, rules } = toRefs(data); |
| | | |
| | | const calcAlreadyReturned = (row) => { |
| | | // 如果 row.unQuantity 已经有值(从后端获取的未退货数量),直接返回 |
| | | // 如果 row.unQuantity 已经有值(从后端获取的未退货数量),计算已退货数量 |
| | | if (row?.unQuantity !== undefined && row?.unQuantity !== null) { |
| | | return Number(row.unQuantity); |
| | | } |
| | | const total = Number(row?.shippingNum ?? row?.totalQuantity ?? 0); |
| | | const unQuantity = Number(row.unQuantity); |
| | | if (!Number.isFinite(total) || !Number.isFinite(unQuantity)) return 0; |
| | | return total - unQuantity; |
| | | }; |
| | | // 否则根据总数量和已退货数量计算 |
| | | const total = Number(row?.shippingNum ?? row?.totalQuantity ?? 0); |
| | | const returned = Number(row?.returnNum ?? 0); |
| | | if (!Number.isFinite(total) || !Number.isFinite(returned)) return 0; |
| | | return total - returned; |
| | | return returned; |
| | | }; |
| | | |
| | | const tableColumn = ref([ |
| | |
| | | const submitForm = () => { |
| | | proxy.$refs["formRef"].validate(valid => { |
| | | if (!valid) return; |
| | | |
| | | // 校验是否有产品数据 |
| | | if (!tableData.value || tableData.value.length === 0) { |
| | | proxy.$modal.msgWarning("请添加退货产品"); |
| | | return; |
| | | } |
| | | |
| | | // 校验未退货数量为0的产品 |
| | | const zeroUnQuantityProducts = tableData.value.filter(row => { |
| | | const unQuantity = Number(row.unQuantity ?? 0); |
| | | return unQuantity <= 0; |
| | | }); |
| | | if (zeroUnQuantityProducts.length > 0) { |
| | | const productNames = zeroUnQuantityProducts.map(p => p.productCategory || p.specificationModel || '未知产品').join('、'); |
| | | proxy.$modal.msgWarning(`以下产品未退货数量为0,无法退货:${productNames}`); |
| | | return; |
| | | } |
| | | |
| | | // 校验退货数量必须大于0 |
| | | const zeroReturnProducts = tableData.value.filter(row => { |
| | | const returnQty = Number(row.returnQuantity ?? 0); |
| | | return returnQty <= 0; |
| | | }); |
| | | if (zeroReturnProducts.length > 0) { |
| | | const productNames = zeroReturnProducts.map(p => p.productCategory || p.specificationModel || '未知产品').join('、'); |
| | | proxy.$modal.msgWarning(`以下产品退货数量必须大于0:${productNames}`); |
| | | return; |
| | | } |
| | | |
| | | const returnSaleProducts = (tableData.value || []).map(el => ({ |
| | | returnSaleLedgerProductId: el.returnSaleLedgerProductId ?? el.id, |
| | | productModelId: el.productModelId, |