修复点餐页面购物车初始化时未拿到商品信息导致判断是否可用限时折扣有误问题
This commit is contained in:
@@ -308,8 +308,7 @@
|
||||
) {
|
||||
youhuiReset();
|
||||
}
|
||||
if (Message.operate_type == 'bulk_edit') {
|
||||
}
|
||||
if (Message.operate_type == 'bulk_edit') {}
|
||||
return Message;
|
||||
}
|
||||
|
||||
@@ -319,24 +318,27 @@
|
||||
|
||||
let cartsSocket = null;
|
||||
cartStore.goodsInit();
|
||||
const socketInitPar = {
|
||||
const socketInitPar = reactive({
|
||||
type: "shopping",
|
||||
operate_type: "init",
|
||||
table_code: uni.cache.get("tableCode"),
|
||||
shop_id: uni.cache.get("shopId"),
|
||||
};
|
||||
time_dis_info: null
|
||||
});
|
||||
|
||||
|
||||
|
||||
function socketInit() {
|
||||
cartsSocket = useWebSocket();
|
||||
cartStore.socketSendMsg=(data)=>{
|
||||
cartStore.socketSendMsg = (data) => {
|
||||
cartsSocket.sendMessage({
|
||||
...data,
|
||||
table_code: uni.cache.get("tableCode"),
|
||||
shop_id: uni.cache.get("shopId"),
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
cartsSocket.connect(socketInitPar, onMessage);
|
||||
}
|
||||
const noPayStatus = {
|
||||
@@ -1097,8 +1099,8 @@
|
||||
Object.assign(listinfo, res);
|
||||
getOrderInfoAfterCalcInit(res);
|
||||
}
|
||||
|
||||
const limitTimeDiscountRes=ref(null)
|
||||
|
||||
const limitTimeDiscountRes = ref(null)
|
||||
async function init(opt) {
|
||||
await storeuser.actionsproductqueryProduct();
|
||||
|
||||
@@ -1120,16 +1122,16 @@
|
||||
if (res && typeof res == "object") {
|
||||
setOrder(res);
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
const limitRes = await limitTimeDiscountapi.getConfig({
|
||||
shopId: uni.cache.get('shopId')
|
||||
});
|
||||
if (limitRes && typeof limitRes == 'object') {
|
||||
limitTimeDiscountRes.value = limitRes;
|
||||
|
||||
|
||||
} else {
|
||||
limitTimeDiscountRes.value = null;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
//获取店铺信息
|
||||
@@ -1265,7 +1267,14 @@
|
||||
});
|
||||
|
||||
watch(() => cartStore.limitTimeDiscount, (newval, oldval) => {
|
||||
|
||||
|
||||
})
|
||||
|
||||
watch(()=>cartStore.limitTimeDiscount,(newval)=>{
|
||||
socketInitPar.time_dis_info=newval
|
||||
},{
|
||||
deep:true,
|
||||
immediate:true
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -1289,7 +1298,8 @@
|
||||
) ?
|
||||
1 :
|
||||
0;
|
||||
if (canUseLimitTimeDiscount != cart.isTimeDiscount) {
|
||||
const is_time_discount = cart.isTimeDiscount || cart.is_time_discount
|
||||
if (canUseLimitTimeDiscount != is_time_discount) {
|
||||
newData.history.push({
|
||||
id: cart.id,
|
||||
is_time_discount: canUseLimitTimeDiscount,
|
||||
@@ -1307,7 +1317,9 @@
|
||||
) ?
|
||||
1 :
|
||||
0;
|
||||
if (canUseLimitTimeDiscount != cart.isTimeDiscount) {
|
||||
|
||||
const is_time_discount = cart.isTimeDiscount || cart.is_time_discount
|
||||
if (canUseLimitTimeDiscount != is_time_discount) {
|
||||
newData.cart.push({
|
||||
id: cart.id,
|
||||
is_time_discount: canUseLimitTimeDiscount,
|
||||
@@ -1318,8 +1330,8 @@
|
||||
if (newData.history.length <= 0 && newData.cart.length <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('bulk_edit',{
|
||||
|
||||
console.log('bulk_edit', {
|
||||
...socketInitPar,
|
||||
operate_type: "bulk_edit",
|
||||
data: newData,
|
||||
|
||||
@@ -1455,7 +1455,8 @@
|
||||
type: 'shopping',
|
||||
operate_type: 'init',
|
||||
table_code: uni.cache.get('tableCode'),
|
||||
shop_id: uni.cache.get('shopId')
|
||||
shop_id: uni.cache.get('shopId'),
|
||||
time_dis_info: null
|
||||
}
|
||||
};
|
||||
const useSocket = useWebSocket();
|
||||
@@ -1554,20 +1555,29 @@
|
||||
|
||||
// 购物车初始化时进行判断商品是否可以使用限时折扣,然后更新
|
||||
let socketTimer = null
|
||||
|
||||
|
||||
// 返回商品对应sku数据
|
||||
|
||||
function cartInit(arr) {
|
||||
const result = []
|
||||
cartStore.carts = arr.map(v => {
|
||||
const is_time_discount = limitUtils.canUseLimitTimeDiscount(v, cartStore.limitTimeDiscount, shopInfo,
|
||||
const goods=matchedProducts.value.find(g=>g.id==v.product_id)
|
||||
const goodsSkuList=goods.skuList||[]
|
||||
const findSku=goodsSkuList.find(sku=>sku.id==v.sku_id)
|
||||
const memberPrice=findSku?findSku.memberPrice:0
|
||||
const is_time_discount = limitUtils.canUseLimitTimeDiscount({...v,memberPrice}, cartStore.limitTimeDiscount, shopInfo,
|
||||
shopUserInfo.value, 'product_id');
|
||||
return {
|
||||
...v,
|
||||
is_time_discount: is_time_discount ? 1 : 0
|
||||
is_time_discount: is_time_discount ? 1 : 0,
|
||||
memberPrice
|
||||
}
|
||||
})
|
||||
|
||||
for (let cart of arr) {
|
||||
const findItem = cartStore.carts.find(v => v.id == cart.id)
|
||||
console.log('findItem',findItem)
|
||||
console.log('matchedProducts',matchedProducts.value)
|
||||
if (findItem && findItem.is_time_discount != cart.is_time_discount) {
|
||||
result.push({
|
||||
id: cart.id,
|
||||
@@ -1670,14 +1680,14 @@
|
||||
time_dis_info: cartStore.limitTimeDiscount
|
||||
};
|
||||
console.log('cartStore.limitTimeDiscount', cartStore.limitTimeDiscount)
|
||||
useSocket.sendMessage({
|
||||
type: 'shopping',
|
||||
operate_type: 'time_discount_save',
|
||||
table_code: Message.data.new_table_code,
|
||||
shop_id: uni.cache.get('shopId'),
|
||||
operate_type: 'time_discount_save',
|
||||
data: cartStore.limitTimeDiscount
|
||||
});
|
||||
// useSocket.sendMessage({
|
||||
// type: 'shopping',
|
||||
// operate_type: 'time_discount_save',
|
||||
// table_code: Message.data.new_table_code,
|
||||
// shop_id: uni.cache.get('shopId'),
|
||||
// operate_type: 'time_discount_save',
|
||||
// data: cartStore.limitTimeDiscount
|
||||
// });
|
||||
useSocket.sendMessage(data);
|
||||
}
|
||||
|
||||
@@ -1854,11 +1864,14 @@
|
||||
let res = await APIhistoryOrder({
|
||||
tableCode: uni.cache.get('tableCode')
|
||||
});
|
||||
orderinfo.value = {
|
||||
id: res.id,
|
||||
detailMap: res.detailMap,
|
||||
placeNum: res.placeNum
|
||||
};
|
||||
if (res && typeof res === 'object') {
|
||||
orderinfo.value = {
|
||||
id: res.id,
|
||||
detailMap: res.detailMap,
|
||||
placeNum: res.placeNum
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2272,7 +2285,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const limitTimeDiscountRes = ref(null);
|
||||
onLoad(async (e) => {
|
||||
if (e.type) {
|
||||
orderType.value = e.type;
|
||||
@@ -2289,12 +2302,13 @@
|
||||
Object.assign(shopInfo, shopInfoRes.shopInfo);
|
||||
uni.cache.set('shopInfo', shopInfoRes.shopInfo)
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (userInfo && typeof userInfo === 'object') {
|
||||
shopUserInfo.value = userInfo
|
||||
uni.cache.set('shopUserInfo', userInfo)
|
||||
}
|
||||
await productqueryProduct();
|
||||
|
||||
const extraInitPar = {}
|
||||
if (e.one_more_order && e.order_id) {
|
||||
@@ -2302,24 +2316,40 @@
|
||||
extraInitPar.order_id = e.order_id
|
||||
extraInitPar.user_id = uni.cache.get('userInfo').id || ''
|
||||
}
|
||||
|
||||
const time_dis_info= await getLimitDiscount()
|
||||
|
||||
const time_dis_info = await getLimitDiscount()
|
||||
options.initMessage.time_dis_info = time_dis_info
|
||||
useSocket.connect({
|
||||
...options.initMessage,
|
||||
...extraInitPar,
|
||||
time_dis_info
|
||||
}, onMessage);
|
||||
|
||||
|
||||
cartStore.setOldOrder({
|
||||
detailMap: {},
|
||||
originAmount: 0
|
||||
});
|
||||
await proxy.$onLaunched;
|
||||
|
||||
|
||||
//新客立减
|
||||
getNewUserDiscount();
|
||||
// 满减活动
|
||||
getDiscountActivity();
|
||||
|
||||
let res = await APIhistoryOrder({
|
||||
tableCode: uni.cache.get('tableCode')
|
||||
});
|
||||
oldOrder.value = res;
|
||||
if (res && res.id && shopInfo.registerType == 'after') {
|
||||
toHistory();
|
||||
return;
|
||||
}
|
||||
setTimeout(() => {
|
||||
// 启动网络监听
|
||||
useSocket.initNetworkListener();
|
||||
getElementTop();
|
||||
}, 500);
|
||||
});
|
||||
|
||||
const limitTimeDiscountRes = ref(null);
|
||||
const nowTime = ref(getEndTimeInSeconds(dayjs().format('HH:mm')));
|
||||
let timer = setInterval(() => {
|
||||
nowTime.value = getEndTimeInSeconds(dayjs().format('HH:mm'));
|
||||
@@ -2356,7 +2386,8 @@
|
||||
if (!cartStore.limitTimeDiscount || !cartStore.limitTimeDiscount.id) {
|
||||
return 0;
|
||||
}
|
||||
return limitUtils.canUseLimitTimeDiscount(item, cartStore.limitTimeDiscount, shopInfo, shopUserInfo.value, 'id')?1:0;
|
||||
return limitUtils.canUseLimitTimeDiscount(item, cartStore.limitTimeDiscount, shopInfo, shopUserInfo.value, 'id') ?
|
||||
1 : 0;
|
||||
}
|
||||
|
||||
function returnLimitPrice(item) {
|
||||
@@ -2474,10 +2505,10 @@
|
||||
return 0
|
||||
})
|
||||
const oldOrder = ref(null);
|
||||
|
||||
|
||||
// 限时折扣
|
||||
async function getLimitDiscount(){
|
||||
|
||||
async function getLimitDiscount() {
|
||||
|
||||
const limitRes = await limitTimeDiscountapi.getConfig({
|
||||
shopId: uni.cache.get('shopId')
|
||||
});
|
||||
@@ -2486,7 +2517,6 @@
|
||||
} else {
|
||||
cartStore.limitTimeDiscount = null;
|
||||
}
|
||||
return cartStore.limitTimeDiscount
|
||||
websocketsendMessage({
|
||||
type: 'shopping',
|
||||
operate_type: 'time_discount_save',
|
||||
@@ -2496,38 +2526,10 @@
|
||||
data: cartStore.limitTimeDiscount
|
||||
});
|
||||
console.log('onMounted:限时折扣', cartStore.limitTimeDiscount);
|
||||
return cartStore.limitTimeDiscount
|
||||
}
|
||||
onMounted(async () => {
|
||||
// #ifdef MP-WEIXIN
|
||||
await proxy.$onLaunched;
|
||||
// #endif
|
||||
// 获取当前页面栈
|
||||
const pages = getCurrentPages();
|
||||
|
||||
// 获取当前页面实例
|
||||
const currentPage = pages[pages.length - 1];
|
||||
// 获取页面参数
|
||||
const options = currentPage.options;
|
||||
console.log('onMounted', options);
|
||||
//新客立减
|
||||
getNewUserDiscount();
|
||||
// 满减活动
|
||||
getDiscountActivity();
|
||||
|
||||
let res = await APIhistoryOrder({
|
||||
tableCode: uni.cache.get('tableCode')
|
||||
});
|
||||
oldOrder.value = res;
|
||||
await productqueryProduct();
|
||||
if (res && res.id && shopInfo.registerType == 'after') {
|
||||
toHistory();
|
||||
return;
|
||||
}
|
||||
setTimeout(() => {
|
||||
// 启动网络监听
|
||||
useSocket.initNetworkListener();
|
||||
getElementTop();
|
||||
}, 500);
|
||||
|
||||
});
|
||||
|
||||
//跳转历史订单
|
||||
|
||||
Reference in New Issue
Block a user