Commit 2837aad0 by songbingqi

修复部分bug

parent 34c2268d
......@@ -40,6 +40,7 @@
</view>
</view>
</scroll-view>
<show-toast ref="toast"/>
</view>
</template>
......@@ -133,10 +134,20 @@ export default {
});
},
cart: (item, category) => {
cart(item, category){
console.log(item)
const skuStatus = item.skus.filter(item=>{return Number(item.state)===1})
if(skuStatus.length===0){
this.showToast({
title: '该商品已售罄',
icon: 'none',
})
}else{
uni.setStorageSync('goodsInfo', JSON.stringify({ ...item, category }));
uni.navigateTo({ url: '/menuSubPackage/pages/goodsDetail/goodsDetail' })
}
}
}
}
</script>
......@@ -553,6 +564,10 @@ export default {
}
.box:last-child{
padding-bottom: 590rpx;
}
.nav-right-item image {
width: 150rpx;
height: 150rpx;
......
......@@ -86,6 +86,7 @@
<script>
import Utils from '@/utils/utils'
import User from '@/request/user';
import Order from '@/request/order'
export default {
data() {
return {
......@@ -251,24 +252,36 @@ export default {
this.size = size - 1;
}
},
shoppingCart() {
async shoppingCart() {
if(this.checkNum('addShop')){
const { goods } = this;
const { data } = await Order.checkSku({skuId:goods.skuId})
if(data.data&&data.data.state===2){
this.showToast({ title: '本商品已经售罄', icon: 'none' });
return;
}else{
goods.num = this.size;
Utils.getallNum(goods)
uni.switchTab({ url: '/pages/menu/menu' })
}
}
},
getallNum(e) {
async getallNum(e) {
let Authorization = uni.getStorageSync('Authorization');
if (!Authorization) {
this.loginByPhoneNumber(e);
return
}
const { goods } = this;
const { data } = await Order.checkSku({skuId:goods.skuId})
if(data.data&&data.data.state===2){
this.showToast({ title: '本商品已经售罄', icon: 'none' });
return;
}else{
goods.num = this.size
Utils.addGoods(goods)
uni.navigateTo({ url: `/orderSubPackage/pages/settlement/index?buyType=1&goodsList=1` })
}
},
// 付款前未登录发起授权
loginByPhoneNumber(e) {
......
......@@ -106,7 +106,7 @@
</view>
</button>
</div>
<show-toast ref="toast"/>
</div>
</template>
......@@ -154,13 +154,25 @@ export default {
orderDetails[item.skuId] = item.num
})
const { data } = await Order.moreOrder({ orderId: id, shopId });
if(!data || !data.data){
this.showToast({ title: "该订单中的商品已经售罄了" });
return;
}
let list = new Array();
data.data.forEach(item => {
const skuId = item.skus[0].skuId
const nextData = { ...item, skuId, num: orderDetails[skuId], flag: true, sku: item.skus[0] }
if (nextData.sku.state == 1) {
Utils.getallNum(nextData)
list.push(nextData);
}
});
if(!list || list.length<=0) {
this.showToast({ title: "该订单中的商品已经售罄了", icon: 'error' });
return;
}
list.forEach(nextData => {
Utils.getallNum(nextData);
})
uni.switchTab({ url: '/pages/menu/menu' })
},
async PayNow() {
......
......@@ -116,17 +116,7 @@ export default {
this.$refs.shopbar.showShopCar = false;
},
async onShow() {
if (!this.userms) return;
const res = await Order.getHomeOrder()
const data = res?.data
if (data?.data) {
// this.$set(data.data, 'state', '2');
// console.log("getHomeOrder:"+JSON.stringify(data.data));
this.buied = true;
this.orderInfo = data.data
} else {
this.buied = false
}
},
methods: {
getShopMenus(params) {
......@@ -139,10 +129,25 @@ export default {
$EventBus.$emit('updateCar');
}
this.shopInfo = data;
uni.setStorageSync("shopInfo",JSON.stringify(this.shopInfo))
this.getMenuList(data.id);
this.getHomeOrder(data.id)
});
User.getShopInfo(params);
},
async getHomeOrder(id){
if (!this.userms) return;
const res = await Order.getHomeOrder({shopId:id})
const data = res?.data
if (data?.data) {
// this.$set(data.data, 'state', '2');
// console.log("getHomeOrder:"+JSON.stringify(data.data));
this.buied = true;
this.orderInfo = data.data
} else {
this.buied = false
}
},
openQrcode() {
// 不生成二维码
if(['2', '3'].indexOf(this.orderInfo.state) != -1){
......@@ -256,13 +261,17 @@ export default {
}
},
// 加入购物车数据
getallNum(item, category) {
async getallNum(item, category) {
let itemCopy = JSON.parse(JSON.stringify(item));
const sku = itemCopy.skus.find(v => v.isDefault == 1 && v.state != 2) || itemCopy.skus.find(v => v.isDefault == 0 && v.state != 2);
if (!sku) {
const {data} = await Order.checkSku({skuId:sku.skuId})
if(data.data&&data.data.state===2){
this.showToast({ title: '本商品已经售罄', icon: 'none' });
return;
} else {
}else{
if(sku.isDefault != 1){
this.showToast({ title: '默认规格已售罄,已添加其他规格', icon: 'none' });
}
itemCopy.skus = [sku];
itemCopy.sku = sku
itemCopy.skuId = sku?.skuId
......@@ -272,6 +281,23 @@ export default {
itemCopy.goodsName = category.name;
Utils.getallNum(itemCopy);
}
return
// if (!sku) {
// this.showToast({ title: '本商品已经售罄', icon: 'none' });
// return;
// } else {
// if(sku.isDefault != 1){
// this.showToast({ title: '默认规格已售罄,已添加其他规格', icon: 'none' });
// }
// itemCopy.skus = [sku];
// itemCopy.sku = sku
// itemCopy.skuId = sku?.skuId
// itemCopy.num = 1;
// itemCopy.flag = true;
// itemCopy.categoryId = category.id;
// itemCopy.goodsName = category.name;
// Utils.getallNum(itemCopy);
// }
},
goToMyPage(logined) {
logined && uni.switchTab({ url: '/pages/mine/mine' })
......
......@@ -258,6 +258,7 @@ export default {
}
.empty_button::after{
border-radius: 0rpx;
border: 0rpx;
}
}
......
......@@ -67,7 +67,7 @@ export default {
},
getHomeOrder(params) {
return uni.$u.http
.get('/app/getHomeOrder', {
.get(`/app/getHomeOrder?shopId=${params.shopId}`, {
params: {},
})
.then((res) => res)
......@@ -96,4 +96,14 @@ export default {
console.log('服务器错误');
});
},
checkSku(params) {
const shopInfo = JSON.parse(uni.getStorageSync('shopInfo'))
return uni.$u.http
.get(`/application/checkSku?shopId=${shopInfo.id}&skuId=${params.skuId}`)
.then((res) => res)
.catch((err) => {
// uni.showToast({ title: '服务器错误', icon: 'none' })
console.log('服务器错误');
});
}
};
......@@ -167,5 +167,5 @@ export default {
}else{
return val.toFixed(1)
}
}
},
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment