Commit 2a2df7caf7ff3d676563df155671dc4ee0af551c

Authored by vking
1 parent cdbd0de1

商家红包活动

... ... @@ -15,19 +15,11 @@ Component({
data: {
checkedNum:0,
display:false,
checkoutObj:null,
},
observers: {
'checkout': function(checkout) {
if(!checkout) return;
let num=0;
checkout.discount.forEach(q=>{
if(q.checked){
num++;
}
})
this.setData({
checkedNum:num,
})
this.discountFormat(checkout)
}
},
/**
... ... @@ -44,27 +36,36 @@ Component({
display:false,
})
},
discountFormat(checkout){
if(!checkout) return;
let num=0;
let disObj={}
let subsidy_price=0;
checkout.discount.forEach(q=>{
checkout.disabled=false
if(q.checked){
num++;
disObj[q.owner+'-'+q.receive_condition]=true
subsidy_price+=q.price/1
}
})
checkout.discount.forEach(q=>{
if(!q.checked && disObj[q.owner+'-'+q.receive_condition]){
checkout.disabled=true
}
})
checkout.subsidy_price=subsidy_price
this.setData({
checkedNum:num,
checkoutObj:checkout
})
},
discountChecked(e){
console.log('discountChecked',e)
let index=util.attr(e,'index')
let discount=this.data.checkout.discount
let checked=discount[index].checked
discount[index].checked=!discount[index].checked
if(checked) {
let subsidy_price=(this.data.checkout.subsidy_price/1 - discount[index].price/1).toFixed(2)
this.setData({
[`checkout.subsidy_price`]: subsidy_price,
[`checkout.discount`]: discount,
checkedNum:this.data.checkedNum-1,
})
}else{
let subsidy_price=(this.data.checkout.subsidy_price/1 + discount[index].price/1).toFixed(2)
this.setData({
[`checkout.subsidy_price`]: subsidy_price,
[`checkout.discount`]: discount,
checkedNum:this.data.checkedNum+1,
})
}
let checkout=this.data.checkout
checkout.discount[index].checked=!checkout.discount[index].checked
this.discountFormat(checkout)
},
}
})
... ...
... ... @@ -9,10 +9,10 @@
<view class="tips">红包均为一次使用,不找零、不兑现,每次买单抵扣不超过消费总额</view>
<view class="content">
<view class="msg flex-ll">
你选中了<text class="light">{{checkedNum}}</text>个红包,共可抵扣<text class="light">¥{{checkout.subsidy_price}}</text>
你选中了<text class="light">{{checkedNum}}</text>个红包,共可抵扣<text class="light">¥{{checkoutObj.subsidy_price}}</text>
</view>
<view class="list">
<view class="quan" wx:for="{{checkout.discount}}" wx:key="discount">
<view class="quan" wx:for="{{checkoutObj.discount}}" wx:key="discount">
<quan quan="{{item}}">
<radio data-index="{{index}}" checked="{{item.checked}}" color="#F05522" bindtap="discountChecked"/>
</quan>
... ...
... ... @@ -78,6 +78,15 @@ Page({
this.GetOrderInfoRun()
}
}
if(checkout.discount.length>0){
let subsidy_price=0
checkout.discount.forEach(q=>{
if(q.checked){
subsidy_price+=q.price/1
}
})
checkout.subsidy_price=subsidy_price.toFixed(2)
}
this.setData({
checkout:checkout,
hasLoading:false,
... ...