购物车打包费和餐位费封装
This commit is contained in:
parent
b40af3ea23
commit
56799f41f6
|
|
@ -0,0 +1,70 @@
|
|||
import {
|
||||
defineStore
|
||||
} from 'pinia';
|
||||
import {
|
||||
computed,
|
||||
watchEffect
|
||||
} from 'vue';
|
||||
import {
|
||||
ref
|
||||
} from 'vue';
|
||||
|
||||
export const useCartStore = defineStore('cart', () => {
|
||||
const shopInfo = uni.cache.get('shopInfo')
|
||||
const dinersNum = uni.cache.get('dinersNum')
|
||||
|
||||
// 计算单个商品的打包费用(向下取整并保留两位小数)
|
||||
const itemSinglePackFee = (item) => {
|
||||
const fee = item.packFee * item.cartNumber;
|
||||
// 先将结果乘以 100,向下取整,再除以 100 以保留两位小数
|
||||
return Math.floor(fee * 100) / 100
|
||||
};
|
||||
|
||||
// 计算购物车商品总价格
|
||||
const getTotalTotalPrices = (matchedProducts) => computed(() => {
|
||||
if (!matchedProducts || !Array.isArray(matchedProducts)) {
|
||||
return 0;
|
||||
}
|
||||
// 购物车总数价格
|
||||
let cart = matchedProducts.reduce((total, item) => {
|
||||
// 是否启用会员价 0否1是
|
||||
if (shopInfo.isVip == 1 && shopInfo.isMemberPrice == 1) {
|
||||
// memberPrice会员价
|
||||
return total + parseFloat(item.memberPrice) * parseFloat(item.cartNumber);
|
||||
} else {
|
||||
// salePrice销售价
|
||||
return total + parseFloat(item.salePrice) * parseFloat(item.cartNumber);
|
||||
}
|
||||
}, 0);
|
||||
// 向上取整并保留两位小数
|
||||
return cart = Math.ceil(cart * 100) / 100;
|
||||
});
|
||||
|
||||
// 桌位置
|
||||
const getTotalSeatcharge = () => computed(() => {
|
||||
// 是否免除桌位费 0 否 1 是
|
||||
let tableFeeTotals = 0
|
||||
if (shopInfo.isTableFee == 0 && dinersNum) {
|
||||
const tableFeeTotals = Math.ceil(parseFloat(dinersNum) * parseFloat(shopInfo
|
||||
.tableFee) * 100) / 100;
|
||||
}
|
||||
return Math.floor(tableFeeTotals * 100) / 100 ? Math.floor(tableFeeTotals * 100) / 100 : 0;
|
||||
});
|
||||
|
||||
// 计算购物车总打包费用(向下取整并保留两位小数)
|
||||
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;
|
||||
// 同样对总费用进行向下取整并保留两位小数处理
|
||||
});
|
||||
|
||||
return {
|
||||
itemSinglePackFee,
|
||||
getTotalPackFee,
|
||||
getTotalSeatcharge,
|
||||
getTotalTotalPrices
|
||||
};
|
||||
});
|
||||
|
|
@ -112,12 +112,12 @@ export const Memberpay = defineStore('memberpay', {
|
|||
payType: 'aliPay',
|
||||
openId: uni.cache.get('alipayOpenId').wechatOpenId,
|
||||
// #endif
|
||||
returnUrl: '',
|
||||
returnUrl: data.returnUrl,
|
||||
buyerRemark: data.buyerRemark,
|
||||
})
|
||||
if (res) {
|
||||
uni.showLoading({
|
||||
title: '加载中',
|
||||
title: '支付吊起中...',
|
||||
mask: true
|
||||
})
|
||||
uni.requestPayment({
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@ export const productStore = defineStore('product', {
|
|||
uni.cache.set('shopTable', res.shopTable)
|
||||
// 台桌信息
|
||||
uni.cache.set('shopInfo', res.shopInfo)
|
||||
uni.cache.set('shopId', res.shopTable.shopId,30)
|
||||
uni.cache.set('shopId', res.shopTable.shopId, 30)
|
||||
// 当前用户距离店铺的米数
|
||||
uni.cache.set('distance', res.distance)
|
||||
|
||||
|
|
@ -199,7 +199,7 @@ export const productStore = defineStore('product', {
|
|||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let res = await APIshopUserInfo()
|
||||
uni.cache.set('userInfo', res);
|
||||
uni.cache.set('shopUserInfo', res);
|
||||
resolve(true)
|
||||
} catch (e) {
|
||||
reject(false)
|
||||
|
|
@ -212,12 +212,13 @@ export const productStore = defineStore('product', {
|
|||
actionsAPIuser() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
// 获取店铺用户会员信息
|
||||
if (uni.cache.get('shopId')) {
|
||||
this.actionsproductqueryProduct()
|
||||
} else {
|
||||
let res = await APIuser()
|
||||
uni.cache.set('userInfo', res);
|
||||
}
|
||||
let res = await APIuser()
|
||||
uni.cache.set('userInfo', res);
|
||||
// }
|
||||
resolve(true)
|
||||
} catch (e) {
|
||||
reject(false)
|
||||
|
|
|
|||
Loading…
Reference in New Issue