Authored by baoss

订单确认优惠券选择 review by bevishuang

@@ -128,7 +128,7 @@ @@ -128,7 +128,7 @@
128 "id": 12, 128 "id": 12,
129 "name": "商品详情线下店", 129 "name": "商品详情线下店",
130 "pathName": "pages/productDetail/index", 130 "pathName": "pages/productDetail/index",
131 - "query": "q=https%3A%2F%2Fo.yohobuy.com%2Fufo%3Fp%3D6298%2C70%26skup%3D6298%26skn%3D10001242%20", 131 + "query": "q=https://o.yohobuy.com/ufo?p=12714,94&skup=12714&skn=10000110",
132 "scene": 1011 132 "scene": 1011
133 }, 133 },
134 { 134 {
@@ -13,63 +13,73 @@ Component({ @@ -13,63 +13,73 @@ Component({
13 type: String, 13 type: String,
14 value: '', 14 value: '',
15 }, 15 },
16 - chosenIdx: {  
17 - type: String,  
18 - value: ''  
19 - }, 16 +
20 }, 17 },
21 data: { 18 data: {
22 - // chosenIdx: '' 19 + activityChosenIdx: '',
  20 + expressChosenIdx: ''
23 }, 21 },
24 methods: { 22 methods: {
25 confirm: function () { 23 confirm: function () {
26 - let item = this.data.coupons[this.data.chosenIdx];  
27 - let codeType = item && item.coupon_type|| '';  
28 - let code = item && item.coupon_code || '';  
29 - let amount = item && item.coupon_value_str || '';  
30 - this.triggerEvent('confirmselect', { code, amount, codeType}) 24 + let chosenIdxName = ['activityChosenIdx','expressChosenIdx'];
  25 + let code = [];
  26 + let amount = 0;
  27 + chosenIdxName.forEach(val => {
  28 + let item = this.data.coupons[this.data[val]];
  29 + let itemCode = item && item.coupon_code || '';
  30 + let itemAmount = item && item.coupon_value_str || '';
  31 + code.push(itemCode);
  32 + amount = itemAmount && parseFloat(itemAmount) + amount;
  33 + })
  34 + code = code.join(',');
  35 + this.triggerEvent('confirmselect', { code, amount})
31 }, 36 },
32 cancel: function () { 37 cancel: function () {
33 this.triggerEvent('cancel') 38 this.triggerEvent('cancel')
34 }, 39 },
35 check: function (e) { 40 check: function (e) {
36 let idx = e.currentTarget.dataset.idx; 41 let idx = e.currentTarget.dataset.idx;
37 - let that = this; 42 + let type = e.currentTarget.dataset.type;
38 this.data.coupons.forEach((item, index) => { 43 this.data.coupons.forEach((item, index) => {
39 - let listItem = item;  
40 - if (index !== idx && item.isChosen) {  
41 - this.setData({  
42 - [`coupons[${index}].isChosen`]: false,  
43 - [`coupons[${idx}].selected`]: 'N'  
44 - });  
45 - }  
46 - if (index === idx) {  
47 - this.setData({  
48 - [`coupons[${idx}].isChosen`]: true,  
49 - [`coupons[${idx}].selected`]: 'Y'  
50 - }); 44 + if(item.coupon_type === type) {
  45 + if (index !== idx && item.isChosen) {
  46 + this.setData({
  47 + [`coupons[${index}].isChosen`]: false,
  48 + [`coupons[${idx}].selected`]: 'N'
  49 + });
  50 + }
  51 + if (index === idx) {
  52 + this.setData({
  53 + [`coupons[${idx}].isChosen`]: true,
  54 + [`coupons[${idx}].selected`]: 'Y'
  55 + });
  56 + }
51 } 57 }
  58 +
52 }); 59 });
53 - this.data.chosenIdx = idx; 60 + let idxName = type === 100 ? 'activityChosenIdx' : 'expressChosenIdx'
  61 + this.data[idxName] = idx;
54 }, 62 },
55 uncheck: function (e) { 63 uncheck: function (e) {
56 let idx = e.currentTarget.dataset.idx; 64 let idx = e.currentTarget.dataset.idx;
57 - 65 + let type = e.currentTarget.dataset.type;
58 this.setData({ 66 this.setData({
59 [`coupons[${idx}].isChosen`]: false, 67 [`coupons[${idx}].isChosen`]: false,
60 [`coupons[${idx}].selected`]: 'N' 68 [`coupons[${idx}].selected`]: 'N'
61 }); 69 });
62 - this.data.chosenIdx = ''; 70 + let idxName = type === 100 ? 'activityChosenIdx' : 'expressChosenIdx'
  71 + this.data[idxName] = '';
63 }, 72 },
64 _show: function (show) { 73 _show: function (show) {
65 if (show) { 74 if (show) {
66 if (this.data.selectedCode) { 75 if (this.data.selectedCode) {
67 this.data.coupons.forEach((item, index) => { 76 this.data.coupons.forEach((item, index) => {
68 - if (item.coupon_code === this.data.selectedCode) { 77 + if (this.data.selectedCode.includes(item.coupon_code)) {
69 this.setData({ 78 this.setData({
70 [`coupons[${index}].isChosen`]: true 79 [`coupons[${index}].isChosen`]: true
71 }); 80 });
72 - this.data.chosenIdx = index; 81 + let idxName = item.coupon_type === 100 ? 'activityChosenIdx' : 'expressChosenIdx'
  82 + this.data[idxName] = index;
73 } else { 83 } else {
74 this.setData({ 84 this.setData({
75 [`coupons[${index}].isChosen`]: false 85 [`coupons[${index}].isChosen`]: false
@@ -82,7 +92,8 @@ Component({ @@ -82,7 +92,8 @@ Component({
82 [`coupons[${index}].isChosen`]: false 92 [`coupons[${index}].isChosen`]: false
83 }); 93 });
84 }); 94 });
85 - this.data.chosenIdx = ''; 95 + this.data.activityChosenIdx = '';
  96 + this.data.expressChosenIdx = '';
86 } 97 }
87 } 98 }
88 console.log(this.data.coupons) 99 console.log(this.data.coupons)
@@ -23,11 +23,12 @@ @@ -23,11 +23,12 @@
23 <text class="name"><text class="prefix">[UFO]</text>{{item.coupon_name}}</text> 23 <text class="name"><text class="prefix">[UFO]</text>{{item.coupon_name}}</text>
24 <text class="period">{{item.coupon_validity}}</text> 24 <text class="period">{{item.coupon_validity}}</text>
25 <block wx:if="{{item.isChosen}}"> 25 <block wx:if="{{item.isChosen}}">
26 - <image bindtap="uncheck" class="checked" data-idx="{{index}}" 26 + <image bindtap="uncheck" class="checked" data-idx="{{index}}" data-type="{{item.coupon_type}}"
27 src="../../assets/images/checked.png"></image> 27 src="../../assets/images/checked.png"></image>
28 </block> 28 </block>
29 <block wx:else> 29 <block wx:else>
30 - <view bindtap="check" class="check" data-idx="{{index}}"></view> 30 + <view wx:if="{{isStore && item.coupon_type === 110}}" class="check disabled"></view>
  31 + <view bindtap="check" class="check" data-idx="{{index}}" data-type="{{item.coupon_type}}"></view>
31 </block> 32 </block>
32 </view> 33 </view>
33 </view> 34 </view>
@@ -161,7 +161,9 @@ @@ -161,7 +161,9 @@
161 border-radius: 48rpx; 161 border-radius: 48rpx;
162 box-sizing: border-box; 162 box-sizing: border-box;
163 } 163 }
164 - 164 +.coupon-use-select .coupon-item .right .check.disabled {
  165 + background-color: #f3f3f3;
  166 +}
165 .coupon-use-select .coupon-item .right .checked { 167 .coupon-use-select .coupon-item .right .checked {
166 position: absolute; 168 position: absolute;
167 top: 50%; 169 top: 50%;
@@ -135,13 +135,13 @@ export default class SelectSize extends Component { @@ -135,13 +135,13 @@ export default class SelectSize extends Component {
135 <Text className="price">¥{this.state.curPrice}</Text> 135 <Text className="price">¥{this.state.curPrice}</Text>
136 } 136 }
137 </Button> 137 </Button>
138 - <Button className='dowload-btn btn-col' hover-class='none' onClick={this.onClickBuy.bind(this, this.state.canBuy)} data-can-buy={this.state.canBu}> 138 + {this.state.canBuy && <Button className='dowload-btn btn-col' hover-class='none'>
139 {/* 下载有货app体验更低价 */} 139 {/* 下载有货app体验更低价 */}
140 更低价 140 更低价
141 { 141 {
142 <Text className="price">¥{this.state.curLowestPrice}</Text> 142 <Text className="price">¥{this.state.curLowestPrice}</Text>
143 } 143 }
144 - </Button> 144 + </Button>}
145 </View>) 145 </View>)
146 : 146 :
147 <Button className={this.state.canBuy ? 'buy-btn' : 'buy-btn disabled'} hover-class='none' onClick={this.onClickBuy.bind(this, this.state.canBuy)} data-can-buy={this.state.canBu}> 147 <Button className={this.state.canBuy ? 'buy-btn' : 'buy-btn disabled'} hover-class='none' onClick={this.onClickBuy.bind(this, this.state.canBuy)} data-can-buy={this.state.canBu}>
@@ -74,14 +74,12 @@ Page({ @@ -74,14 +74,12 @@ Page({
74 }, 74 },
75 75
76 async confirmSelectCoupon({detail}) { 76 async confirmSelectCoupon({detail}) {
77 -  
78 let code = detail.code; 77 let code = detail.code;
79 - let codeType = detail.codeType;  
80 let amount = detail.amount || ''; 78 let amount = detail.amount || '';
81 let couponsList = this.data.couponList; 79 let couponsList = this.data.couponList;
82 if (couponsList){ 80 if (couponsList){
83 couponsList.forEach((item, index) => { 81 couponsList.forEach((item, index) => {
84 - if (code === item.coupon_code) { 82 + if (code.includes(item.coupon_code)) {
85 item.isChosen = true; 83 item.isChosen = true;
86 item.selected = 'Y' 84 item.selected = 'Y'
87 } 85 }
@@ -93,8 +91,7 @@ Page({ @@ -93,8 +91,7 @@ Page({
93 couponsList, 91 couponsList,
94 selectCouponAmount: amount, 92 selectCouponAmount: amount,
95 selectCouponCode: code, 93 selectCouponCode: code,
96 - selectingCoupon: false,  
97 - selectingCouponType: codeType 94 + selectingCoupon: false
98 }); 95 });
99 96
100 // 区分线上线下 97 // 区分线上线下
@@ -104,10 +101,6 @@ Page({ @@ -104,10 +101,6 @@ Page({
104 if (this.data && this.data.promotionTips && this.data.promotionTips.promotionIds) { 101 if (this.data && this.data.promotionTips && this.data.promotionTips.promotionIds) {
105 promotion_id = this.data.promotionTips.promotionIds; 102 promotion_id = this.data.promotionTips.promotionIds;
106 } 103 }
107 - //判断优惠劵的类型  
108 - if (code && codeType !== 110){  
109 - promotion_id = '';  
110 - }  
111 try { 104 try {
112 if (this.data.isStore) { 105 if (this.data.isStore) {
113 info = await api.orderOfflineCompute({ 106 info = await api.orderOfflineCompute({
@@ -193,16 +186,29 @@ Page({ @@ -193,16 +186,29 @@ Page({
193 let that = this; 186 let that = this;
194 if (data && data.couponList && data.couponList.length > 0){ 187 if (data && data.couponList && data.couponList.length > 0){
195 let coupons = []; 188 let coupons = [];
  189 + let activityCoupons = [];
  190 + let expressCoupons = [];
  191 + let couponsAmount = 0;
196 data.couponList.forEach((item, index) => { 192 data.couponList.forEach((item, index) => {
197 let selected = item.selected; 193 let selected = item.selected;
  194 + let couponsType = item.coupon_type;
198 if (selected === 'Y'){ 195 if (selected === 'Y'){
199 item.isChosen = true; 196 item.isChosen = true;
200 - data.selectCouponAmount = item.coupon_value_str;  
201 - data.selectCouponCode = item.coupon_code; 197 + couponsAmount += parseFloat(item.coupon_value_str);
  198 + coupons.push(item.coupon_code);
202 }else { 199 }else {
203 item.isChosen = false; 200 item.isChosen = false;
204 } 201 }
  202 + if(couponsType === 100) {
  203 + activityCoupons.push(item)
  204 + } else if(couponsType === 110) {
  205 + expressCoupons.push(item)
  206 + }
205 }); 207 });
  208 + data.activityCoupons = activityCoupons;
  209 + data.expressCoupons = expressCoupons;
  210 + data.selectCouponAmount = couponsAmount;
  211 + data.selectCouponCode = coupons.join(',');
206 } 212 }
207 213
208 if (data.good && data.good.goodImg) { 214 if (data.good && data.good.goodImg) {
@@ -254,10 +260,7 @@ Page({ @@ -254,10 +260,7 @@ Page({
254 if (this.data && this.data.promotionTips && this.data.promotionTips.promotionIds){ 260 if (this.data && this.data.promotionTips && this.data.promotionTips.promotionIds){
255 promotionId = this.data.promotionTips.promotionIds; 261 promotionId = this.data.promotionTips.promotionIds;
256 } 262 }
257 -  
258 - if (this.data.selectingCouponType && this.data.selectingCouponType !== 110) {  
259 - promotionId = '';  
260 - } 263 +
261 if (this.data.isStore) { 264 if (this.data.isStore) {
262 this.check = this.selectComponent("#check"); 265 this.check = this.selectComponent("#check");
263 let checkRes = await this.check.init(); 266 let checkRes = await this.check.init();
@@ -38,6 +38,6 @@ @@ -38,6 +38,6 @@
38 </view> 38 </view>
39 </view> 39 </view>
40 </view> 40 </view>
41 -<couponSelect bindconfirmselect="confirmSelectCoupon" show="{{selectingCoupon}}" selected-code="{{selectCouponCode}}"  
42 - bindcancel="cancelSelectCoupon" coupons="{{couponList}}" chosenIdx="{{chosenIdx}}"></couponSelect> 41 +<couponSelect bindconfirmselect="confirmSelectCoupon" show="{{selectingCoupon}}" selected-code="{{selectCouponCode}}" isStore="{{isStore === 1}}"
  42 + bindcancel="cancelSelectCoupon" coupons="{{couponList}}"></couponSelect>
43 <checkstore id="check" storeId="{{storeId}}" productId="{{product_id}}"></checkstore> 43 <checkstore id="check" storeId="{{storeId}}" productId="{{product_id}}"></checkstore>
@@ -44,10 +44,17 @@ @@ -44,10 +44,17 @@
44 <text class='order-detail-sum-grey-txt'>-¥{{data.priceInfo.activityCutPrice}}</text> 44 <text class='order-detail-sum-grey-txt'>-¥{{data.priceInfo.activityCutPrice}}</text>
45 </block> 45 </block>
46 </view> 46 </view>
47 - <view class='order-detail-count-view' wx:if="{{data.isOffline !== 'Y'}}"> 47 + <block wx:if="{{data.isOffline !== 'Y'}}">
  48 + <view class='order-detail-count-view'>
48 <text class='order-detail-sum-grey-txt'>运费:</text> 49 <text class='order-detail-sum-grey-txt'>运费:</text>
49 <text class='order-detail-sum-grey-txt'>¥{{data.priceInfo.feePrice}}</text> 50 <text class='order-detail-sum-grey-txt'>¥{{data.priceInfo.feePrice}}</text>
50 </view> 51 </view>
  52 + <view class='order-detail-count-view' wx:if="{{data.priceInfo.shippingCouponCutPrice && data.priceInfo.shippingCouponCutPrice != '0.00' && data.priceInfo.shippingCouponCutPrice != '0'}}">
  53 + <text class='order-detail-sum-grey-txt'>运费券:</text>
  54 + <text class='order-detail-sum-grey-txt'>-¥{{data.priceInfo.shippingCouponCutPrice}}</text>
  55 + </view>
  56 + </block>
  57 +
51 <view class='order-detail-count-view' wx:if="{{data.priceInfo.couponCutPrice}}"> 58 <view class='order-detail-count-view' wx:if="{{data.priceInfo.couponCutPrice}}">
52 <block wx:if="{{data.priceInfo.couponCutPrice != '0.00' && data.priceInfo.couponCutPrice != '0'}}"> 59 <block wx:if="{{data.priceInfo.couponCutPrice != '0.00' && data.priceInfo.couponCutPrice != '0'}}">
53 <text class='order-detail-sum-grey-txt'>优惠券:</text> 60 <text class='order-detail-sum-grey-txt'>优惠券:</text>