update: 单价和实际金额 结算单价 结算金额控制小数位数

This commit is contained in:
admin 2024-07-22 17:14:00 +08:00
parent 12f325e46e
commit ea7e4ddb27
5 changed files with 133 additions and 65 deletions

View File

@ -127,12 +127,10 @@
import { import {
DeviceApi, DeviceApi,
PictureApi, PictureApi,
ProfileApi,
ReceiveApi, ReceiveApi,
ReceiveProductApi, ReceiveProductApi,
SupplierApi,
} from "@/services"; } from "@/services";
import { countDots, formatDate } from "@/utils"; import { countDots, formatDate, isTwoDecimalPlaces } from "@/utils";
import { DeviceType, ImagesType, OrderType } from "@/utils/enum"; import { DeviceType, ImagesType, OrderType } from "@/utils/enum";
import _ from "underscore"; import _ from "underscore";
import ProductDialog from "@/components/Dialog/ProductDialog.vue"; import ProductDialog from "@/components/Dialog/ProductDialog.vue";
@ -570,6 +568,21 @@ const save = () => {
}); });
return; return;
} }
if (countDots(model1.order.price) === 1 && isTwoDecimalPlaces(model1.order.price)) {
uni.showToast({
title: "单价最多只能输入2位小数",
icon: "none",
});
return
}
if (countDots(model1.order.balanceTotalPrice) === 1 && isTwoDecimalPlaces(model1.order.balanceTotalPrice)) {
uni.showToast({
title: "实际付款最多只能输入2位小数",
icon: "none",
});
return
}
check().then((res) => { check().then((res) => {
if (res) { if (res) {
startSave(); startSave();

View File

@ -546,6 +546,7 @@ const save = () => {
}); });
return; return;
} }
check().then((res) => { check().then((res) => {
if (res) { if (res) {
startSave(); startSave();

View File

@ -137,18 +137,13 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import type { ComType } from "@/types/global"; import type { ComType } from "@/types/global";
import { import { ReceiveApi, PictureApi, SupplierApi } from "@/services/index";
ReceiveProductApi,
ReceiveApi,
PictureApi,
SupplierApi,
} from "@/services/index";
import _ from "underscore"; import _ from "underscore";
import { onLoad, onShow } from "@dcloudio/uni-app"; import { onLoad, onShow } from "@dcloudio/uni-app";
import { ImagesType, OrderType } from "@/utils/enum"; import { ImagesType, OrderType } from "@/utils/enum";
import ProductDialog from "@/components/Dialog/ProductDialog.vue"; import ProductDialog from "@/components/Dialog/ProductDialog.vue";
import valid from "@/utils/validate"; import valid from "@/utils/validate";
import { countDots } from "@/utils"; import { countDots, isTwoDecimalPlaces } from "@/utils";
import Photo from "@/components/Photo/index.vue"; import Photo from "@/components/Photo/index.vue";
import CarNoDialog from "@/components/Dialog/CarNoDialog.vue"; import CarNoDialog from "@/components/Dialog/CarNoDialog.vue";
@ -679,6 +674,27 @@ const save = () => {
}); });
return; return;
} }
if (
countDots(model1.order.price + "") === 1 &&
isTwoDecimalPlaces(model1.order.price)
) {
uni.showToast({
title: "单价最多只能输入2位小数",
icon: "none",
});
return;
}
if (
countDots(model1.order.balanceTotalPrice + "") === 1 &&
isTwoDecimalPlaces(model1.order.balanceTotalPrice)
) {
uni.showToast({
title: "实际付款最多只能输入2位小数",
icon: "none",
});
return;
}
check().then((res) => { check().then((res) => {
if (res) { if (res) {
// //
@ -753,11 +769,11 @@ const updateOrder = () => {
}); });
}; };
const prePage = ref(""); const prePage = ref("");
const title = ref("") const title = ref("");
onLoad((option: any) => { onLoad((option: any) => {
model1.order.id = parseInt(option.id); model1.order.id = parseInt(option.id);
prePage.value = option.prePage; prePage.value = option.prePage;
title.value = option.title title.value = option.title;
if (prePage.value) { if (prePage.value) {
uni.setNavigationBarTitle({ uni.setNavigationBarTitle({

View File

@ -105,7 +105,12 @@
<script setup lang="ts"> <script setup lang="ts">
import { PictureApi, ShipmentApi } from "@/services"; import { PictureApi, ShipmentApi } from "@/services";
import type { ComType } from "@/types/global"; import type { ComType } from "@/types/global";
import { formatDate, num_subtract } from "@/utils"; import {
formatDate,
num_subtract,
countDots,
isTwoDecimalPlaces,
} from "@/utils";
import { import {
ImagesType, ImagesType,
OrderType, OrderType,
@ -471,7 +476,10 @@ watch(
预估总价 结算单价*结算重量 预估总价 结算单价*结算重量
实际收入实际结算金额-运费-杂费 实际收入实际结算金额-运费-杂费
*/ */
model1.order.settlementNet = num_subtract((settlementGrossNew || 0), (settlementTareNew || 0)) model1.order.settlementNet = num_subtract(
settlementGrossNew || 0,
settlementTareNew || 0
);
if (model1.order.buttonType === 0) { if (model1.order.buttonType === 0) {
if (model1.order.subtractNum) { if (model1.order.subtractNum) {
model1.order.settlementWeight = model1.order.settlementWeight =
@ -590,6 +598,27 @@ const save = () => {
} }
} }
if (
countDots(model1.order.unitPrice + "") === 1 &&
isTwoDecimalPlaces(model1.order.unitPrice)
) {
uni.showToast({
title: "结算单价最多只能输入2位小数",
icon: "none",
});
return;
}
if (
countDots(model1.order.totalPrice + "") === 1 &&
isTwoDecimalPlaces(model1.order.totalPrice)
) {
uni.showToast({
title: "结算金额最多只能输入2位小数",
icon: "none",
});
return;
}
check().then((res) => { check().then((res) => {
if (res) { if (res) {
if ( if (

View File

@ -271,10 +271,10 @@ export function countDots(str: any) {
} }
export function isTwoDecimalPlaces(num: any) { export function isTwoDecimalPlaces(num: any) {
// 转换为字符串并移除可能的符号 // 转换为字符串并移除可能的符号
const str = num.toString().replace(/[-]+/g, ''); const str = num.toString().replace(/[-]+/g, "");
// 分割整数部分和小数部分 // 分割整数部分和小数部分
const parts = str.split('.'); const parts = str.split(".");
console.log(parts) console.log(parts);
// 如果小数点后有两位数字返回true // 如果小数点后有两位数字返回true
return parts.length === 2 && parts[1].length > 2; return parts.length === 2 && parts[1].length > 2;
} }
@ -310,15 +310,15 @@ export function getScaleStatus(type: number, value: number) {
// 判断是否是时间格式 // 判断是否是时间格式
export function isDateTimePicker(str: any) { export function isDateTimePicker(str: any) {
return str.split(' ').length === 2 return str.split(" ").length === 2;
} }
// 格式化开始时间和结束时间 // 格式化开始时间和结束时间
export function formatStartAndEndTime(str: string, type: string) { export function formatStartAndEndTime(str: string, type: string) {
if (type === 's') { if (type === "s") {
return str ? isDateTimePicker(str) ? str : (str + " 00:00:00") : '' return str ? (isDateTimePicker(str) ? str : str + " 00:00:00") : "";
}else if (type === 'e') { } else if (type === "e") {
return str ? isDateTimePicker(str) ? str : (str + " 23:59:59") : '' return str ? (isDateTimePicker(str) ? str : str + " 23:59:59") : "";
} }
} }
@ -326,7 +326,7 @@ export function formatStartAndEndTime(str:string, type:string) {
export function num_add(num1: number, num2: number) { export function num_add(num1: number, num2: number) {
var r1, r2, m; var r1, r2, m;
try { try {
r1 = num1.toString().split('.')[1].length; r1 = num1.toString().split(".")[1].length;
} catch (e) { } catch (e) {
r1 = 0; r1 = 0;
} }
@ -343,7 +343,7 @@ export function num_add(num1: number,num2: number){
export function num_subtract(num1: number, num2: number) { export function num_subtract(num1: number, num2: number) {
var r1, r2, m, n; var r1, r2, m, n;
try { try {
r1 = num1.toString().split('.')[1].length; r1 = num1.toString().split(".")[1].length;
} catch (e) { } catch (e) {
r1 = 0; r1 = 0;
} }
@ -353,23 +353,32 @@ export function num_subtract(num1: number,num2: number){
r2 = 0; r2 = 0;
} }
m = Math.pow(10, Math.max(r1, r2)); m = Math.pow(10, Math.max(r1, r2));
n=(r1>=r2)?r1:r2; n = r1 >= r2 ? r1 : r2;
return Number((Math.round(num1 * m - num2 * m) / m).toFixed(n)); return Number((Math.round(num1 * m - num2 * m) / m).toFixed(n));
} }
// 两个浮点数相乘 // 两个浮点数相乘
export function num_multiply(num1: number, num2: number) { export function num_multiply(num1: number, num2: number) {
var m=0,s1=num1.toString(),s2=num2.toString(); var m = 0,
try{m+=s1.split(".")[1].length}catch(e){}; s1 = num1.toString(),
try{m+=s2.split(".")[1].length}catch(e){}; s2 = num2.toString();
return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m); try {
m += s1.split(".")[1].length;
} catch (e) {}
try {
m += s2.split(".")[1].length;
} catch (e) {}
return (
(Number(s1.replace(".", "")) * Number(s2.replace(".", ""))) /
Math.pow(10, m)
);
} }
// 两个浮点数相除 // 两个浮点数相除
export function num_divide(num1: number, num2: number) { export function num_divide(num1: number, num2: number) {
var t1, t2, r1, r2; var t1, t2, r1, r2;
try { try {
t1 = num1.toString().split('.')[1].length; t1 = num1.toString().split(".")[1].length;
} catch (e) { } catch (e) {
t1 = 0; t1 = 0;
} }