优惠卷和商品卷
This commit is contained in:
@@ -10,8 +10,12 @@ import {
|
||||
} from 'vue';
|
||||
|
||||
export const useCartStore = defineStore('cart', () => {
|
||||
const shopInfo = null
|
||||
const dinersNum = uni.cache.get('dinersNum')
|
||||
// const dinersNum = uni.cache.get('dinersNum')
|
||||
// const isVip = uni.cache.get('orderVIP').isVip //此用户是否是会员
|
||||
// const isMemberPrice = uni.cache.get('ordershopUserInfo').isMemberPrice //此店是否可以用会员
|
||||
// const isTableFee = uni.cache.get('ordershopUserInfo').isTableFee //此店是否免桌位费
|
||||
// const tableFee = uni.cache.get('ordershopUserInfo').tableFee //一个餐位费多钱
|
||||
|
||||
// 计算单个商品的打包费用(向下取整并保留两位小数)
|
||||
const itemSinglePackFee = (item) => {
|
||||
const fee = item.packFee * item.cartNumber;
|
||||
@@ -24,15 +28,39 @@ export const useCartStore = defineStore('cart', () => {
|
||||
if (!matchedProducts || !Array.isArray(matchedProducts)) {
|
||||
return 0;
|
||||
}
|
||||
// console.log(uni.cache.get('orderVIP').isVip, uni.cache.get('ordershopUserInfo').isMemberPrice,
|
||||
// 111)
|
||||
// 购物车总数价格
|
||||
let cart = matchedProducts.reduce((total, item) => {
|
||||
// 是否启用会员价 0否1是
|
||||
if (shopInfo.isVip == 1 && shopInfo.isMemberPrice == 1) {
|
||||
if (uni.cache.get('orderVIP').isVip == 1 && uni.cache.get('ordershopUserInfo')
|
||||
.isMemberPrice == 1) {
|
||||
// memberPrice会员价
|
||||
return total + parseFloat(item.memberPrice) * parseFloat(item.cartNumber);
|
||||
return total + parseFloat(item.memberPrice) * parseFloat(item.num);
|
||||
} else {
|
||||
// salePrice销售价
|
||||
return total + parseFloat(item.salePrice) * parseFloat(item.cartNumber);
|
||||
return total + parseFloat(item.price) * parseFloat(item.num);
|
||||
}
|
||||
}, 0);
|
||||
// 向上取整并保留两位小数
|
||||
return cart = Math.ceil(cart * 100) / 100;
|
||||
});
|
||||
|
||||
// 计算商品卷所选择的总价格
|
||||
const getTotalProductroll = (matchedProducts) => computed(() => {
|
||||
if (!matchedProducts || !Array.isArray(matchedProducts)) {
|
||||
return 0;
|
||||
}
|
||||
// 购物车总数价格
|
||||
let cart = matchedProducts.reduce((total, item) => {
|
||||
// 是否启用会员价 0否1是
|
||||
if (uni.cache.get('orderVIP').isVip == 1 && uni.cache.get('ordershopUserInfo')
|
||||
.isMemberPrice == 1) {
|
||||
// memberPrice会员价
|
||||
return total + parseFloat(item.memberPrice)
|
||||
} else {
|
||||
// salePrice销售价
|
||||
return total + parseFloat(item.price)
|
||||
}
|
||||
}, 0);
|
||||
// 向上取整并保留两位小数
|
||||
@@ -40,18 +68,16 @@ export const useCartStore = defineStore('cart', () => {
|
||||
});
|
||||
|
||||
// 桌位置
|
||||
const getTotalSeatcharge = () => computed(() => {
|
||||
const getTotalSeatcharge = (seatNum) => computed(() => {
|
||||
// 是否免除桌位费 0 否 1 是
|
||||
let tableFeeTotals = 0
|
||||
try {
|
||||
if (shopInfo.isTableFee == 0 && dinersNum) {
|
||||
const tableFeeTotals = Math.ceil(parseFloat(dinersNum) * parseFloat(shopInfo
|
||||
.tableFee) * 100) / 100;
|
||||
}
|
||||
} catch (error) {
|
||||
//TODO handle the exception
|
||||
|
||||
if (uni.cache.get('ordershopUserInfo').isTableFee == 0 && (seatNum || uni.cache.get('dinersNum'))) {
|
||||
tableFeeTotals = Math.ceil(parseFloat((seatNum || uni.cache.get('dinersNum'))) * parseFloat(
|
||||
uni.cache.get('ordershopUserInfo').tableFee) * 100) / 100;
|
||||
}
|
||||
return Math.floor(tableFeeTotals * 100) / 100 ? Math.floor(tableFeeTotals * 100) / 100 : 0;
|
||||
console.log(uni.cache.get('ordershopUserInfo').isTableFee,seatNum,22222)
|
||||
return Math.floor(tableFeeTotals * 100) / 100;
|
||||
});
|
||||
|
||||
// 计算购物车总打包费用(向下取整并保留两位小数)
|
||||
@@ -68,6 +94,7 @@ export const useCartStore = defineStore('cart', () => {
|
||||
itemSinglePackFee,
|
||||
getTotalPackFee,
|
||||
getTotalSeatcharge,
|
||||
getTotalTotalPrices
|
||||
getTotalTotalPrices,
|
||||
getTotalProductroll
|
||||
};
|
||||
});
|
||||
@@ -62,6 +62,9 @@ export const Memberpay = defineStore('memberpay', {
|
||||
title: "支付成功"
|
||||
})
|
||||
console.log('支付成功')
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1000)
|
||||
resolve(res)
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
@@ -69,6 +72,9 @@ export const Memberpay = defineStore('memberpay', {
|
||||
uni.showToast({
|
||||
title: "支付成功"
|
||||
})
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 1000)
|
||||
resolve(res)
|
||||
} else {
|
||||
uni.showToast({
|
||||
@@ -110,14 +116,14 @@ export const Memberpay = defineStore('memberpay', {
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
payType: 'aliPay',
|
||||
openId: uni.cache.get('alipayOpenId').wechatOpenId,
|
||||
openId: uni.cache.get('alipayOpenId').alipayOpenId,
|
||||
// #endif
|
||||
returnUrl: data.returnUrl,
|
||||
buyerRemark: data.buyerRemark,
|
||||
})
|
||||
if (res) {
|
||||
uni.showLoading({
|
||||
title: '支付吊起中...',
|
||||
title: '加载中...',
|
||||
mask: true
|
||||
})
|
||||
uni.requestPayment({
|
||||
|
||||
@@ -95,46 +95,75 @@ export const productStore = defineStore('product', {
|
||||
return null;
|
||||
},
|
||||
// 扫码请求
|
||||
scanCodeactions() {
|
||||
scanCodeactions(q) {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// #ifdef APP || MP-WEIXIN || MP-ALIPAY
|
||||
uni.scanCode({
|
||||
success: async (res) => {
|
||||
let tableCode = this.getQueryString(
|
||||
decodeURIComponent(res
|
||||
.result),
|
||||
'code')
|
||||
// 储存卓玛
|
||||
uni.cache.set('tableCode', tableCode)
|
||||
if (tableCode) {
|
||||
let data = await this.actionsproductqueryShop()
|
||||
// -4请求登录
|
||||
const store = Storelogin()
|
||||
if (data.code == '-4') {
|
||||
if (await store.actionslogin()) {
|
||||
// 成功 接着在调用
|
||||
await this.actionsproductqueryShop()
|
||||
}
|
||||
}
|
||||
// 是否免除桌位费 0否1是
|
||||
if (uni.cache.get('shopInfo').isTableFee == 0) {
|
||||
uni.pro.navigateTo('product/choosetable')
|
||||
} else {
|
||||
uni.pro.navigateTo(
|
||||
'product/index', {
|
||||
tableCode: tableCode,
|
||||
})
|
||||
}
|
||||
if (q) {
|
||||
// #ifdef MP-WEIXIN
|
||||
let tableCode = this.getQueryString(decodeURIComponent(q), 'code')
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
let tableCode = q
|
||||
// #endif
|
||||
|
||||
// 储存卓玛
|
||||
uni.cache.set('tableCode', tableCode)
|
||||
if (tableCode) {
|
||||
let data = await this.actionsproductqueryShop()
|
||||
// -4请求登录
|
||||
const store = Storelogin()
|
||||
if (data.code == '-4') {
|
||||
if (await store.actionslogin()) {
|
||||
// 成功 接着在调用
|
||||
await this.actionsproductqueryShop()
|
||||
}
|
||||
}
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log(res)
|
||||
// 是否免除桌位费 0否1是
|
||||
if (uni.cache.get('shopInfo').isTableFee == 0) {
|
||||
uni.pro.navigateTo('product/choosetable')
|
||||
} else {
|
||||
uni.pro.navigateTo(
|
||||
'product/index', {
|
||||
tableCode: tableCode,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
|
||||
} else {
|
||||
// #ifdef APP || MP-WEIXIN || MP-ALIPAY
|
||||
uni.scanCode({
|
||||
success: async (res) => {
|
||||
let tableCode = this.getQueryString(
|
||||
decodeURIComponent(res.result), 'code')
|
||||
// 储存卓玛
|
||||
uni.cache.set('tableCode', tableCode)
|
||||
if (tableCode) {
|
||||
let data = await this.actionsproductqueryShop()
|
||||
// -4请求登录
|
||||
const store = Storelogin()
|
||||
if (data.code == '-4') {
|
||||
if (await store.actionslogin()) {
|
||||
// 成功 接着在调用
|
||||
await this.actionsproductqueryShop()
|
||||
}
|
||||
}
|
||||
// 是否免除桌位费 0否1是
|
||||
if (uni.cache.get('shopInfo').isTableFee == 0) {
|
||||
uni.pro.navigateTo('product/choosetable')
|
||||
} else {
|
||||
uni.pro.navigateTo(
|
||||
'product/index', {
|
||||
tableCode: tableCode,
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log(res)
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
}
|
||||
// #ifdef H5
|
||||
if (uni.cache.get('tableCode')) {
|
||||
let data = await this.actionsproductqueryShop()
|
||||
|
||||
Reference in New Issue
Block a user