订单详情完善
This commit is contained in:
@@ -16,11 +16,19 @@ export const useCartStore = defineStore('cart', () => {
|
||||
// const isTableFee = uni.cache.get('ordershopUserInfo').isTableFee //此店是否免桌位费
|
||||
// const tableFee = uni.cache.get('ordershopUserInfo').tableFee //一个餐位费多钱
|
||||
|
||||
// 计算单个商品的打包费用(向下取整并保留两位小数)
|
||||
const itemSinglePackFee = (item) => {
|
||||
const fee = item.packFee * item.cartNumber;
|
||||
// 先将结果乘以 100,向下取整,再除以 100 以保留两位小数
|
||||
return Math.floor(fee * 100) / 100
|
||||
// 计算向上取整
|
||||
const roundUpToTwoDecimals = (num, i) => {
|
||||
// 先将数字乘以 100 并转换为字符串保留足够的小数位
|
||||
let temp = (num * 100).toFixed(10);
|
||||
// 向上取整
|
||||
let rounded = null
|
||||
if (i == 'upward') {
|
||||
rounded = Math.ceil(parseFloat(temp));
|
||||
} else {
|
||||
rounded = Math.floor(parseFloat(temp));
|
||||
}
|
||||
// 再除以 100 得到保留两位小数的结果
|
||||
return rounded / 100;
|
||||
};
|
||||
|
||||
// 计算购物车商品总价格
|
||||
@@ -43,7 +51,8 @@ export const useCartStore = defineStore('cart', () => {
|
||||
}
|
||||
}, 0);
|
||||
// 向上取整并保留两位小数
|
||||
return cart = Math.ceil(cart * 100) / 100;
|
||||
let result = roundUpToTwoDecimals(cart, 'upward')
|
||||
return result;
|
||||
});
|
||||
|
||||
// 计算商品卷所选择的总价格
|
||||
@@ -64,34 +73,33 @@ export const useCartStore = defineStore('cart', () => {
|
||||
}
|
||||
}, 0);
|
||||
// 向上取整并保留两位小数
|
||||
return cart = Math.ceil(cart * 100) / 100;
|
||||
let result = roundUpToTwoDecimals(cart, 'upward')
|
||||
return result;
|
||||
});
|
||||
|
||||
// 桌位置
|
||||
const getTotalSeatcharge = (seatNum) => computed(() => {
|
||||
// 是否免除桌位费 0 否 1 是
|
||||
let tableFeeTotals = 0
|
||||
let cart = 0
|
||||
|
||||
if (uni.cache.get('ordershopUserInfo').isTableFee == 0 && (seatNum || uni.cache.get('dinersNum'))) {
|
||||
tableFeeTotals = Math.ceil(parseFloat((seatNum || uni.cache.get('dinersNum'))) * parseFloat(
|
||||
if (uni.cache.get('ordershopUserInfo').isTableFee == 0 && seatNum) {
|
||||
cart = Math.ceil(parseFloat(seatNum) * parseFloat(
|
||||
uni.cache.get('ordershopUserInfo').tableFee) * 100) / 100;
|
||||
}
|
||||
console.log(uni.cache.get('ordershopUserInfo').isTableFee,seatNum,22222)
|
||||
return Math.floor(tableFeeTotals * 100) / 100;
|
||||
// 向下取整并保留两位小数
|
||||
let result = roundUpToTwoDecimals(cart, 'downward')
|
||||
return result;
|
||||
});
|
||||
|
||||
// 计算购物车总打包费用(向下取整并保留两位小数)
|
||||
const getTotalPackFee = (cartList) => computed(() => {
|
||||
let total = 0;
|
||||
for (const item of cartList) {
|
||||
total += itemSinglePackFee(item);
|
||||
}
|
||||
return Math.floor(total * 100) / 100 ? Math.floor(total * 100) / 100 : 0;
|
||||
// 同样对总费用进行向下取整并保留两位小数处理
|
||||
const total = cartList.reduce((sum, item) => {
|
||||
return sum + item.packAmount * (item.packNumber || (item.num - item.returnNum));
|
||||
}, 0);
|
||||
return Math.floor(total * 100) / 100;
|
||||
});
|
||||
|
||||
return {
|
||||
itemSinglePackFee,
|
||||
getTotalPackFee,
|
||||
getTotalSeatcharge,
|
||||
getTotalTotalPrices,
|
||||
|
||||
@@ -8,7 +8,8 @@ import {
|
||||
|
||||
import {
|
||||
APIpayltPayOrder,
|
||||
APIpayltPayVip
|
||||
APIpayltPayVip,
|
||||
APIrefundVip
|
||||
} from '@/common/api/pay.js'
|
||||
|
||||
import {
|
||||
@@ -182,6 +183,37 @@ export const Memberpay = defineStore('memberpay', {
|
||||
})
|
||||
},
|
||||
|
||||
//会员支付
|
||||
balancePayOrder(data) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let res = await APIrefundVip({
|
||||
shopId: uni.cache.get('shopId'),
|
||||
checkOrderPay: data.checkOrderPay,
|
||||
pwd: data.pwd,
|
||||
payType: 'accountPay',
|
||||
returnUrl: data.returnUrl,
|
||||
buyerRemark: data.buyerRemark,
|
||||
shopUserId: data.shopUserId,
|
||||
})
|
||||
if (res) {
|
||||
uni.showLoading({
|
||||
title: '加载中...',
|
||||
mask: true
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
uni.showToast({
|
||||
title: "支付失败"
|
||||
})
|
||||
setTimeout(() => {
|
||||
uni.hideLoading()
|
||||
}, 1000)
|
||||
reject(false)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 生成订单
|
||||
actionscreateOrder(data) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
|
||||
Reference in New Issue
Block a user