修复商品更新剔除下架商品问题
This commit is contained in:
@@ -52,8 +52,8 @@
|
||||
|
||||
|
||||
<view class="relative">
|
||||
<image @click.stop="getProductImgs(item)" class="panelfiveitemimage" :src="item.coverImg"
|
||||
mode="aspectFill"></image>
|
||||
<image @click.stop="getProductImgs(item)" class="panelfiveitemimage"
|
||||
:src="item.coverImg" mode="aspectFill"></image>
|
||||
<view class="limitDiscount" v-if="showLimitDiscount(item)">
|
||||
限时折扣{{ limitDiscountCountdown }}</view>
|
||||
<!-- <view class="limitDiscount" v-if="item.is_time_discount">
|
||||
@@ -197,8 +197,8 @@
|
||||
<view class="goods" @click="clickspecifications(item1, index, index1)"
|
||||
v-for="(item1, index1) in item.productList" :key="item1.id">
|
||||
<view class="relative">
|
||||
<image class="goodsImg" @click.stop="getProductImgs(item1)" v-if="item1.coverImg != null"
|
||||
:lazy-load="true"
|
||||
<image class="goodsImg" @click.stop="getProductImgs(item1)"
|
||||
v-if="item1.coverImg != null" :lazy-load="true"
|
||||
:src="`${item1.coverImg}${!item1.imgLoad ? '?x-oss-process=image/resize,m_lfit,w_150,h_150' : ''}`"
|
||||
mode="aspectFill"></image>
|
||||
<image class="goodsImg"
|
||||
@@ -671,8 +671,8 @@
|
||||
import {
|
||||
useNavbarStore
|
||||
} from '@/stores/navbarStore';
|
||||
|
||||
|
||||
|
||||
|
||||
import {
|
||||
useWebSocket
|
||||
} from '@/stores/carts-websocket.js';
|
||||
@@ -1269,9 +1269,9 @@
|
||||
//预览图
|
||||
const showPrveImg = ref(false);
|
||||
const prveImgsList = ref([]);
|
||||
|
||||
function updateShowPrveImg(e){
|
||||
showPrveImg.value=e
|
||||
|
||||
function updateShowPrveImg(e) {
|
||||
showPrveImg.value = e
|
||||
}
|
||||
|
||||
function prveImgs(images) {
|
||||
@@ -1285,14 +1285,14 @@
|
||||
}
|
||||
|
||||
async function getProductImgs(item) {
|
||||
console.log('getProductImgs',item)
|
||||
console.log('getProductImgs', item)
|
||||
let res = await APIminiAppinfo(item.id);
|
||||
prveImgs(res.images);
|
||||
}
|
||||
|
||||
//获取多规格数据
|
||||
const clickspecifications = async (item, index, indexs, type) => {
|
||||
console.log('clickspecifications',item);
|
||||
console.log('clickspecifications', item);
|
||||
// 商品类型 single-单规格商品 sku-多规格商品 package-套餐商品 weight-称重商品 coupon-团购券
|
||||
// if (
|
||||
// item.isSoldStock == 1 ||
|
||||
@@ -1586,11 +1586,11 @@
|
||||
|
||||
function cartInit(arr) {
|
||||
const result = []
|
||||
console.log('cartInitArr',arr);
|
||||
console.log('allGoodsArr',allGoodsArr);
|
||||
console.log('cartInitArr', arr);
|
||||
console.log('allGoodsArr', allGoodsArr);
|
||||
cartStore.carts = arr.map(v => {
|
||||
const goods = allGoodsArr.find(g => g.id == v.product_id)
|
||||
const goodsSkuList = goods?goods.skuList : []
|
||||
const goodsSkuList = goods ? goods.skuList : []
|
||||
const findSku = goodsSkuList.find(sku => sku.id == v.sku_id)
|
||||
const memberPrice = findSku ? findSku.memberPrice : 0
|
||||
const is_time_discount = limitUtils.canUseLimitTimeDiscount({
|
||||
@@ -1598,7 +1598,7 @@
|
||||
memberPrice
|
||||
}, cartStore.limitTimeDiscount, shopInfo,
|
||||
shopUserInfo.value, 'product_id');
|
||||
if(!goods){
|
||||
if (!goods) {
|
||||
useSocket.sendMessage({
|
||||
id: v.id,
|
||||
operate_type: "del",
|
||||
@@ -1613,7 +1613,7 @@
|
||||
is_time_discount: is_time_discount ? 1 : 0,
|
||||
memberPrice
|
||||
}
|
||||
}).filter(v=>v)
|
||||
}).filter(v => v)
|
||||
|
||||
for (let cart of arr) {
|
||||
const findItem = cartStore.carts.find(v => v.id == cart.id)
|
||||
@@ -1790,7 +1790,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//除去p 每次返回都回执消息
|
||||
await websocketsendMessage({
|
||||
@@ -2084,11 +2084,11 @@
|
||||
}
|
||||
return currentTime >= startTime && currentTime <= endTime;
|
||||
});
|
||||
let allGoodsArr=[]
|
||||
let allGoodsArr = []
|
||||
// 列表请求
|
||||
const productqueryProduct = async () => {
|
||||
cartStore.goodsIsloading = false;
|
||||
allGoodsArr=[]
|
||||
allGoodsArr = []; // 确保声明过(建议用ref/let声明,避免全局隐式变量)
|
||||
try {
|
||||
shopProductList.hots = await productminiApphotsquery();
|
||||
shopProductList.productInfo = await APIgroupquery();
|
||||
@@ -2100,40 +2100,45 @@
|
||||
setTimeout(() => {
|
||||
uni.pro.switchTab('index/index');
|
||||
}, 1000);
|
||||
return; // 出错直接返回,避免后续逻辑
|
||||
}
|
||||
if (shopProductList.productInfo.length > 0 || shopProductList.hots.length > 0) {
|
||||
//TODO handle the exception
|
||||
//第一步:将所有商品的 cartNumber 初始化为 0
|
||||
shopProductList.productInfo.forEach((group) => {
|
||||
group.productList.forEach(async (product) => {
|
||||
product.cartNumber = 0;
|
||||
product.isSaleTimeshow = await isProductAvailable(product.days, product
|
||||
.startTime, product.endTime);
|
||||
|
||||
allGoodsArr.push(product)
|
||||
|
||||
if (shopProductList.productInfo.length > 0 || shopProductList.hots.length > 0) {
|
||||
// 第一步:处理productInfo(替换forEach为for...of,支持await)
|
||||
for (const group of shopProductList.productInfo) {
|
||||
for (const product of group.productList) {
|
||||
product.cartNumber = 0;
|
||||
// 等待异步函数执行完成后,再push
|
||||
product.isSaleTimeshow = await isProductAvailable(
|
||||
product.days,
|
||||
product.startTime,
|
||||
product.endTime
|
||||
);
|
||||
allGoodsArr.push(product);
|
||||
cartStore.setGoodsMap(product.id, product);
|
||||
});
|
||||
});
|
||||
shopProductList.hots.forEach(async (i) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 第二步:处理hots(同理替换forEach为for...of)
|
||||
for (const i of shopProductList.hots) {
|
||||
i.cartNumber = 0;
|
||||
i.isSaleTimeshow = await isProductAvailable(i.days, i.startTime, i.endTime);
|
||||
allGoodsArr.push(i)
|
||||
allGoodsArr.push(i);
|
||||
cartStore.setGoodsMap(i.id, i);
|
||||
});
|
||||
console.log('shopProductList', shopProductList);
|
||||
|
||||
if(cartStore.carts.length>0){
|
||||
cartInit(cartStore.carts)
|
||||
}
|
||||
|
||||
|
||||
// 此时所有异步操作完成,allGoodsArr已有数据
|
||||
console.log('allGoodsArr', allGoodsArr);
|
||||
console.log('shopProductList', shopProductList);
|
||||
|
||||
if (cartStore.carts.length > 0) {
|
||||
cartInit(cartStore.carts);
|
||||
}
|
||||
|
||||
cartStore.goodsIsloading = true;
|
||||
scrollTopSize.value = 0;
|
||||
topArr.value = [];
|
||||
// userStore.actionsAPIuser()
|
||||
// 数据可以更新
|
||||
isDataLoaded.value = true;
|
||||
// 历史订单
|
||||
Historicalorders();
|
||||
updateProductQuantities();
|
||||
} else {
|
||||
@@ -2381,7 +2386,7 @@
|
||||
tableCode: uni.cache.get('tableCode')
|
||||
});
|
||||
oldOrder.value = res;
|
||||
if (res && res.id && shopInfo.registerType == 'after'&&!e.noJump) {
|
||||
if (res && res.id && shopInfo.registerType == 'after' && !e.noJump) {
|
||||
toHistory();
|
||||
return;
|
||||
}
|
||||
@@ -2441,8 +2446,8 @@
|
||||
idKey: 'id'
|
||||
});
|
||||
}
|
||||
|
||||
function watchEmit(){
|
||||
|
||||
function watchEmit() {
|
||||
uni.$off('updateProductIndex')
|
||||
uni.$on('updateProductIndex', function(data) {
|
||||
getNewUserDiscount()
|
||||
@@ -2496,12 +2501,12 @@
|
||||
});
|
||||
if (res && typeof res == 'object') {
|
||||
newUserDiscount.value = res;
|
||||
cartStore.consumeDiscount=res
|
||||
cartStore.newUserDiscount=res.amount
|
||||
}else{
|
||||
cartStore.consumeDiscount = res
|
||||
cartStore.newUserDiscount = res.amount
|
||||
} else {
|
||||
newUserDiscount.value = null;
|
||||
cartStore.consumeDiscount={}
|
||||
cartStore.newUserDiscount=0
|
||||
cartStore.consumeDiscount = {}
|
||||
cartStore.newUserDiscount = 0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2561,8 +2566,8 @@
|
||||
return 0
|
||||
})
|
||||
const oldOrder = ref(null);
|
||||
|
||||
|
||||
|
||||
|
||||
// 限时折扣
|
||||
async function getLimitDiscount() {
|
||||
const limitRes = await limitTimeDiscountapi.getConfig({
|
||||
|
||||
Reference in New Issue
Block a user