| | |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="数量" |
| | | prop="quantity" /> |
| | | prop="quantity" |
| | | :formatter="formattedNumber" /> |
| | | <el-table-column label="可用数量" |
| | | prop="availableQuality" /> |
| | | prop="availableQuality" |
| | | :formatter="formattedNumber" /> |
| | | <el-table-column label="退货数量" |
| | | prop="returnQuantity" /> |
| | | prop="returnQuantity" |
| | | :formatter="formattedNumber" /> |
| | | <el-table-column label="税率(%)" |
| | | prop="taxRate" /> |
| | | prop="taxRate" |
| | | :formatter="formattedNumber" /> |
| | | <el-table-column label="含税单价(元)" |
| | | prop="taxInclusiveUnitPrice" |
| | | :formatter="formattedNumber" /> |
| | |
| | | width="70" /> |
| | | <el-table-column label="数量" |
| | | prop="quantity" |
| | | width="70" /> |
| | | width="70" |
| | | :formatter="formattedNumber" /> |
| | | <el-table-column label="库存预警数量" |
| | | prop="warnNum" |
| | | width="120" |
| | | show-overflow-tooltip /> |
| | | show-overflow-tooltip |
| | | :formatter="formattedNumber" /> |
| | | <el-table-column label="税率(%)" |
| | | prop="taxRate" |
| | | width="80" /> |
| | |
| | | <el-form-item label="含税单价(元):" |
| | | prop="taxInclusiveUnitPrice"> |
| | | <el-input-number v-model="productForm.taxInclusiveUnitPrice" |
| | | :precision="6" |
| | | :step="0.1" |
| | | :min="0" |
| | | clearable |
| | |
| | | prop="quantity"> |
| | | <el-input-number :step="0.1" |
| | | clearable |
| | | :precision="6" |
| | | :min="0" |
| | | style="width: 100%" |
| | | v-model="productForm.quantity" |
| | |
| | | <el-form-item label="含税总价(元):" |
| | | prop="taxInclusiveTotalPrice"> |
| | | <el-input-number v-model="productForm.taxInclusiveTotalPrice" |
| | | :precision="6" |
| | | :step="0.1" |
| | | :min="0" |
| | | clearable |
| | |
| | | <el-form-item label="不含税总价(元):" |
| | | prop="taxExclusiveTotalPrice"> |
| | | <el-input-number v-model="productForm.taxExclusiveTotalPrice" |
| | | :precision="6" |
| | | :step="0.1" |
| | | :min="0" |
| | | clearable |
| | |
| | | <el-form-item label="库存预警数量:" |
| | | prop="warnNum"> |
| | | <el-input-number v-model="productForm.warnNum" |
| | | :precision="6" |
| | | :step="0.1" |
| | | :min="0" |
| | | clearable |
| | | style="width: 100%" /> |
| | | style="width: 100%" |
| | | @change="normalizeProductNumber('warnNum')" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | |
| | | import { modelList, productTreeList } from "@/api/basicData/product.js"; |
| | | import dayjs from "dayjs"; |
| | | import FileUpload from "@/components/AttachmentUpload/file/index.vue"; |
| | | import { roundHalfUp, trimZeros } from "@/utils/formatNumber.js"; |
| | | import { formatDecimal6 } from "@/utils/formatNumber.js"; |
| | | |
| | | const userStore = useUserStore(); |
| | | |
| | |
| | | }; |
| | | |
| | | const formattedNumber = (row, column, cellValue) => { |
| | | return trimZeros(cellValue, 6); |
| | | return formatDecimal6(cellValue); |
| | | }; |
| | | // 金额显示格式化:按十进制四舍五入到 2 位小数(与数据库 ROUND 一致),再去掉末尾多余的 0 |
| | | const formatAmount = value => { |
| | | return trimZeros(roundHalfUp(value, 2), 2); |
| | | }; |
| | | // 金额列的表格格式化函数(单价列仍用 formattedNumber 保留 6 位小数) |
| | | // 金额显示格式化:最多保留 6 位小数,超过 6 位的按十进制四舍五入 |
| | | const formattedAmount = (row, column, cellValue) => { |
| | | return formatAmount(cellValue); |
| | | return formatDecimal6(cellValue); |
| | | }; |
| | | // 查询列表 |
| | | /** 搜索按钮操作 */ |
| | |
| | | "futureTicketsAmount", |
| | | ], |
| | | { |
| | | 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 }, |
| | | ticketsAmount: { roundEach: 2, decimalPlaces: 2, trimZeros: true }, |
| | | futureTicketsAmount: { roundEach: 2, decimalPlaces: 2, trimZeros: true }, |
| | | ticketsNum: { noDecimal: true }, // 不保留小数 |
| | |
| | | param, |
| | | ["contractAmount", "netContractAmount"], |
| | | { |
| | | // 金额列:每行先按 2 位小数四舍五入再求和,保证合计与列内展示值一致 |
| | | contractAmount: { roundEach: 2, decimalPlaces: 2, trimZeros: true }, |
| | | netContractAmount: { roundEach: 2, decimalPlaces: 2, trimZeros: true }, |
| | | // 金额列:合计后最多保留 6 位小数,超过 6 位按十进制四舍五入 |
| | | contractAmount: { formatter: formatDecimal6 }, |
| | | netContractAmount: { 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 }, |
| | | } |
| | | ); |
| | | }; |
| | |
| | | // 复制行数据 |
| | | productForm.value = { ...row }; |
| | | |
| | | // 后端数量/金额字段按 6 位小数返回(如 10.000000),转成普通数值, |
| | | // 避免输入框回显多余的 0 |
| | | [ |
| | | "quantity", |
| | | "taxInclusiveUnitPrice", |
| | | "taxInclusiveTotalPrice", |
| | | "taxExclusiveTotalPrice", |
| | | "warnNum", |
| | | ].forEach(key => { |
| | | const val = productForm.value[key]; |
| | | if (val === null || val === undefined || val === "") return; |
| | | productForm.value[key] = toDisplayNumber(val); |
| | | }); |
| | | |
| | | // 如果是从模板加载的数据,可能没有 productId 和 productModelId |
| | | // 需要根据 productCategory 和 specificationModel 来查找对应的 ID |
| | | if (!productForm.value.productId && productForm.value.productCategory) { |
| | |
| | | const submitProduct = () => { |
| | | proxy.$refs["productFormRef"].validate(valid => { |
| | | if (valid) { |
| | | // 提交前统一把数值收敛到最多 6 位小数(超出四舍五入) |
| | | normalizeProductNumbers(); |
| | | if (operationType.value === "edit") { |
| | | submitProductEdit(); |
| | | } else { |
| | |
| | | return `${year}-${month}-${day}`; |
| | | } |
| | | |
| | | // 计算结果转成数字:最多保留 6 位小数(超过 6 位的四舍五入),并去掉末尾无意义的 0, |
| | | // 避免回填到 el-input-number 时出现 100.000000 这类展示 |
| | | 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", |
| | | "warnNum", |
| | | ].forEach(normalizeProductNumber); |
| | | }; |
| | | |
| | | const mathNum = () => { |
| | | normalizeProductNumbers(); |
| | | if (!productForm.value.taxRate) { |
| | | proxy.$modal.msgWarning("请先选择税率"); |
| | | 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 reverseMathNum = field => { |
| | | normalizeProductNumbers(); |
| | | if (!productForm.value.taxRate) { |
| | | proxy.$modal.msgWarning("请先选择税率"); |
| | | return; |
| | |
| | | ) { |
| | | const value = Number(productForm.value[field]); |
| | | if (value < 0) { |
| | | productForm.value[field] = "0"; |
| | | productForm.value[field] = 0; |
| | | proxy.$modal.msgWarning("值不能小于0"); |
| | | return; |
| | | } |
| | |
| | | if (field === "taxInclusiveTotalPrice") { |
| | | // 已知含税总价和数量,反算含税单价 |
| | | if (productForm.value.quantity) { |
| | | productForm.value.taxInclusiveUnitPrice = ( |
| | | productForm.value.taxInclusiveUnitPrice = toDisplayNumber( |
| | | Number(productForm.value.taxInclusiveTotalPrice) / |
| | | Number(productForm.value.quantity) |
| | | ).toFixed(6); |
| | | ); |
| | | // 确保结果不为负数 |
| | | if (Number(productForm.value.taxInclusiveUnitPrice) < 0) { |
| | | productForm.value.taxInclusiveUnitPrice = "0"; |
| | | productForm.value.taxInclusiveUnitPrice = 0; |
| | | } |
| | | } |
| | | // 已知含税总价和含税单价,反算数量 |
| | | else if (productForm.value.taxInclusiveUnitPrice) { |
| | | productForm.value.quantity = ( |
| | | productForm.value.quantity = toDisplayNumber( |
| | | Number(productForm.value.taxInclusiveTotalPrice) / |
| | | Number(productForm.value.taxInclusiveUnitPrice) |
| | | ).toFixed(6); |
| | | ); |
| | | // 确保结果不为负数 |
| | | if (Number(productForm.value.quantity) < 0) { |
| | | productForm.value.quantity = "0"; |
| | | productForm.value.quantity = 0; |
| | | } |
| | | } |
| | | // 反算不含税总价 |
| | | productForm.value.taxExclusiveTotalPrice = ( |
| | | Number(productForm.value.taxInclusiveTotalPrice) / |
| | | (1 + taxRate / 100) |
| | | ).toFixed(6); |
| | | productForm.value.taxExclusiveTotalPrice = toDisplayNumber( |
| | | Number(productForm.value.taxInclusiveTotalPrice) / (1 + taxRate / 100) |
| | | ); |
| | | // 确保结果不为负数 |
| | | if (Number(productForm.value.taxExclusiveTotalPrice) < 0) { |
| | | productForm.value.taxExclusiveTotalPrice = "0"; |
| | | productForm.value.taxExclusiveTotalPrice = 0; |
| | | } |
| | | } else if (field === "taxExclusiveTotalPrice") { |
| | | // 反算含税总价 |
| | | productForm.value.taxInclusiveTotalPrice = ( |
| | | Number(productForm.value.taxExclusiveTotalPrice) * |
| | | (1 + taxRate / 100) |
| | | ).toFixed(6); |
| | | productForm.value.taxInclusiveTotalPrice = toDisplayNumber( |
| | | Number(productForm.value.taxExclusiveTotalPrice) * (1 + taxRate / 100) |
| | | ); |
| | | // 确保结果不为负数 |
| | | if (Number(productForm.value.taxInclusiveTotalPrice) < 0) { |
| | | productForm.value.taxInclusiveTotalPrice = "0"; |
| | | productForm.value.taxInclusiveTotalPrice = 0; |
| | | } |
| | | // 已知数量,反算含税单价 |
| | | if (productForm.value.quantity) { |
| | | productForm.value.taxInclusiveUnitPrice = ( |
| | | productForm.value.taxInclusiveUnitPrice = toDisplayNumber( |
| | | Number(productForm.value.taxInclusiveTotalPrice) / |
| | | Number(productForm.value.quantity) |
| | | ).toFixed(6); |
| | | ); |
| | | // 确保结果不为负数 |
| | | if (Number(productForm.value.taxInclusiveUnitPrice) < 0) { |
| | | productForm.value.taxInclusiveUnitPrice = "0"; |
| | | productForm.value.taxInclusiveUnitPrice = 0; |
| | | } |
| | | } |
| | | // 已知含税单价,反算数量 |
| | | else if (productForm.value.taxInclusiveUnitPrice) { |
| | | productForm.value.quantity = ( |
| | | productForm.value.quantity = toDisplayNumber( |
| | | Number(productForm.value.taxInclusiveTotalPrice) / |
| | | Number(productForm.value.taxInclusiveUnitPrice) |
| | | ).toFixed(6); |
| | | ); |
| | | // 确保结果不为负数 |
| | | if (Number(productForm.value.quantity) < 0) { |
| | | productForm.value.quantity = "0"; |
| | | productForm.value.quantity = 0; |
| | | } |
| | | } |
| | | } |