Commit 2a2df7caf7ff3d676563df155671dc4ee0af551c

Authored by vking
1 parent cdbd0de1

商家红包活动

@@ -15,19 +15,11 @@ Component({ @@ -15,19 +15,11 @@ Component({
15 data: { 15 data: {
16 checkedNum:0, 16 checkedNum:0,
17 display:false, 17 display:false,
  18 + checkoutObj:null,
18 }, 19 },
19 observers: { 20 observers: {
20 'checkout': function(checkout) { 21 'checkout': function(checkout) {
21 - if(!checkout) return;  
22 - let num=0;  
23 - checkout.discount.forEach(q=>{  
24 - if(q.checked){  
25 - num++;  
26 - }  
27 - })  
28 - this.setData({  
29 - checkedNum:num,  
30 - }) 22 + this.discountFormat(checkout)
31 } 23 }
32 }, 24 },
33 /** 25 /**
@@ -44,27 +36,36 @@ Component({ @@ -44,27 +36,36 @@ Component({
44 display:false, 36 display:false,
45 }) 37 })
46 }, 38 },
  39 + discountFormat(checkout){
  40 + if(!checkout) return;
  41 + let num=0;
  42 + let disObj={}
  43 + let subsidy_price=0;
  44 + checkout.discount.forEach(q=>{
  45 + checkout.disabled=false
  46 + if(q.checked){
  47 + num++;
  48 + disObj[q.owner+'-'+q.receive_condition]=true
  49 + subsidy_price+=q.price/1
  50 + }
  51 + })
  52 + checkout.discount.forEach(q=>{
  53 + if(!q.checked && disObj[q.owner+'-'+q.receive_condition]){
  54 + checkout.disabled=true
  55 + }
  56 + })
  57 + checkout.subsidy_price=subsidy_price
  58 + this.setData({
  59 + checkedNum:num,
  60 + checkoutObj:checkout
  61 + })
  62 + },
47 discountChecked(e){ 63 discountChecked(e){
48 console.log('discountChecked',e) 64 console.log('discountChecked',e)
49 let index=util.attr(e,'index') 65 let index=util.attr(e,'index')
50 - let discount=this.data.checkout.discount  
51 - let checked=discount[index].checked  
52 - discount[index].checked=!discount[index].checked  
53 - if(checked) {  
54 - let subsidy_price=(this.data.checkout.subsidy_price/1 - discount[index].price/1).toFixed(2)  
55 - this.setData({  
56 - [`checkout.subsidy_price`]: subsidy_price,  
57 - [`checkout.discount`]: discount,  
58 - checkedNum:this.data.checkedNum-1,  
59 - })  
60 - }else{  
61 - let subsidy_price=(this.data.checkout.subsidy_price/1 + discount[index].price/1).toFixed(2)  
62 - this.setData({  
63 - [`checkout.subsidy_price`]: subsidy_price,  
64 - [`checkout.discount`]: discount,  
65 - checkedNum:this.data.checkedNum+1,  
66 - })  
67 - } 66 + let checkout=this.data.checkout
  67 + checkout.discount[index].checked=!checkout.discount[index].checked
  68 + this.discountFormat(checkout)
68 }, 69 },
69 } 70 }
70 }) 71 })
@@ -9,10 +9,10 @@ @@ -9,10 +9,10 @@
9 <view class="tips">红包均为一次使用,不找零、不兑现,每次买单抵扣不超过消费总额</view> 9 <view class="tips">红包均为一次使用,不找零、不兑现,每次买单抵扣不超过消费总额</view>
10 <view class="content"> 10 <view class="content">
11 <view class="msg flex-ll"> 11 <view class="msg flex-ll">
12 - 你选中了<text class="light">{{checkedNum}}</text>个红包,共可抵扣<text class="light">¥{{checkout.subsidy_price}}</text> 12 + 你选中了<text class="light">{{checkedNum}}</text>个红包,共可抵扣<text class="light">¥{{checkoutObj.subsidy_price}}</text>
13 </view> 13 </view>
14 <view class="list"> 14 <view class="list">
15 - <view class="quan" wx:for="{{checkout.discount}}" wx:key="discount"> 15 + <view class="quan" wx:for="{{checkoutObj.discount}}" wx:key="discount">
16 <quan quan="{{item}}"> 16 <quan quan="{{item}}">
17 <radio data-index="{{index}}" checked="{{item.checked}}" color="#F05522" bindtap="discountChecked"/> 17 <radio data-index="{{index}}" checked="{{item.checked}}" color="#F05522" bindtap="discountChecked"/>
18 </quan> 18 </quan>
@@ -78,6 +78,15 @@ Page({ @@ -78,6 +78,15 @@ Page({
78 this.GetOrderInfoRun() 78 this.GetOrderInfoRun()
79 } 79 }
80 } 80 }
  81 + if(checkout.discount.length>0){
  82 + let subsidy_price=0
  83 + checkout.discount.forEach(q=>{
  84 + if(q.checked){
  85 + subsidy_price+=q.price/1
  86 + }
  87 + })
  88 + checkout.subsidy_price=subsidy_price.toFixed(2)
  89 + }
81 this.setData({ 90 this.setData({
82 checkout:checkout, 91 checkout:checkout,
83 hasLoading:false, 92 hasLoading:false,