增加:商品兑换 额度区分为瓶装酒和封坛酒;商品区分瓶装酒和封坛酒

This commit is contained in:
wuhui_zzw 2024-06-04 11:58:26 +08:00
parent b0eef8c887
commit 166b0237c1
2 changed files with 182 additions and 103 deletions

View File

@ -51,18 +51,23 @@
</view> </view>
</view> </view>
<view class="buy"> <view class="buy">
<!--<view class="left" @click="changeBatchType(item.product_id)"> <!--酒类型0=未知1=瓶装酒2=封坛酒-->
<template v-if="item.is_batch == 1"> <view class="left">
<view v-if="(batch_list[item.product_id] || 0) == 1" class="buy-unit">{{ item.batch_unit }}购买</view> <view class="left-text wine-type-one" v-if="item.wine_type == 1">瓶装酒</view>
<view v-else class="buy-unit">{{ item.unit_name }}购买</view> <view class="left-text wine-type-two" v-if="item.wine_type == 2">封坛酒</view>
<text class="iconfont icon-jiantou_shangxiaqiehuan_o"></text> </view>
</template>
</view>-->
<view class="left"></view>
<view class="right"> <view class="right">
<template v-if="!buyList[item.product_id]"> <template v-if="!buyList[item.product_id]">
<text v-if="Number(surplus_available) >= (Number(item.price) * (Number(item.once_min_count) || 1))" @click="buyFlowAddBuyNum('add', item)" class="iconfont icon-gengduozhankai1"></text> <!--瓶装酒-->
<view v-else class="lack_available">额度不足</view> <template v-if="item.wine_type == 1">
<text v-if="Number(surplus_available) >= (Number(item.price) * (Number(item.once_min_count) || 1))" @click="buyFlowAddBuyNum('add', item)" class="iconfont icon-gengduozhankai1"></text>
<view v-else class="lack_available">额度不足</view>
</template>
<!--封坛酒-->
<template v-if="item.wine_type == 2">
<text v-if="Number(surplus_wine_available) >= (Number(item.price) * (Number(item.once_min_count) || 1))" @click="buyFlowAddBuyNum('add', item)" class="iconfont icon-gengduozhankai1"></text>
<view v-else class="lack_available">额度不足</view>
</template>
</template> </template>
<template v-else> <template v-else>
<view class="buy-num"> <view class="buy-num">
@ -90,18 +95,23 @@
</view> </view>
<!--结算按钮--> <!--结算按钮-->
<view class="settlement"> <view class="settlement">
<view class="left"> <view class="top">
<text class="iconfont icon-gouwuche-mendian"> <view class="left">
<text class="total-num" v-if="totalNum > 0">{{ totalNum > 99 ? '99+' : totalNum }}</text> <text class="iconfont icon-gouwuche-mendian">
</text> <text class="total-num" v-if="totalNum > 0">{{ totalNum > 99 ? '99+' : totalNum }}</text>
<view class="total"> </text>
合计<text class="total-price">{{ totalPrice }}积分</text> <view class="total">
合计<text class="total-price">{{ totalPrice }}积分</text>
</view>
</view>
<view class="right">
<view class="settlement-btn" @click="settlementCart" v-if="Object.values(buyList).length > 0">立即结算</view>
<view class="settlement-btn not-btn" v-else>立即结算</view>
</view> </view>
</view> </view>
<view class="right"> <view class="quota-info">
<view class="settlement-btn" @click="settlementCart" v-if="Object.values(buyList).length > 0">立即结算</view> <view class="available-line">可用瓶装酒额度:{{ surplus_available || 0 }}</view>
<view class="settlement-btn not-btn" v-else>立即结算</view> <view class="available-line">可用封坛酒额度:{{ surplus_wine_available || 0 }}</view>
<view class="available">剩余额度:{{ surplus_available }}</view>
</view> </view>
</view> </view>
</view> </view>
@ -277,6 +287,8 @@ export default {
userInfoNow: {}, userInfoNow: {},
available: 0, available: 0,
surplus_available: 0, surplus_available: 0,
wine_available: 0,
surplus_wine_available: 0,
} }
}, },
onLoad(options) { onLoad(options) {
@ -401,8 +413,12 @@ export default {
let _this = this; let _this = this;
getUserInfo().then(res => { getUserInfo().then(res => {
_this.$set(_this, 'userInfoNow', res.data); _this.$set(_this, 'userInfoNow', res.data);
_this.$set(_this, 'available', res.data.available)
_this.$set(_this, 'surplus_available', res.data.surplus_available) _this.$set(_this, 'available', res.data.available_quota)
_this.$set(_this, 'surplus_available', res.data.available_quota)
_this.$set(_this, 'wine_available', res.data.wine_available_quota)
_this.$set(_this, 'surplus_wine_available', res.data.wine_available_quota)
}); });
}, },
// //
@ -426,7 +442,7 @@ export default {
_this.$set(_this, 'list', oldList); _this.$set(_this, 'list', oldList);
}).catch(err => { }).catch(err => {
this.$util.Tips({title: err}); this.$util.tips({ content: err });
}); });
}, },
// //
@ -495,14 +511,7 @@ export default {
let currentNum = currentSpec.cart_num || 0; let currentNum = currentSpec.cart_num || 0;
let changeNum = Number(oldNum) - Number(currentNum); let changeNum = Number(oldNum) - Number(currentNum);
// //
if(type != 'reduce'){ if(type !== 'reduce' && this.quotaIsAdequate(changeNum, currentSpec.price)) return false;
let surplus_available = this.surplus_available || 0;
if(Number(surplus_available) < (Math.abs(Number(changeNum)) * Number(currentSpec.price))){
this.$util.Tips({ title: '额度不足!'});
this.cartGetList();
return false;
}
}
// 0 // 0
if(currentSpec.cart_num <= 0) { if(currentSpec.cart_num <= 0) {
this.cartDel(currentSpec); this.cartDel(currentSpec);
@ -512,6 +521,7 @@ export default {
// //
currentSpec.batch_num = this.currentGoods.batch_num || ''; currentSpec.batch_num = this.currentGoods.batch_num || '';
currentSpec.is_batch = this.currentGoods.is_batch || 0; currentSpec.is_batch = this.currentGoods.is_batch || 0;
this.cartSubmitEdit(currentSpec); this.cartSubmitEdit(currentSpec);
} }
// //
@ -536,6 +546,8 @@ export default {
let stock = spec.stock || 0; let stock = spec.stock || 0;
if(isBatch == 1) stock = Math.floor(stock / (this.currentGoods.batch_num || ''));// if(isBatch == 1) stock = Math.floor(stock / (this.currentGoods.batch_num || ''));//
if(Number(stock) < Number(spec.cart_num)) spec.cart_num = stock; if(Number(stock) < Number(spec.cart_num)) spec.cart_num = stock;
//
if(this.quotaIsAdequate(spec.cart_num, spec.price)) return false;
// //
this.$set(this.buyList, spec.product_id, { this.$set(this.buyList, spec.product_id, {
// //
@ -546,11 +558,11 @@ export default {
product_id: spec.product_id, product_id: spec.product_id,
total_num: spec.cart_num, total_num: spec.cart_num,
store_name: this.currentGoods.store_name, store_name: this.currentGoods.store_name,
wine_type: this.currentGoods.wine_type || 0,
specs: { specs: {
[spec.unique]: spec, [spec.unique]: spec,
}, },
}); });
// //
spec.batch_num = this.currentGoods.batch_num || ''; spec.batch_num = this.currentGoods.batch_num || '';
spec.is_batch = this.currentGoods.is_batch || 0; spec.is_batch = this.currentGoods.is_batch || 0;
@ -559,6 +571,28 @@ export default {
this.$forceUpdate(); this.$forceUpdate();
}, },
// -
quotaIsAdequate(num, price){
let wineType = this.currentGoods.wine_type || 0;
let surplus_available = 0;
let tips = '额度不足!';
// 0=1=2=
if(Number(wineType) === 1) {
surplus_available = this.surplus_available || 0;
tips = '瓶装酒额度不足!'
}
else if(Number(wineType) === 2) {
surplus_available = this.surplus_wine_available || 0;
tips = '封坛酒额度不足!'
}
//
if(Number(surplus_available) < (Math.abs(Number(num)) * Number(price))){
this.$util.tips({ content: tips });
this.cartGetList();
return true;
}
return false;
},
// - // -
closeMoreSpecsSelect(){ closeMoreSpecsSelect(){
this.$refs.moreSpecsSelect.close(); this.$refs.moreSpecsSelect.close();
@ -608,8 +642,11 @@ export default {
}, },
// - // -
BuyFlowComputeTotal(){ BuyFlowComputeTotal(){
let totalNum = 0; let totalNum = 0;//
let totalPrice = 0.00; let totalPrice = 0.00;//
let needAvailable = 0;//
let needWindAvailable = 0;//
//
Object.values(this.buyList).forEach(item => { Object.values(this.buyList).forEach(item => {
totalNum += item.total_num; totalNum += item.total_num;
Object.values(item.specs).forEach(value => { Object.values(item.specs).forEach(value => {
@ -617,6 +654,9 @@ export default {
let currentBatchType = this.batch_list[value.product_id] || 0; let currentBatchType = this.batch_list[value.product_id] || 0;
// //
if(currentBatchType == 1) price = price * item.batch_num; if(currentBatchType == 1) price = price * item.batch_num;
// 0=1=2=
if(Number(item.wine_type) === 1) needAvailable += price;
else if(Number(item.wine_type) === 2) needWindAvailable += price;
totalPrice += price; totalPrice += price;
}) })
@ -624,10 +664,14 @@ export default {
// //
this.totalNum = totalNum.toFixed(0); this.totalNum = totalNum.toFixed(0);
this.totalPrice = totalPrice.toFixed(2); this.totalPrice = totalPrice.toFixed(2);
// //
let surplusAvailable = this.available || 0; let surplusAvailable = this.available || 0;
surplusAvailable = (Number(surplusAvailable) - Number(this.totalPrice)).toFixed(2); surplusAvailable = (Number(surplusAvailable) - Number(needAvailable)).toFixed(2);
this.$set(this, 'surplus_available', surplusAvailable); this.$set(this, 'surplus_available', surplusAvailable);
//
let surplusWineAvailable = this.wine_available || 0;
surplusWineAvailable = (Number(surplusWineAvailable) - Number(needWindAvailable)).toFixed(2);
this.$set(this, 'surplus_wine_available', surplusWineAvailable);
this.$forceUpdate(); this.$forceUpdate();
}, },
@ -662,6 +706,7 @@ export default {
product_id: item.product_id, product_id: item.product_id,
total_num: item.cart_num, total_num: item.cart_num,
store_name: item.product.store_name, store_name: item.product.store_name,
wine_type: item.product.wine_type || 0,
specs: { specs: {
[item.product_attr_unique]: spec, [item.product_attr_unique]: spec,
}, },
@ -673,10 +718,11 @@ export default {
_this.buyList = Object.assign({}, buyList); _this.buyList = Object.assign({}, buyList);
_this.batch_list = Object.assign({}, batchList); _this.batch_list = Object.assign({}, batchList);
_this.forceUpdate();
_this.$forceUpdate();
} }
}).catch(err => { }).catch(err => {
_this.$util.Tips({title: err}); _this.$util.tips({ content: err});
}); });
}, },
// - // -
@ -695,7 +741,7 @@ export default {
// console.log(res) // console.log(res)
}).catch(err => { }).catch(err => {
_this.cartGetList(); _this.cartGetList();
this.$util.Tips({title: err}); _this.$util.tips({ content: err});
}); });
}, },
// - // -
@ -710,7 +756,7 @@ export default {
// console.log(res) // console.log(res)
}).catch(err => { }).catch(err => {
_this.cartGetList(); _this.cartGetList();
this.$util.Tips({title: err}); _this.$util.tips({ content: err});
}); });
}, },
// //
@ -721,7 +767,7 @@ export default {
if(res.status == 200){ if(res.status == 200){
let data = res.data || {}; let data = res.data || {};
if(Object.values(data).length <= 0){ if(Object.values(data).length <= 0){
_this.$util.Tips({title: '请选择商品!'}); _this.$util.tips({ content: '请选择商品!'});
return false; return false;
} }
// //
@ -730,7 +776,7 @@ export default {
}); });
} }
}).catch(err => { }).catch(err => {
_this.$util.Tips({title: err}); _this.$util.tips({ content: err});
}); });
}, },
// - // -
@ -821,7 +867,7 @@ export default {
this.getGoodsList( 1); this.getGoodsList( 1);
break; break;
} }
} },
}, },
// //
onReachBottom() { onReachBottom() {
@ -1004,19 +1050,12 @@ export default {
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
.left{ .left{
display: inline-flex; .left-text{}
flex-direction: row; .wine-type-one{
flex-wrap: nowrap; color: #409eff;
justify-content: flex-start;
align-items: center;
.buy-unit{
font-size: 26rpx;
} }
.icon-jiantou_shangxiaqiehuan_o{ .wine-type-two{
transform: rotate(90deg); color: #e6a23c;
font-size: 36rpx;
font-weight: bold;
margin-left: 15rpx;
} }
} }
.right{ .right{
@ -1082,67 +1121,85 @@ export default {
background: #FFFFFF; background: #FFFFFF;
padding: 20rpx 20rpx 50rpx 20rpx; padding: 20rpx 20rpx 50rpx 20rpx;
box-shadow: 0 0 10px 0 #f3f3f3; box-shadow: 0 0 10px 0 #f3f3f3;
display: inline-flex; z-index: 9;
flex-direction: row; .top{
flex-wrap: nowrap; width: 100%;
justify-content: space-between;
align-items: center;
.left{
display: inline-flex; display: inline-flex;
flex-direction: row; flex-direction: row;
flex-wrap: nowrap; flex-wrap: nowrap;
justify-content: flex-start; justify-content: space-between;
align-items: center; align-items: center;
.icon-gouwuche-mendian{ .left{
font-size: 30rpx; display: inline-flex;
margin-right: 20rpx; flex-direction: row;
border: 2rpx solid #000000; flex-wrap: nowrap;
border-radius: 50%; justify-content: flex-start;
padding: 15rpx; align-items: center;
position: relative; .icon-gouwuche-mendian{
.total-num{ font-size: 30rpx;
position: absolute; margin-right: 20rpx;
top: -5px; border: 2rpx solid #000000;
right: -5px;
font-size: 20rpx;
background: #ef2c1c;
color: #ffffff;
border-radius: 50%; border-radius: 50%;
width: 35rpx; padding: 15rpx;
height: 35rpx; position: relative;
text-align: center; .total-num{
line-height: 35rpx; position: absolute;
top: -5px;
right: -5px;
font-size: 20rpx;
background: #ef2c1c;
color: #ffffff;
border-radius: 50%;
width: 35rpx;
height: 35rpx;
text-align: center;
line-height: 35rpx;
}
}
.total{
font-size: 30rpx;
.total-price{
font-weight: bold;
color: #ef2c1c;
}
} }
} }
.total{ .right{
font-size: 30rpx; .available{
.total-price{ font-size: 24rpx;
font-weight: bold; color: #828282;
color: #ef2c1c; height: 40rpx;
line-height: 50rpx;
}
.settlement-btn{
background: #ef2c1c;
color: #FFFFFF;
height: 55rpx;
line-height: 55rpx;
width: 200rpx;
text-align: center;
border-radius: 100rpx;
}
.not-btn{
background-color: #909399!important;
border-color: #909399!important;
color: #fff!important;
} }
} }
} }
.right{ .quota-info{
.available{ width: 100%;
display: inline-flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content: space-between;
align-items: center;
.available-line{
font-size: 24rpx; font-size: 24rpx;
color: #828282; color: #828282;
height: 40rpx; height: 40rpx;
line-height: 50rpx; line-height: 50rpx;
} }
.settlement-btn{
background: #ef2c1c;
color: #FFFFFF;
height: 55rpx;
line-height: 55rpx;
width: 200rpx;
text-align: center;
border-radius: 100rpx;
}
.not-btn{
background-color: #909399!important;
border-color: #909399!important;
color: #fff!important;
}
} }
} }
} }

View File

@ -26,6 +26,7 @@ export default {
return obj; return obj;
}, },
/** /**
* 提示信息 微提示
* opt object | string * opt object | string
* to_url object | string * to_url object | string
* : * :
@ -119,6 +120,26 @@ export default {
} }
} }
}, },
// 提示信息 确认弹框
tips(config, confirmFun, confirmData) {
uni.showModal({
title: config.title || '提示',// 弹框标题
content: config.content || '',// 提示
confirmText: config.confirmText || '关闭',// 确认按钮文字
editable: config.editable || false,//是否显示输入框
placeholderText: config.placeholderText || '请输入内容',//输入框提示内容
showCancel: config.showCancel || false, // 是否显示取消按钮
cancelText: '取消', // 取消按钮文字
success(res) {
if (res.confirm) {
// console.log('点击确认按钮')
if(typeof confirmFun === "function") confirmFun(confirmData);
} else {
// console.log('点击关闭按钮')
}
}
})
},
/** /**
* 移除数组中的某个数组并组成新的数组返回 * 移除数组中的某个数组并组成新的数组返回
* @param array array 需要移除的数组 * @param array array 需要移除的数组
@ -849,14 +870,15 @@ export default {
// 获取地理位置; // 获取地理位置;
$L: { $L: {
async getLocation() { async getLocation() {
let status = 0;
// #ifdef APP-PLUS // #ifdef APP-PLUS
let status = await this.checkPermission(); status = await this.checkPermission();
if (status !== 1) { if (status !== 1) {
return; return;
} }
// #endif // #endif
// #ifdef MP-WEIXIN || MP-TOUTIAO || MP-QQ // #ifdef MP-WEIXIN || MP-TOUTIAO || MP-QQ
let status = await this.getSetting(); status = await this.getSetting();
if (status === 2) { if (status === 2) {
this.openSetting(); this.openSetting();
return; return;