Commit 2837aad0 by songbingqi

修复部分bug

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