增加:商品兑换 额度区分为瓶装酒和封坛酒;商品区分瓶装酒和封坛酒
This commit is contained in:
parent
b0eef8c887
commit
166b0237c1
|
|
@ -51,18 +51,23 @@
|
|||
</view>
|
||||
</view>
|
||||
<view class="buy">
|
||||
<!--<view class="left" @click="changeBatchType(item.product_id)">
|
||||
<template v-if="item.is_batch == 1">
|
||||
<view v-if="(batch_list[item.product_id] || 0) == 1" class="buy-unit">按{{ item.batch_unit }}购买</view>
|
||||
<view v-else class="buy-unit">按{{ item.unit_name }}购买</view>
|
||||
<text class="iconfont icon-jiantou_shangxiaqiehuan_o"></text>
|
||||
</template>
|
||||
</view>-->
|
||||
<view class="left"></view>
|
||||
<!--酒类型:0=未知,1=瓶装酒,2=封坛酒-->
|
||||
<view class="left">
|
||||
<view class="left-text wine-type-one" v-if="item.wine_type == 1">瓶装酒</view>
|
||||
<view class="left-text wine-type-two" v-if="item.wine_type == 2">封坛酒</view>
|
||||
</view>
|
||||
<view class="right">
|
||||
<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 v-else>
|
||||
<view class="buy-num">
|
||||
|
|
@ -90,18 +95,23 @@
|
|||
</view>
|
||||
<!--结算按钮-->
|
||||
<view class="settlement">
|
||||
<view class="left">
|
||||
<text class="iconfont icon-gouwuche-mendian">
|
||||
<text class="total-num" v-if="totalNum > 0">{{ totalNum > 99 ? '99+' : totalNum }}</text>
|
||||
</text>
|
||||
<view class="total">
|
||||
合计:<text class="total-price">{{ totalPrice }}积分</text>
|
||||
<view class="top">
|
||||
<view class="left">
|
||||
<text class="iconfont icon-gouwuche-mendian">
|
||||
<text class="total-num" v-if="totalNum > 0">{{ totalNum > 99 ? '99+' : totalNum }}</text>
|
||||
</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 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 class="available">剩余额度:{{ surplus_available }}</view>
|
||||
<view class="quota-info">
|
||||
<view class="available-line">可用瓶装酒额度:{{ surplus_available || 0 }}</view>
|
||||
<view class="available-line">可用封坛酒额度:{{ surplus_wine_available || 0 }}</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
|
@ -277,6 +287,8 @@ export default {
|
|||
userInfoNow: {},
|
||||
available: 0,
|
||||
surplus_available: 0,
|
||||
wine_available: 0,
|
||||
surplus_wine_available: 0,
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
|
|
@ -401,8 +413,12 @@ export default {
|
|||
let _this = this;
|
||||
getUserInfo().then(res => {
|
||||
_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);
|
||||
}).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 changeNum = Number(oldNum) - Number(currentNum);
|
||||
// 判断:额度 是否充足
|
||||
if(type != 'reduce'){
|
||||
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;
|
||||
}
|
||||
}
|
||||
if(type !== 'reduce' && this.quotaIsAdequate(changeNum, currentSpec.price)) return false;
|
||||
// 判断:购买数量是否已经为0 是则删除
|
||||
if(currentSpec.cart_num <= 0) {
|
||||
this.cartDel(currentSpec);
|
||||
|
|
@ -512,6 +521,7 @@ export default {
|
|||
// 增加购物车信息 存在即修改
|
||||
currentSpec.batch_num = this.currentGoods.batch_num || '';
|
||||
currentSpec.is_batch = this.currentGoods.is_batch || 0;
|
||||
|
||||
this.cartSubmitEdit(currentSpec);
|
||||
}
|
||||
// 判断:当前商品不存在任何购买规格
|
||||
|
|
@ -536,6 +546,8 @@ export default {
|
|||
let stock = spec.stock || 0;
|
||||
if(isBatch == 1) stock = Math.floor(stock / (this.currentGoods.batch_num || ''));//批量购买时 库存需要除以每批数量
|
||||
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, {
|
||||
// 购买单位类型
|
||||
|
|
@ -546,11 +558,11 @@ export default {
|
|||
product_id: spec.product_id,
|
||||
total_num: spec.cart_num,
|
||||
store_name: this.currentGoods.store_name,
|
||||
wine_type: this.currentGoods.wine_type || 0,
|
||||
specs: {
|
||||
[spec.unique]: spec,
|
||||
},
|
||||
});
|
||||
|
||||
// 增加购物车信息
|
||||
spec.batch_num = this.currentGoods.batch_num || '';
|
||||
spec.is_batch = this.currentGoods.is_batch || 0;
|
||||
|
|
@ -559,6 +571,28 @@ export default {
|
|||
|
||||
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(){
|
||||
this.$refs.moreSpecsSelect.close();
|
||||
|
|
@ -608,8 +642,11 @@ export default {
|
|||
},
|
||||
// 购买流程 - 计算总价值和总数量
|
||||
BuyFlowComputeTotal(){
|
||||
let totalNum = 0;
|
||||
let totalPrice = 0.00;
|
||||
let totalNum = 0;// 总数量
|
||||
let totalPrice = 0.00;// 总价值
|
||||
let needAvailable = 0;// 需要的瓶装酒额度
|
||||
let needWindAvailable = 0;// 需要的封坛酒额度
|
||||
// 循环处理
|
||||
Object.values(this.buyList).forEach(item => {
|
||||
totalNum += item.total_num;
|
||||
Object.values(item.specs).forEach(value => {
|
||||
|
|
@ -617,6 +654,9 @@ export default {
|
|||
let currentBatchType = this.batch_list[value.product_id] || 0;
|
||||
// 判断:如果是批量购买 当前价格需要乘以每批的数量
|
||||
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;
|
||||
})
|
||||
|
|
@ -624,10 +664,14 @@ export default {
|
|||
// 赋值
|
||||
this.totalNum = totalNum.toFixed(0);
|
||||
this.totalPrice = totalPrice.toFixed(2);
|
||||
// 计算剩余额度
|
||||
// 计算剩余瓶装酒额度
|
||||
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);
|
||||
// 计算剩余封坛酒额度
|
||||
let surplusWineAvailable = this.wine_available || 0;
|
||||
surplusWineAvailable = (Number(surplusWineAvailable) - Number(needWindAvailable)).toFixed(2);
|
||||
this.$set(this, 'surplus_wine_available', surplusWineAvailable);
|
||||
|
||||
this.$forceUpdate();
|
||||
},
|
||||
|
|
@ -662,6 +706,7 @@ export default {
|
|||
product_id: item.product_id,
|
||||
total_num: item.cart_num,
|
||||
store_name: item.product.store_name,
|
||||
wine_type: item.product.wine_type || 0,
|
||||
specs: {
|
||||
[item.product_attr_unique]: spec,
|
||||
},
|
||||
|
|
@ -673,10 +718,11 @@ export default {
|
|||
|
||||
_this.buyList = Object.assign({}, buyList);
|
||||
_this.batch_list = Object.assign({}, batchList);
|
||||
_this.forceUpdate();
|
||||
|
||||
_this.$forceUpdate();
|
||||
}
|
||||
}).catch(err => {
|
||||
_this.$util.Tips({title: err});
|
||||
_this.$util.tips({ content: err});
|
||||
});
|
||||
},
|
||||
// 购物车 - 提交购物车
|
||||
|
|
@ -695,7 +741,7 @@ export default {
|
|||
// console.log(res)
|
||||
}).catch(err => {
|
||||
_this.cartGetList();
|
||||
this.$util.Tips({title: err});
|
||||
_this.$util.tips({ content: err});
|
||||
});
|
||||
},
|
||||
// 购物车 - 删除购物车商品信息
|
||||
|
|
@ -710,7 +756,7 @@ export default {
|
|||
// console.log(res)
|
||||
}).catch(err => {
|
||||
_this.cartGetList();
|
||||
this.$util.Tips({title: err});
|
||||
_this.$util.tips({ content: err});
|
||||
});
|
||||
},
|
||||
// 立即结算
|
||||
|
|
@ -721,7 +767,7 @@ export default {
|
|||
if(res.status == 200){
|
||||
let data = res.data || {};
|
||||
if(Object.values(data).length <= 0){
|
||||
_this.$util.Tips({title: '请选择商品!'});
|
||||
_this.$util.tips({ content: '请选择商品!'});
|
||||
return false;
|
||||
}
|
||||
// 去结算
|
||||
|
|
@ -730,7 +776,7 @@ export default {
|
|||
});
|
||||
}
|
||||
}).catch(err => {
|
||||
_this.$util.Tips({title: err});
|
||||
_this.$util.tips({ content: err});
|
||||
});
|
||||
},
|
||||
// 搜索 - 获取品牌列表
|
||||
|
|
@ -821,7 +867,7 @@ export default {
|
|||
this.getGoodsList( 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
// 滚动到底部
|
||||
onReachBottom() {
|
||||
|
|
@ -1004,19 +1050,12 @@ export default {
|
|||
justify-content: space-between;
|
||||
align-items: center;
|
||||
.left{
|
||||
display: inline-flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
.buy-unit{
|
||||
font-size: 26rpx;
|
||||
.left-text{}
|
||||
.wine-type-one{
|
||||
color: #409eff;
|
||||
}
|
||||
.icon-jiantou_shangxiaqiehuan_o{
|
||||
transform: rotate(90deg);
|
||||
font-size: 36rpx;
|
||||
font-weight: bold;
|
||||
margin-left: 15rpx;
|
||||
.wine-type-two{
|
||||
color: #e6a23c;
|
||||
}
|
||||
}
|
||||
.right{
|
||||
|
|
@ -1082,67 +1121,85 @@ export default {
|
|||
background: #FFFFFF;
|
||||
padding: 20rpx 20rpx 50rpx 20rpx;
|
||||
box-shadow: 0 0 10px 0 #f3f3f3;
|
||||
display: inline-flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
.left{
|
||||
z-index: 9;
|
||||
.top{
|
||||
width: 100%;
|
||||
display: inline-flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: flex-start;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
.icon-gouwuche-mendian{
|
||||
font-size: 30rpx;
|
||||
margin-right: 20rpx;
|
||||
border: 2rpx solid #000000;
|
||||
border-radius: 50%;
|
||||
padding: 15rpx;
|
||||
position: relative;
|
||||
.total-num{
|
||||
position: absolute;
|
||||
top: -5px;
|
||||
right: -5px;
|
||||
font-size: 20rpx;
|
||||
background: #ef2c1c;
|
||||
color: #ffffff;
|
||||
.left{
|
||||
display: inline-flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
.icon-gouwuche-mendian{
|
||||
font-size: 30rpx;
|
||||
margin-right: 20rpx;
|
||||
border: 2rpx solid #000000;
|
||||
border-radius: 50%;
|
||||
width: 35rpx;
|
||||
height: 35rpx;
|
||||
text-align: center;
|
||||
line-height: 35rpx;
|
||||
padding: 15rpx;
|
||||
position: relative;
|
||||
.total-num{
|
||||
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{
|
||||
font-size: 30rpx;
|
||||
.total-price{
|
||||
font-weight: bold;
|
||||
color: #ef2c1c;
|
||||
.right{
|
||||
.available{
|
||||
font-size: 24rpx;
|
||||
color: #828282;
|
||||
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{
|
||||
.available{
|
||||
.quota-info{
|
||||
width: 100%;
|
||||
display: inline-flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: nowrap;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
.available-line{
|
||||
font-size: 24rpx;
|
||||
color: #828282;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ export default {
|
|||
return obj;
|
||||
},
|
||||
/**
|
||||
* 提示信息 微提示
|
||||
* opt 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 需要移除的数组
|
||||
|
|
@ -849,14 +870,15 @@ export default {
|
|||
// 获取地理位置;
|
||||
$L: {
|
||||
async getLocation() {
|
||||
let status = 0;
|
||||
// #ifdef APP-PLUS
|
||||
let status = await this.checkPermission();
|
||||
status = await this.checkPermission();
|
||||
if (status !== 1) {
|
||||
return;
|
||||
}
|
||||
// #endif
|
||||
// #ifdef MP-WEIXIN || MP-TOUTIAO || MP-QQ
|
||||
let status = await this.getSetting();
|
||||
status = await this.getSetting();
|
||||
if (status === 2) {
|
||||
this.openSetting();
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in New Issue