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