| | |
| | | </el-table-column> |
| | | <el-table-column label="审批中数量" width="120" align="center"> |
| | | <template #default="scope"> |
| | | <span>{{ scope.row.pendingApprovalQuantity || 0 }}</span> |
| | | <span>{{ formatDecimal6(scope.row.pendingApprovalQuantity) }}</span> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column |
| | |
| | | </div> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="数量" prop="quantity" /> |
| | | <el-table-column label="待发货数量" prop="noQuantity" /> |
| | | <el-table-column label="税率(%)" prop="taxRate" /> |
| | | <el-table-column |
| | | label="数量" |
| | | prop="quantity" |
| | | :formatter="formattedNumber" |
| | | /> |
| | | <el-table-column label="待发货数量" |
| | | prop="noQuantity" |
| | | :formatter="formattedNumber" /> |
| | | <el-table-column label="税率(%)" |
| | | prop="taxRate" |
| | | :formatter="formattedNumber" /> |
| | | <el-table-column |
| | | label="含税单价(元)" |
| | | prop="taxInclusiveUnitPrice" |
| | |
| | | <el-table-column |
| | | label="含税总价(元)" |
| | | prop="taxInclusiveTotalPrice" |
| | | :formatter="formattedAmount" |
| | | :formatter="formattedRawAmount" |
| | | /> |
| | | <el-table-column |
| | | label="不含税总价(元)" |
| | | prop="taxExclusiveTotalPrice" |
| | | :formatter="formattedAmount" |
| | | :formatter="formattedRawAmount" |
| | | /> |
| | | <!--操作--> |
| | | <el-table-column Width="60px" label="操作" align="center"> |
| | |
| | | prop="contractAmount" |
| | | width="220" |
| | | show-overflow-tooltip |
| | | :formatter="formattedAmount" |
| | | :formatter="formattedRawAmount" |
| | | /> |
| | | <el-table-column |
| | | label="录入人" |
| | |
| | | <el-table-column label="产品大类" prop="productCategory" /> |
| | | <el-table-column label="规格型号" prop="specificationModel" /> |
| | | <el-table-column label="单位" prop="unit" /> |
| | | <el-table-column label="数量" prop="quantity" /> |
| | | <el-table-column |
| | | label="数量" |
| | | prop="quantity" |
| | | :formatter="formattedNumber" |
| | | /> |
| | | <el-table-column label="税率(%)" prop="taxRate" /> |
| | | <el-table-column |
| | | label="含税单价(元)" |
| | |
| | | <el-table-column |
| | | label="含税总价(元)" |
| | | prop="taxInclusiveTotalPrice" |
| | | :formatter="formattedAmount" |
| | | :formatter="formattedRawAmount" |
| | | /> |
| | | <el-table-column |
| | | label="不含税总价(元)" |
| | | prop="taxExclusiveTotalPrice" |
| | | :formatter="formattedAmount" |
| | | :formatter="formattedRawAmount" |
| | | /> |
| | | <el-table-column label="是否生产" prop="isProduction" width="150"> |
| | | <template #default="scope"> |
| | |
| | | :min="0" |
| | | v-model="productForm.taxInclusiveUnitPrice" |
| | | style="width: 100%" |
| | | :precision="6" |
| | | placeholder="请输入" |
| | | clearable |
| | | @change="calculateFromUnitPrice" |
| | |
| | | v-model="productForm.quantity" |
| | | placeholder="请输入" |
| | | clearable |
| | | :precision="6" |
| | | @change="calculateFromQuantity" |
| | | style="width: 100%" |
| | | /> |
| | |
| | | <td>{{ product.productCategory || "" }}</td> |
| | | <td>{{ product.specificationModel || "" }}</td> |
| | | <td>{{ product.unit || "" }}</td> |
| | | <td>{{ trimZeros(product.taxInclusiveUnitPrice, 6) }}</td> |
| | | <td>{{ trimZeros(product.quantity, 6) }}</td> |
| | | <td>{{ formatDecimal6(product.taxInclusiveUnitPrice) }}</td> |
| | | <td>{{ formatDecimal6(product.quantity) }}</td> |
| | | <td> |
| | | {{ formatAmount(product.taxInclusiveTotalPrice) }} |
| | | {{ formatDecimal6(product.taxInclusiveTotalPrice) }} |
| | | </td> |
| | | </tr> |
| | | <tr v-if="!item.products || item.products.length === 0"> |
| | |
| | | <el-col :span="24"> |
| | | <el-form-item label="待发货数量:"> |
| | | <el-input |
| | | :model-value="currentDeliveryRow?.noQuantity" |
| | | :model-value="formatDecimal6(currentDeliveryRow?.noQuantity)" |
| | | disabled |
| | | /> |
| | | </el-form-item> |
| | |
| | | align="center" |
| | | > |
| | | <template #default="scope"> |
| | | {{ getDeliveryBatchQuantity(scope.row) }} |
| | | {{ formatDecimal6(getDeliveryBatchQuantity(scope.row)) }} |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column |
| | |
| | | import FileUpload from "@/components/AttachmentUpload/file/index.vue"; |
| | | import ImageUpload from "@/components/AttachmentUpload/image/index.vue"; |
| | | import { getCurrentDate } from "@/utils/index.js"; |
| | | import { roundHalfUp, trimZeros } from "@/utils/formatNumber.js"; |
| | | import { formatDecimal6, roundHalfUp } from "@/utils/formatNumber.js"; |
| | | import { listCustomer } from "@/api/basicData/customer.js"; |
| | | |
| | | const FileList = defineAsyncComponent(() => |
| | |
| | | }); |
| | | }; |
| | | const formattedNumber = (row, column, cellValue) => { |
| | | return trimZeros(cellValue, 6); |
| | | return formatDecimal6(cellValue); |
| | | }; |
| | | // 金额显示格式化:按十进制四舍五入到 2 位小数(与数据库 ROUND 一致),再去掉末尾多余的 0 |
| | | // 报价金额显示:按十进制四舍五入到 2 位小数(与数据库 ROUND 一致),再去掉末尾多余的 0 |
| | | const formatAmount = (value) => { |
| | | return trimZeros(roundHalfUp(value, 2), 2); |
| | | return formatDecimal6(roundHalfUp(value, 2)); |
| | | }; |
| | | // 金额列的表格格式化函数(单价列仍用 formattedNumber 保留 6 位小数) |
| | | const formattedAmount = (row, column, cellValue) => { |
| | | return formatAmount(cellValue); |
| | | // 金额列显示:最多保留 6 位小数,超过 6 位的按十进制四舍五入 |
| | | const formattedRawAmount = (row, column, cellValue) => { |
| | | return formatDecimal6(cellValue); |
| | | }; |
| | | // 把金额计算结果转成「输入几位就几位」的数字(最多 6 位小数,超出四舍五入) |
| | | const toDisplayNumber = (value) => { |
| | | const num = Number(formatDecimal6(value)); |
| | | return Number.isFinite(num) ? num : 0; |
| | | }; |
| | | // 产品弹窗单个数值字段归一化:输入超过 6 位小数时四舍五入到 6 位 |
| | | const normalizeProductNumber = (key) => { |
| | | const val = productForm.value[key]; |
| | | if (val === null || val === undefined || val === "") return; |
| | | productForm.value[key] = toDisplayNumber(val); |
| | | }; |
| | | // 产品弹窗参与联动计算的数值字段统一归一化 |
| | | const normalizeProductNumbers = () => { |
| | | [ |
| | | "quantity", |
| | | "taxInclusiveUnitPrice", |
| | | "taxInclusiveTotalPrice", |
| | | "taxExclusiveTotalPrice", |
| | | ].forEach(normalizeProductNumber); |
| | | }; |
| | | const findLedgerRecordByRow = (row) => { |
| | | if (!row) return null; |
| | |
| | | param, |
| | | ["contractAmount", "taxInclusiveTotalPrice", "taxExclusiveTotalPrice"], |
| | | { |
| | | // 金额列:每行先按 2 位小数四舍五入再求和,保证合计与列内展示值一致 |
| | | contractAmount: { roundEach: 2, decimalPlaces: 2, trimZeros: true }, |
| | | taxInclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true }, |
| | | taxExclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true }, |
| | | // 金额列合计后最多保留 6 位小数,超过 6 位按十进制四舍五入 |
| | | contractAmount: { formatter: formatDecimal6 }, |
| | | taxInclusiveTotalPrice: { formatter: formatDecimal6 }, |
| | | taxExclusiveTotalPrice: { formatter: formatDecimal6 }, |
| | | } |
| | | ); |
| | | }; |
| | |
| | | "taxExclusiveTotalPrice", |
| | | ], |
| | | { |
| | | taxInclusiveUnitPrice: { decimalPlaces: 6, trimZeros: true }, |
| | | // 金额列:每行先按 2 位小数四舍五入再求和,保证合计与列内展示值一致 |
| | | taxInclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true }, |
| | | taxExclusiveTotalPrice: { roundEach: 2, decimalPlaces: 2, trimZeros: true }, |
| | | taxInclusiveUnitPrice: { formatter: formatDecimal6 }, |
| | | // 金额列合计后最多保留 6 位小数,超过 6 位按十进制四舍五入 |
| | | taxInclusiveTotalPrice: { formatter: formatDecimal6 }, |
| | | taxExclusiveTotalPrice: { formatter: formatDecimal6 }, |
| | | } |
| | | ); |
| | | }; |
| | |
| | | const quantity = Number(p.quantity ?? 0) || 0; |
| | | const unitPrice = Number(p.unitPrice ?? 0) || 0; |
| | | const taxRate = "13"; // 默认 13%,便于直接提交(如需可在产品中自行修改) |
| | | const taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(6); |
| | | const taxExclusiveTotalPrice = proxy.calculateTaxExclusiveTotalPrice( |
| | | taxInclusiveTotalPrice, |
| | | taxRate, |
| | | 6 |
| | | const taxInclusiveTotalPrice = toDisplayNumber(unitPrice * quantity); |
| | | const taxExclusiveTotalPrice = toDisplayNumber( |
| | | proxy.calculateTaxExclusiveTotalPrice(taxInclusiveTotalPrice, taxRate, 6) |
| | | ); |
| | | return { |
| | | // 台账字段 |
| | |
| | | unit: p.unit || "", |
| | | quantity: quantity, |
| | | taxRate: taxRate, |
| | | taxInclusiveUnitPrice: unitPrice.toFixed(6), |
| | | taxInclusiveUnitPrice: toDisplayNumber(unitPrice), |
| | | taxInclusiveTotalPrice: taxInclusiveTotalPrice, |
| | | taxExclusiveTotalPrice: taxExclusiveTotalPrice, |
| | | invoiceType: "增普票", |
| | |
| | | proxy.resetForm("productFormRef"); |
| | | if (type === "edit") { |
| | | productForm.value = { ...row }; |
| | | // 回填时把金额/数量统一成数字,避免 "5000.000000" 这类补零字符串直接进输入框 |
| | | [ |
| | | "quantity", |
| | | "taxInclusiveUnitPrice", |
| | | "taxInclusiveTotalPrice", |
| | | "taxExclusiveTotalPrice", |
| | | ].forEach((key) => { |
| | | const val = productForm.value[key]; |
| | | if (val === null || val === undefined || val === "") return; |
| | | productForm.value[key] = toDisplayNumber(val); |
| | | }); |
| | | productIndex.value = index; |
| | | // 编辑时根据产品大类名称反查 tree 节点 id,并加载规格型号列表 |
| | | try { |
| | |
| | | const submitProduct = () => { |
| | | proxy.$refs["productFormRef"].validate((valid) => { |
| | | if (valid) { |
| | | // 提交前统一把数值收敛到最多 6 位小数(超出四舍五入) |
| | | normalizeProductNumbers(); |
| | | if (operationType.value === "edit") { |
| | | submitProductEdit(); |
| | | } else { |
| | |
| | | "" |
| | | }</td> |
| | | <td>${ |
| | | product.taxInclusiveUnitPrice || |
| | | "0" |
| | | formatDecimal6( |
| | | product.taxInclusiveUnitPrice |
| | | ) |
| | | }</td> |
| | | <td>${ |
| | | product.quantity || |
| | | "0" |
| | | formatDecimal6( |
| | | product.quantity |
| | | ) |
| | | }</td> |
| | | <td>${ |
| | | product.taxInclusiveTotalPrice || |
| | | "0" |
| | | formatDecimal6( |
| | | product.taxInclusiveTotalPrice |
| | | ) |
| | | }</td> |
| | | </tr> |
| | | ` |
| | |
| | | const total = products.reduce((sum, product) => { |
| | | return sum + (parseFloat(product.quantity) || 0); |
| | | }, 0); |
| | | return trimZeros(total, 6); |
| | | return formatDecimal6(total); |
| | | }; |
| | | |
| | | // 计算产品总金额 |
| | |
| | | const total = products.reduce((sum, product) => { |
| | | return sum + (parseFloat(product.taxInclusiveTotalPrice) || 0); |
| | | }, 0); |
| | | return formatAmount(total); |
| | | return formatDecimal6(total); |
| | | }; |
| | | |
| | | // 用于打印的计算函数 |
| | |
| | | const total = products.reduce((sum, product) => { |
| | | return sum + (parseFloat(product.quantity) || 0); |
| | | }, 0); |
| | | return trimZeros(total, 6); |
| | | return formatDecimal6(total); |
| | | }; |
| | | |
| | | const getTotalAmountForPrint = (products) => { |
| | |
| | | const total = products.reduce((sum, product) => { |
| | | return sum + (parseFloat(product.taxInclusiveTotalPrice) || 0); |
| | | }, 0); |
| | | return formatAmount(total); |
| | | return formatDecimal6(total); |
| | | }; |
| | | |
| | | const mathNum = () => { |
| | | console.log("productForm.value", productForm.value); |
| | | normalizeProductNumbers(); |
| | | if (!productForm.value.taxInclusiveUnitPrice) { |
| | | return; |
| | | } |
| | |
| | | return; |
| | | } |
| | | // 含税总价计算 |
| | | productForm.value.taxInclusiveTotalPrice = |
| | | productForm.value.taxInclusiveTotalPrice = toDisplayNumber( |
| | | proxy.calculateTaxIncludeTotalPrice( |
| | | productForm.value.taxInclusiveUnitPrice, |
| | | productForm.value.quantity, |
| | | 6 |
| | | ) |
| | | ); |
| | | if (productForm.value.taxRate) { |
| | | // 不含税总价计算 |
| | | productForm.value.taxExclusiveTotalPrice = |
| | | productForm.value.taxExclusiveTotalPrice = toDisplayNumber( |
| | | proxy.calculateTaxExclusiveTotalPrice( |
| | | productForm.value.taxInclusiveTotalPrice, |
| | | productForm.value.taxRate, |
| | | 6 |
| | | ) |
| | | ); |
| | | } |
| | | }; |
| | | |
| | | // 根据含税总价计算含税单价和数量 |
| | | const calculateFromTotalPrice = () => { |
| | | normalizeProductNumbers(); |
| | | if (isCalculating.value) return; |
| | | |
| | | const totalPrice = parseFloat(productForm.value.taxInclusiveTotalPrice); |
| | |
| | | isCalculating.value = true; |
| | | |
| | | // 计算含税单价 = 含税总价 / 数量 |
| | | productForm.value.taxInclusiveUnitPrice = (totalPrice / quantity).toFixed(6); |
| | | productForm.value.taxInclusiveUnitPrice = toDisplayNumber( |
| | | totalPrice / quantity |
| | | ); |
| | | |
| | | // 如果有税率,计算不含税总价 |
| | | if (productForm.value.taxRate) { |
| | | productForm.value.taxExclusiveTotalPrice = |
| | | productForm.value.taxExclusiveTotalPrice = toDisplayNumber( |
| | | proxy.calculateTaxExclusiveTotalPrice( |
| | | totalPrice, |
| | | productForm.value.taxRate, |
| | | 6 |
| | | ) |
| | | ); |
| | | } |
| | | |
| | |
| | | |
| | | // 根据不含税总价计算含税单价和数量 |
| | | const calculateFromExclusiveTotalPrice = () => { |
| | | normalizeProductNumbers(); |
| | | if (!productForm.value.taxRate) { |
| | | proxy.$modal.msgWarning("请先选择税率"); |
| | | return; |
| | |
| | | // 先计算含税总价 = 不含税总价 / (1 - 税率/100) |
| | | const taxRateDecimal = taxRate / 100; |
| | | const inclusiveTotalPrice = exclusiveTotalPrice / (1 - taxRateDecimal); |
| | | productForm.value.taxInclusiveTotalPrice = inclusiveTotalPrice.toFixed(6); |
| | | productForm.value.taxInclusiveTotalPrice = toDisplayNumber(inclusiveTotalPrice); |
| | | |
| | | // 计算含税单价 = 含税总价 / 数量 |
| | | productForm.value.taxInclusiveUnitPrice = ( |
| | | productForm.value.taxInclusiveUnitPrice = toDisplayNumber( |
| | | inclusiveTotalPrice / quantity |
| | | ).toFixed(6); |
| | | ); |
| | | |
| | | isCalculating.value = false; |
| | | }; |
| | | |
| | | // 根据数量变化计算总价 |
| | | const calculateFromQuantity = () => { |
| | | normalizeProductNumbers(); |
| | | if (!productForm.value.taxRate) { |
| | | proxy.$modal.msgWarning("请先选择税率"); |
| | | return; |
| | |
| | | isCalculating.value = true; |
| | | |
| | | // 计算含税总价 |
| | | productForm.value.taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(6); |
| | | productForm.value.taxInclusiveTotalPrice = toDisplayNumber( |
| | | unitPrice * quantity |
| | | ); |
| | | |
| | | // 如果有税率,计算不含税总价 |
| | | if (productForm.value.taxRate) { |
| | | productForm.value.taxExclusiveTotalPrice = |
| | | productForm.value.taxExclusiveTotalPrice = toDisplayNumber( |
| | | proxy.calculateTaxExclusiveTotalPrice( |
| | | productForm.value.taxInclusiveTotalPrice, |
| | | productForm.value.taxRate, |
| | | 6 |
| | | ) |
| | | ); |
| | | } |
| | | |
| | |
| | | |
| | | // 根据含税单价变化计算总价 |
| | | const calculateFromUnitPrice = () => { |
| | | normalizeProductNumbers(); |
| | | if (!productForm.value.taxRate) { |
| | | proxy.$modal.msgWarning("请先选择税率"); |
| | | return; |
| | |
| | | isCalculating.value = true; |
| | | |
| | | // 计算含税总价 |
| | | productForm.value.taxInclusiveTotalPrice = (unitPrice * quantity).toFixed(6); |
| | | productForm.value.taxInclusiveTotalPrice = toDisplayNumber( |
| | | unitPrice * quantity |
| | | ); |
| | | |
| | | // 如果有税率,计算不含税总价 |
| | | if (productForm.value.taxRate) { |
| | | productForm.value.taxExclusiveTotalPrice = |
| | | productForm.value.taxExclusiveTotalPrice = toDisplayNumber( |
| | | proxy.calculateTaxExclusiveTotalPrice( |
| | | productForm.value.taxInclusiveTotalPrice, |
| | | productForm.value.taxRate, |
| | | 6 |
| | | ) |
| | | ); |
| | | } |
| | | |
| | |
| | | |
| | | // 根据税率变化计算不含税总价 |
| | | const calculateFromTaxRate = () => { |
| | | normalizeProductNumbers(); |
| | | if (!productForm.value.taxRate) { |
| | | proxy.$modal.msgWarning("请先选择税率"); |
| | | return; |
| | |
| | | isCalculating.value = true; |
| | | |
| | | // 计算不含税总价 |
| | | productForm.value.taxExclusiveTotalPrice = |
| | | proxy.calculateTaxExclusiveTotalPrice(inclusiveTotalPrice, taxRate, 6); |
| | | productForm.value.taxExclusiveTotalPrice = toDisplayNumber( |
| | | proxy.calculateTaxExclusiveTotalPrice(inclusiveTotalPrice, taxRate, 6) |
| | | ); |
| | | |
| | | isCalculating.value = false; |
| | | }; |