|
@@ -109,7 +109,7 @@
|
|
|
<uni-popup ref="couponPopup" type="bottom" class="popup" background-color="#FFFFFF" >
|
|
|
<view class="popup_title">优惠券</view>
|
|
|
<view class="coupon_list">
|
|
|
- <view class="coupon_item" v-for="(item,index) in couponList" @click="checkedCoupon(index)" :key="index">
|
|
|
+ <view class="coupon_item" v-for="(item,index) in couponList" @click="checkedCoupon(index,false)" :key="index">
|
|
|
<view class="box_left">
|
|
|
<view class="rebate" v-if="item.rebate_type == 1" > ¥{{item.rebate}}</view>
|
|
|
<view class="rebate" v-if="item.rebate_type == 2" > 打 {{item.rebate}} 折</view>
|
|
@@ -347,7 +347,7 @@
|
|
|
// 如果不是0.表示两侧按钮点击,0表示输入的修改
|
|
|
if( number != 0 ) {
|
|
|
// 计算个数
|
|
|
- this.quantity = this.quantity + number;
|
|
|
+ this.quantity = parseInt(this.quantity) + parseInt(number);
|
|
|
}
|
|
|
// 如果大于库存设置为库存
|
|
|
if( this.quantity > this.productInfo.stock ) {
|
|
@@ -497,6 +497,8 @@
|
|
|
checkCoupon(){
|
|
|
// 如果存在的话
|
|
|
if( this.couponList.length ){
|
|
|
+ // 推荐使用的优惠券
|
|
|
+ let oldrebatePrice = 0.00;
|
|
|
let hasIsStd = false;
|
|
|
// 循环优惠券
|
|
|
for (let i in this.couponList) {
|
|
@@ -525,14 +527,44 @@
|
|
|
// 判断价格到不到限额
|
|
|
this.couponList[i].is_std = parseFloat(totalPrice.toFixed()) >= parseFloat(this.$decimal.mul(this.couponList[i].std_pay,1).toFixed());
|
|
|
// 如果不可用的话,该项已选择则不选
|
|
|
- if( !this.couponList[i].is_std && this.couponList[i].checked ) this.checkedCoupon(i);
|
|
|
+ if( !this.couponList[i].is_std && this.couponList[i].checked ) this.checkedCoupon(i,false);
|
|
|
+ // 如果可用的话,并且优惠券没有选中
|
|
|
+ if( this.couponList[i].is_std ){
|
|
|
+ // 优惠金额
|
|
|
+ let newRebatePrice = 0.00;
|
|
|
+ // 计算满减价格
|
|
|
+ if( this.couponList[i].rebate_type == 1 ){
|
|
|
+ // 计算扣减数据
|
|
|
+ newRebatePrice = this.$decimal.mul(this.couponList[i].rebate,1);
|
|
|
+ }
|
|
|
+ // 计算折扣价格
|
|
|
+ if( this.couponList[i].rebate_type == 2 ){
|
|
|
+ // 折扣
|
|
|
+ newRebatePrice = this.$decimal.mul(totalPrice,this.couponList[i].rebate);
|
|
|
+ // 减数
|
|
|
+ newRebatePrice = this.$decimal.sub(totalPrice,newRebatePrice.mul(0.1));
|
|
|
+ }
|
|
|
+ // 判断哪个比较优惠
|
|
|
+ if( parseFloat(oldrebatePrice.toFixed(2)) <= parseFloat(newRebatePrice.toFixed(2)) ){
|
|
|
+ // 覆盖价格
|
|
|
+ oldrebatePrice = parseFloat(newRebatePrice.toFixed(2));
|
|
|
+ // 如果选中的是自己,不需要取消
|
|
|
+ if( this.customCoupon == this.couponList[i].id && this.couponList[i].checked ){
|
|
|
+ // 选中
|
|
|
+ this.checkedCoupon(i,true);
|
|
|
+ }else{
|
|
|
+ // 选中
|
|
|
+ this.checkedCoupon(i,false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
// 选择优惠券
|
|
|
- checkedCoupon(index){
|
|
|
- // 单个设置选中/未选
|
|
|
- this.couponList[index].checked = this.couponList[index].checked ? 0 : 1;
|
|
|
+ checkedCoupon(index,save_checked=false){
|
|
|
+ // 单个设置选中/未选(如果保持选中,则不变)
|
|
|
+ this.couponList[index].checked = save_checked ? this.couponList[index].checked : (this.couponList[index].checked ? 0 : 1);
|
|
|
// 循环处理
|
|
|
for (let i in this.couponList) {
|
|
|
// 有未选的就不做全选
|