This commit is contained in:
shijing 2022-02-10 09:20:43 +08:00
parent 119d92ea09
commit dce7d15ab1
1 changed files with 24 additions and 34 deletions

View File

@ -46,7 +46,8 @@
</view>
<view class="btn">
<view class="joinCart" @tap="joinCart">加入购物车</view>
<view class="buy" @tap="buy">立即购买</view>
<view v-if="good.num>0" class="buy" @tap="buy">立即购买</view>
<view v-else class="buy">库存不足</view>
</view>
</view>
<!-- share弹窗 -->
@ -102,16 +103,12 @@
</view>
</view>
</view>
<!-- 规格-模态层弹窗 -->
<!-- 立即购买-模态层弹窗 -->
<view class="popup spec" :class="specClass" @touchmove.stop.prevent="discard" @tap="hideSpec">
<!-- 遮罩层 -->
<view class="mask"></view>
<view class="layer" @tap.stop="discard">
<view class="content">
<!-- <view class="title">选择规格</view>
<view class="sp">
<view v-for="(item,index) in goodsData.spec" :class="[index==selectSpec?'on':'']" @tap="setSelectSpec(index)" :key="index">{{item}}</view>
</view> -->
<view class="length">
<view class="text">数量</view>
<view class="number">
@ -336,12 +333,11 @@
methods: {
getGood(id) {
this.$u.api.getGood(id).then(res => {
let good = res.data
let good = res.data;
good._num = 1;//
if (good.content) {
good.content = richTextUtil.formatRichText(good.content);
good._num = 1;//
}
// console.log(good)
this.good = good
})
},
@ -399,13 +395,6 @@
buy() {
this.action = 'buy';
this.specClass = 'show'
// this.showSpec()
// if(this.selectSpec==null){
// return this.showSpec(()=>{
// this.toConfirmation();
// });
// }
// this.toConfirmation();
},
//
toRatings() {
@ -524,24 +513,25 @@
},
//
confirm() {
this.specClass = 'none';
//
// this.selectSpec&&this.specCallback&&this.specCallback();
// this.specCallback = false;
// setTimeout(() => {
// this.specClass = 'none';
// }, 200);
if (this.action == 'buy') {
this.toConfirmation()
} else {
this.$u.api.addtoCart(this.good.id, this.good._num).then(res => {
uni.showToast({
title: "已加入购物车"
});
})
debugger;
let num = parseInt(this.good._num);
if(num>this.good.num){
uni.showToast({
icon:'error',
title: "库存不足!"
});
}else{
this.specClass = 'none';
if (this.action == 'buy') {
this.toConfirmation()
} else {
this.$u.api.addtoCart(this.good.id, this.good._num).then(res => {
uni.showToast({
title: "已加入购物车"
});
})
}
}
},
discard() {