| | |
| | | |
| | | const tableData = ref<ErpPurchaseRequestApi.PurchaseRequestItem[]>([]); |
| | | |
| | | /** 获取表格合计数据 */ |
| | | /** 获取表格合计数据(行上 totalPrice 为不含税金额,含税合计需加上税额) */ |
| | | const summaries = computed(() => { |
| | | return { |
| | | count: tableData.value.reduce((sum, item) => sum + (item.count || 0), 0), |
| | | totalPrice: tableData.value.reduce( |
| | | (sum, item) => { |
| | | const price = erpPriceMultiply(item.productPrice || 0, item.count || 0) ?? 0; |
| | | return sum + price; |
| | | }, |
| | | (sum, item) => sum + (item.totalPrice || 0), |
| | | 0, |
| | | ), |
| | | taxPrice: tableData.value.reduce((sum, item) => sum + (item.taxPrice || 0), 0), |
| | | }; |
| | | }); |
| | | |
| | | /** 含税合计 = 不含税金额 + 税额 */ |
| | | const totalTaxInclusivePrice = computed( |
| | | () => summaries.value.totalPrice + summaries.value.taxPrice, |
| | | ); |
| | | |
| | | /** 表格配置 */ |
| | | const [Grid, gridApi] = useVbenVxeGrid({ |
| | |
| | | handleRowChange(row); |
| | | } |
| | | |
| | | /** |
| | | * 重算行金额(单价为**含税**单价) |
| | | * 含税金额 = 含税单价 × 数量;税额 = 含税金额 × 税率;不含税金额 = 含税金额 - 税额 |
| | | */ |
| | | function recalcRow(row: ErpPurchaseRequestApi.PurchaseRequestItem) { |
| | | if (row.productPrice && row.count) { |
| | | const taxInclusivePrice = erpPriceMultiply(row.productPrice, row.count) ?? 0; |
| | | row.taxPrice = |
| | | erpPriceMultiply(taxInclusivePrice, (row.taxPercent || 0) / 100) ?? 0; |
| | | row.totalPrice = taxInclusivePrice - row.taxPrice; |
| | | } |
| | | } |
| | | |
| | | /** 处理行数据变更 */ |
| | | function handleRowChange(row: any) { |
| | | recalcRow(row); |
| | | const index = tableData.value.findIndex((item) => item.seq === row.seq); |
| | | if (index === -1) { |
| | | tableData.value.push(row); |
| | | } else { |
| | | tableData.value[index] = row; |
| | | } |
| | | // 计算预估金额 |
| | | if (row.productPrice && row.count) { |
| | | row.totalPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0; |
| | | } |
| | | emit('update:items', [...tableData.value]); |
| | | } |
| | | |
| | | /** 初始化行数据 */ |
| | | /** |
| | | * 初始化行数据 |
| | | * 已有单据的明细行(带 id)沿用后端返回的金额,避免历史单据被新口径覆盖; |
| | | * 只有未保存的新增行才按新口径重算。 |
| | | */ |
| | | function initRow(row: ErpPurchaseRequestApi.PurchaseRequestItem) { |
| | | if (row.productPrice && row.count) { |
| | | row.totalPrice = erpPriceMultiply(row.productPrice, row.count) ?? 0; |
| | | if (!row.id) { |
| | | recalcRow(row); |
| | | } |
| | | } |
| | | |
| | |
| | | /> |
| | | <span v-else>{{ row.taxPercent ? `${row.taxPercent}%` : '-' }}</span> |
| | | </template> |
| | | <template #totalTaxInclusivePrice="{ row }"> |
| | | <span>{{ erpPriceInputFormatter((row.totalPrice || 0) + (row.taxPrice || 0)) }}</span> |
| | | </template> |
| | | <template #demandTime="{ row }"> |
| | | <DatePicker |
| | | v-if="!disabled" |
| | |
| | | <span class="font-medium text-foreground">合计:</span> |
| | | <div class="flex space-x-4"> |
| | | <span>数量:{{ erpCountInputFormatter(summaries.count) }}</span> |
| | | <span>预估金额:{{ erpPriceInputFormatter(summaries.totalPrice) }}</span> |
| | | <span>不含税金额:{{ erpPriceInputFormatter(summaries.totalPrice) }}</span> |
| | | <span>税额:{{ erpPriceInputFormatter(summaries.taxPrice) }}</span> |
| | | <span>含税合计:{{ erpPriceInputFormatter(totalTaxInclusivePrice) }}</span> |
| | | </div> |
| | | </div> |
| | | </div> |