新疆海川开心
1.采购模块的计算都改为保留三位小数并且不四舍五入
| | |
| | | return `${year}-${month}-${day}`;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 截断(舍去)指定位数后不四舍五入
|
| | | * @param {number} num - 要处理的数字
|
| | | * @param {number} decimals - 要保留的小数位数,默认为0
|
| | | * @returns {number} 截断后的数字
|
| | | * @example
|
| | | * truncate(3.14159, 2) // 返回 3.14
|
| | | * truncate(3.999, 2) // 返回 3.99
|
| | | * truncate(-3.14159, 2) // 返回 -3.14
|
| | | * truncate(123.456, 0) // 返回 123
|
| | | */
|
| | | export function truncate(num, decimals = 0) {
|
| | | // 参数验证
|
| | | if (typeof num !== 'number' || isNaN(num)) {
|
| | | console.warn('truncate: 第一个参数必须是有效数字');
|
| | | return num;
|
| | | }
|
| | | if (typeof decimals !== 'number' || decimals < 0 || !Number.isInteger(decimals)) {
|
| | | console.warn('truncate: 第二个参数必须是非负整数');
|
| | | return num;
|
| | | }
|
| | |
|
| | | // 如果保留0位小数,直接使用 Math.trunc
|
| | | if (decimals === 0) {
|
| | | return Math.trunc(num);
|
| | | }
|
| | |
|
| | | // 计算倍数(10的decimals次方)
|
| | | const multiplier = Math.pow(10, decimals);
|
| | | |
| | | // 对于负数,使用 Math.ceil 来确保正确截断
|
| | | // 对于正数,使用 Math.floor 来截断
|
| | | if (num < 0) {
|
| | | return Math.ceil(num * multiplier) / multiplier;
|
| | | } else {
|
| | | return Math.floor(num * multiplier) / multiplier;
|
| | | }
|
| | | }
|
| | |
| | | } else { |
| | | // 默认保留两位小数 |
| | | sums[index] = parseFloat(sum).toFixed( |
| | | specialFormat[prop]?.decimalPlaces ?? 2 |
| | | specialFormat[prop]?.decimalPlaces ?? 3 |
| | | ); |
| | | } |
| | | } else { |
| | |
| | | // 不含税总价计算 |
| | | const calculateTaxExclusiveTotalPrice = (taxInclusiveTotalPrice, taxRate) => { |
| | | const taxRateDecimal = taxRate / 100; |
| | | return (taxInclusiveTotalPrice / (1 + taxRateDecimal)).toFixed(2); |
| | | return (taxInclusiveTotalPrice / (1 + taxRateDecimal)).toFixed(3); |
| | | }; |
| | | // 含税总价计算 |
| | | const calculateTaxIncludeTotalPrice = (taxInclusiveUnitPrice, quantity) => { |
| | | return (taxInclusiveUnitPrice * quantity).toFixed(2); |
| | | return (taxInclusiveUnitPrice * quantity).toFixed(3); |
| | | }; |
| | | // 导出函数供其他文件使用 |
| | | export { |
| | |
| | | <script setup> |
| | | import { usePaginationApi } from "@/hooks/usePaginationApi"; |
| | | import { productList } from "@/api/procurementManagement/procurementLedger.js"; |
| | | import { nextTick } from "vue"; |
| | | import { nextTick, getCurrentInstance } from "vue"; |
| | | import { truncate } from "@/utils/index.js"; |
| | | const { proxy } = getCurrentInstance(); |
| | | |
| | | defineOptions({ |
| | |
| | | prop: "taxInclusiveUnitPrice", |
| | | width:200, |
| | | formatData: (val) => { |
| | | return val ? parseFloat(val).toFixed(2) : "-"; |
| | | return val ? truncate(parseFloat(val), 3) : "-"; |
| | | }, |
| | | }, |
| | | { |
| | |
| | | prop: "taxInclusiveTotalPrice", |
| | | width:200, |
| | | formatData: (val) => { |
| | | return val ? parseFloat(val).toFixed(2) : "-"; |
| | | return val ? truncate(parseFloat(val), 3) : "-"; |
| | | }, |
| | | }, |
| | | { |
| | |
| | | prop: "taxExclusiveTotalPrice", |
| | | width:200, |
| | | formatData: (val) => { |
| | | return val ? parseFloat(val).toFixed(2) : "-"; |
| | | return val ? truncate(parseFloat(val), 3) : "-"; |
| | | }, |
| | | }, |
| | | { |
| | |
| | | prop: "ticketsAmount", |
| | | width:200, |
| | | formatData: (val) => { |
| | | return val ? parseFloat(val).toFixed(2) : "-"; |
| | | return val ? truncate(parseFloat(val), 3) : "-"; |
| | | }, |
| | | }, |
| | | { |
| | |
| | | prop: "futureTicketsAmount", |
| | | width:200, |
| | | formatData: (val) => { |
| | | return val ? parseFloat(val).toFixed(2) : "-"; |
| | | return val ? truncate(parseFloat(val), 3) : "-"; |
| | | }, |
| | | }, |
| | | ], |
| | |
| | | <el-table-column label="本次开票数" prop="ticketsNum" width="180"> |
| | | <template #default="scope"> |
| | | <el-input-number :step="0.1" :min="0" style="width: 100%" |
| | | :precision="2" |
| | | :precision="3" |
| | | v-model="scope.row.ticketsNum" |
| | | @change="invoiceNumBlur(scope.row)" |
| | | /> |
| | |
| | | > |
| | | <template #default="scope"> |
| | | <el-input-number :step="0.01" :min="0" style="width: 100%" |
| | | :precision="2" |
| | | :precision="3" |
| | | v-model="scope.row.ticketsAmount" |
| | | @change="invoiceAmountBlur(scope.row)" |
| | | /> |
| | |
| | | import { getToken } from "@/utils/auth"; |
| | | import useUserStore from "@/store/modules/user"; |
| | | import dayjs from "dayjs"; |
| | | import { truncate } from "@/utils/index.js"; |
| | | |
| | | defineOptions({ |
| | | name: "来票登记模态框", |
| | |
| | | prop: "taxInclusiveUnitPrice", |
| | | width: 150, |
| | | formatData: (val) => { |
| | | return val ? parseFloat(val).toFixed(2) : 0; |
| | | return val ? truncate(parseFloat(val), 3) : 0; |
| | | }, |
| | | }, |
| | | { |
| | |
| | | prop: "taxInclusiveTotalPrice", |
| | | width: 150, |
| | | formatData: (val) => { |
| | | return parseFloat(val).toFixed(2) ?? 0; |
| | | return val ? truncate(parseFloat(val), 3) : 0; |
| | | }, |
| | | }, |
| | | { |
| | |
| | | prop: "taxExclusiveTotalPrice", |
| | | width: 150, |
| | | formatData: (val) => { |
| | | return parseFloat(val).toFixed(2) ?? 0; |
| | | return val ? truncate(parseFloat(val), 3) : 0; |
| | | }, |
| | | }, |
| | | { |
| | |
| | | ]; |
| | | const formattedNumber = (row, column, cellValue) => { |
| | | if (cellValue == 0) { |
| | | return parseFloat(cellValue).toFixed(2); |
| | | return truncate(parseFloat(cellValue), 3); |
| | | } |
| | | if (cellValue) { |
| | | return parseFloat(cellValue).toFixed(2); |
| | | return truncate(parseFloat(cellValue), 3); |
| | | } else { |
| | | return cellValue; |
| | | } |
| | |
| | | const totalAmount = allProductData.reduce((sum, item) => { |
| | | return sum + (Number(item.taxInclusiveTotalPrice) || 0); |
| | | }, 0); |
| | | form.invoiceAmount = totalAmount.toFixed(2); |
| | | form.invoiceAmount = truncate(totalAmount, 3); |
| | | |
| | | // 存储选中的合同数据 |
| | | selectedContracts.value = selectedRows; |
| | |
| | | return; |
| | | } |
| | | // 计算本次来票金额 |
| | | row.ticketsAmount = (row.ticketsNum * row.taxInclusiveUnitPrice).toFixed(2) |
| | | row.ticketsAmount = truncate(row.ticketsNum * row.taxInclusiveUnitPrice, 3) |
| | | // 计算未来票数 |
| | | row.futureTickets = (row.tempFutureTickets - row.ticketsNum).toFixed(2) |
| | | row.futureTickets = truncate(row.tempFutureTickets - row.ticketsNum, 3) |
| | | // 计算未来票金额 |
| | | row.futureTicketsAmount = (row.tempFutureTicketsAmount - row.ticketsAmount).toFixed(2) |
| | | row.futureTicketsAmount = truncate(row.tempFutureTicketsAmount - row.ticketsAmount, 3) |
| | | calculateinvoiceAmount(); |
| | | }; |
| | | |
| | |
| | | } |
| | | // 计算本次来票数 |
| | | row.ticketsNum = Number( |
| | | (row.ticketsAmount / row.taxInclusiveUnitPrice).toFixed(2) |
| | | truncate(row.ticketsAmount / row.taxInclusiveUnitPrice, 3) |
| | | ); |
| | | // 计算未来票数 |
| | | row.futureTickets = (row.tempFutureTickets - row.ticketsNum).toFixed(2) |
| | | row.futureTickets = truncate(row.tempFutureTickets - row.ticketsNum, 3) |
| | | // 计算未来票金额 |
| | | row.futureTicketsAmount = (row.tempFutureTicketsAmount - row.ticketsAmount).toFixed(2) |
| | | row.futureTicketsAmount = truncate(row.tempFutureTicketsAmount - row.ticketsAmount, 3) |
| | | calculateinvoiceAmount(); |
| | | }; |
| | | |
| | |
| | | invoiceAmountTotal += Number(item.ticketsAmount); |
| | | } |
| | | }); |
| | | form.invoiceAmount = invoiceAmountTotal.toFixed(2); |
| | | form.invoiceAmount = truncate(invoiceAmountTotal, 3); |
| | | }; |
| | | |
| | | const open = async (type, selectedRows) => { |
| | |
| | | import ExpandTable from "./components/ExpandTable.vue"; |
| | | import Modal from "./components/Modal.vue"; |
| | | import {ElMessageBox} from "element-plus"; |
| | | import { truncate } from "@/utils/index.js"; |
| | | |
| | | defineOptions({ |
| | | name: "来票登记", |
| | |
| | | prop: "contractAmount", |
| | | width:200, |
| | | formatData: (val) => { |
| | | return val ? parseFloat(val).toFixed(2) : 0; |
| | | return val ? truncate(parseFloat(val), 3) : 0; |
| | | }, |
| | | }, |
| | | { |
| | |
| | | prop: "receiptPaymentAmount", |
| | | width:200, |
| | | formatData: (val) => { |
| | | return val ? parseFloat(val).toFixed(2) : 0; |
| | | return val ? truncate(parseFloat(val), 3) : 0; |
| | | }, |
| | | }, |
| | | { |
| | |
| | | prop: "unReceiptPaymentAmount", |
| | | width:200, |
| | | formatData: (val) => { |
| | | return val ? parseFloat(val).toFixed(2) : 0; |
| | | return val ? truncate(parseFloat(val), 3) : 0; |
| | | }, |
| | | }, |
| | | // { |
| | |
| | | <el-input-number :step="0.01" :min="0" style="width: 100%" |
| | | v-model="scope.row.currentPaymentAmount" |
| | | :disabled="!scope.row.editType" |
| | | :precision="2" |
| | | :precision="3" |
| | | placeholder="请输入" |
| | | clearable |
| | | /> |
| | |
| | | <el-col :span="12"> |
| | | <el-form-item label="本次付款金额:" prop="currentPaymentAmount"> |
| | | <el-input-number :step="0.01" :min="0" style="width: 100%" |
| | | :precision="2" |
| | | :precision="3" |
| | | v-model="form.currentPaymentAmount" |
| | | placeholder="请输入" |
| | | clearable |
| | |
| | | updatePaymentRegistration |
| | | } from "@/api/procurementManagement/procurementInvoiceLedger.js"; |
| | | import useFormData from "@/hooks/useFormData"; |
| | | import { getCurrentDate } from "@/utils/index.js"; |
| | | import { getCurrentDate, truncate } from "@/utils/index.js"; |
| | | |
| | | const { proxy } = getCurrentInstance(); |
| | | const tableColumn = ref([ |
| | |
| | | label: "发票金额(元)", |
| | | prop: "invoiceAmount", |
| | | formatData: (params) => { |
| | | return params ? parseFloat(params).toFixed(2) : 0; |
| | | return params ? truncate(parseFloat(params), 3) : 0; |
| | | }, |
| | | }, |
| | | { |
| | | label: "已付款金额(元)", |
| | | prop: "paymentAmountTotal", |
| | | formatData: (params) => { |
| | | return params ? parseFloat(params).toFixed(2) : 0; |
| | | return params ? truncate(parseFloat(params), 3) : 0; |
| | | }, |
| | | }, |
| | | { |
| | | label: "待付款金额(元)", |
| | | prop: "unPaymentAmountTotal", |
| | | formatData: (params) => { |
| | | return params ? parseFloat(params).toFixed(2) : 0; |
| | | return params ? truncate(parseFloat(params), 3) : 0; |
| | | }, |
| | | }, |
| | | { |
| | |
| | | import { paymentHistoryListPage } from "@/api/procurementManagement/paymentEntry.js"; |
| | | import useFormData from "@/hooks/useFormData"; |
| | | import dayjs from "dayjs"; |
| | | import { truncate } from "@/utils/index.js"; |
| | | |
| | | const { proxy } = getCurrentInstance(); |
| | | const isShowSummarySon = ref(true); |
| | |
| | | label: "付款金额", |
| | | prop: "currentPaymentAmount", |
| | | formatData: (params) => { |
| | | return params ? parseFloat(params).toFixed(2) : 0; |
| | | return params ? truncate(parseFloat(params), 3) : 0; |
| | | }, |
| | | }, |
| | | { |
| | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { getCurrentInstance, ref } from "vue"; |
| | | import useFormData from "@/hooks/useFormData"; |
| | | import { getProductRecordById } from "@/api/procurementManagement/procurementInvoiceLedger"; |
| | | import { truncate } from "@/utils/index.js"; |
| | | const { proxy } = getCurrentInstance() |
| | | |
| | | defineOptions({ |
| | |
| | | form.createdAt = data.createdAt; |
| | | form.invoiceNumber = data.invoiceNumber; |
| | | form.ticketsNum = data.ticketsNum; |
| | | form.ticketsAmount = data.ticketsAmount.toFixed(2); |
| | | form.ticketsAmount = truncate(data.ticketsAmount, 3); |
| | | form.taxInclusiveUnitPrice = data.taxInclusiveUnitPrice; |
| | | form.futureTickets = data.futureTickets; |
| | | temFutureTickets.value = data.futureTickets; |
| | |
| | | // 确保所有数值都转换为数字类型进行计算 |
| | | const ticketsAmount = Number(form.ticketsNum) * Number(form.taxInclusiveUnitPrice); |
| | | const futureTickets = Number(temFutureTickets.value) - Number(form.ticketsNum); |
| | | form.futureTickets = Number(futureTickets.toFixed(2)); |
| | | form.ticketsAmount = Number(ticketsAmount.toFixed(2)); |
| | | form.futureTickets = Number(truncate(futureTickets, 3)); |
| | | form.ticketsAmount = Number(truncate(ticketsAmount, 3)); |
| | | }; |
| | | const inputTicketsAmount = (val) => { |
| | | // 确保含税单价存在且不为零 |
| | |
| | | |
| | | if (Number(val) > Number(form.futureTickets*form.taxInclusiveUnitPrice)) { |
| | | proxy.$modal.msgWarning("本次来票金额不得大于总金额"); |
| | | form.ticketsAmount = (form.futureTickets*form.taxInclusiveUnitPrice).toFixed(2) |
| | | form.ticketsAmount = truncate(form.futureTickets*form.taxInclusiveUnitPrice, 3) |
| | | const ticketsNum = Number(form.ticketsAmount) / Number(form.taxInclusiveUnitPrice); |
| | | form.ticketsNum = Number(ticketsNum.toFixed(2)) |
| | | form.ticketsNum = Number(truncate(ticketsNum, 3)) |
| | | return; |
| | | } |
| | | |
| | | // 确保所有数值都转换为数字类型进行计算 |
| | | const ticketsNum = Number(val) / Number(form.taxInclusiveUnitPrice); |
| | | form.ticketsNum = Number(ticketsNum.toFixed(2)); |
| | | form.ticketsNum = Number(truncate(ticketsNum, 3)); |
| | | }; |
| | | |
| | | defineExpose({ |
| | |
| | | import useUserStore from "@/store/modules/user.js"; |
| | | import dayjs from "dayjs"; |
| | | import FileList from "./fileList.vue"; |
| | | import { truncate } from "@/utils/index.js"; |
| | | |
| | | defineOptions({ |
| | | name: "来票台账", |
| | |
| | | prop: "taxInclusiveTotalPrice", |
| | | width: 200, |
| | | formatData: (cell) => { |
| | | return cell ? parseFloat(cell).toFixed(2) : 0; |
| | | return cell ? truncate(parseFloat(cell), 3) : 0; |
| | | }, |
| | | }, |
| | | { |
| | |
| | | prop: "ticketsAmount", |
| | | width: 200, |
| | | formatData: (cell) => { |
| | | return cell ? parseFloat(cell).toFixed(2) : 0; |
| | | return cell ? truncate(parseFloat(cell), 3) : 0; |
| | | }, |
| | | }, |
| | | { |
| | |
| | | prop: "unTicketsPrice", |
| | | width: 200, |
| | | formatData: (cell) => { |
| | | return cell ? parseFloat(cell).toFixed(2) : 0; |
| | | return cell ? truncate(parseFloat(cell), 3) : 0; |
| | | }, |
| | | }, |
| | | { |
| | |
| | | <el-form-item label="含税单价(元):" prop="taxInclusiveUnitPrice"> |
| | | <el-input-number |
| | | v-model="productForm.taxInclusiveUnitPrice" |
| | | :precision="2" |
| | | :precision="3" |
| | | :step="0.1" |
| | | clearable |
| | | style="width: 100%" |
| | |
| | | <el-input-number |
| | | :step="0.1" |
| | | clearable |
| | | :precision="2" |
| | | :precision="3" |
| | | style="width: 100%" |
| | | v-model="productForm.quantity" |
| | | placeholder="请输入" |
| | |
| | | <el-form-item label="含税总价(元):" prop="taxInclusiveTotalPrice"> |
| | | <el-input-number |
| | | v-model="productForm.taxInclusiveTotalPrice" |
| | | :precision="2" |
| | | :precision="3" |
| | | :step="0.1" |
| | | clearable |
| | | style="width: 100%" |
| | |
| | | <el-form-item label="库存预警数量:" prop="warnNum"> |
| | | <el-input-number |
| | | v-model="productForm.warnNum" |
| | | :precision="2" |
| | | :precision="3" |
| | | :step="0.1" |
| | | clearable |
| | | style="width: 100%" |
| | |
| | | <el-form-item label="合同金额(元):" prop="contractAmount"> |
| | | <el-input-number |
| | | v-model="scanAddForm.contractAmount" |
| | | :precision="2" |
| | | :precision="3" |
| | | :step="0.1" |
| | | clearable |
| | | style="width: 100%" |
| | |
| | | import useUserStore from "@/store/modules/user"; |
| | | import { modelList, productTreeList } from "@/api/basicData/product.js"; |
| | | import dayjs from "dayjs"; |
| | | import { getCurrentDate } from "@/utils/index.js"; |
| | | import { getCurrentDate, truncate } from "@/utils/index.js"; |
| | | |
| | | const userStore = useUserStore(); |
| | | |
| | |
| | | }; |
| | | |
| | | const formattedNumber = (row, column, cellValue) => { |
| | | return parseFloat(cellValue).toFixed(2); |
| | | return truncate(parseFloat(cellValue), 3); |
| | | }; |
| | | // 查询列表 |
| | | /** 搜索按钮操作 */ |
| | |
| | | } |
| | | // 含税总价计算 |
| | | productForm.value.taxInclusiveTotalPrice = |
| | | proxy.calculateTaxIncludeTotalPrice( |
| | | productForm.value.taxInclusiveUnitPrice, |
| | | productForm.value.quantity |
| | | truncate( |
| | | Number(productForm.value.taxInclusiveUnitPrice) * Number(productForm.value.quantity), |
| | | 3 |
| | | ); |
| | | if (productForm.value.taxRate) { |
| | | // 不含税总价计算 |
| | | const taxRate = Number(productForm.value.taxRate); |
| | | const taxRateDecimal = taxRate / 100; |
| | | productForm.value.taxExclusiveTotalPrice = |
| | | proxy.calculateTaxExclusiveTotalPrice( |
| | | productForm.value.taxInclusiveTotalPrice, |
| | | productForm.value.taxRate |
| | | truncate( |
| | | Number(productForm.value.taxInclusiveTotalPrice) / (1 + taxRateDecimal), |
| | | 3 |
| | | ); |
| | | } |
| | | }; |
| | |
| | | // 已知含税总价和数量,反算含税单价 |
| | | if (productForm.value.quantity) { |
| | | productForm.value.taxInclusiveUnitPrice = |
| | | (Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.quantity)).toFixed(2); |
| | | truncate(Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.quantity), 3); |
| | | } |
| | | // 已知含税总价和含税单价,反算数量 |
| | | else if (productForm.value.taxInclusiveUnitPrice) { |
| | | productForm.value.quantity = |
| | | (Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.taxInclusiveUnitPrice)).toFixed(2); |
| | | truncate(Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.taxInclusiveUnitPrice), 3); |
| | | } |
| | | // 反算不含税总价 |
| | | productForm.value.taxExclusiveTotalPrice = |
| | | (Number(productForm.value.taxInclusiveTotalPrice) / (1 + taxRate / 100)).toFixed(2); |
| | | truncate(Number(productForm.value.taxInclusiveTotalPrice) / (1 + taxRate / 100), 3); |
| | | } else if (field === 'taxExclusiveTotalPrice') { |
| | | // 反算含税总价 |
| | | productForm.value.taxInclusiveTotalPrice = |
| | | (Number(productForm.value.taxExclusiveTotalPrice) * (1 + taxRate / 100)).toFixed(2); |
| | | truncate(Number(productForm.value.taxExclusiveTotalPrice) * (1 + taxRate / 100), 3); |
| | | // 已知数量,反算含税单价 |
| | | if (productForm.value.quantity) { |
| | | productForm.value.taxInclusiveUnitPrice = |
| | | (Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.quantity)).toFixed(2); |
| | | truncate(Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.quantity), 3); |
| | | } |
| | | // 已知含税单价,反算数量 |
| | | else if (productForm.value.taxInclusiveUnitPrice) { |
| | | productForm.value.quantity = |
| | | (Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.taxInclusiveUnitPrice)).toFixed(2); |
| | | truncate(Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.taxInclusiveUnitPrice), 3); |
| | | } |
| | | } |
| | | }; |