Authored by baoss

促销与运费券选择优化 review by bevishuang

@@ -27,15 +27,24 @@ Component({ @@ -27,15 +27,24 @@ Component({
27 let chosenIdxName = ['activityChosenIdx','expressChosenIdx']; 27 let chosenIdxName = ['activityChosenIdx','expressChosenIdx'];
28 let code = []; 28 let code = [];
29 let amount = 0; 29 let amount = 0;
  30 + let typeVal = {};
30 chosenIdxName.forEach(val => { 31 chosenIdxName.forEach(val => {
31 let item = this.data.coupons[this.data[val]]; 32 let item = this.data.coupons[this.data[val]];
32 let itemCode = item && item.coupon_code || ''; 33 let itemCode = item && item.coupon_code || '';
33 let itemAmount = item && item.coupon_value_str || ''; 34 let itemAmount = item && item.coupon_value_str || '';
34 - itemCode && code.push(itemCode); 35 +
35 amount = (itemAmount ? parseFloat(itemAmount) : 0) + amount; 36 amount = (itemAmount ? parseFloat(itemAmount) : 0) + amount;
  37 + if (itemCode) {
  38 + code.push(itemCode);
  39 + let itemVal = {
  40 + code: itemCode,
  41 + amount: itemAmount ? parseFloat(itemAmount) : 0
  42 + }
  43 + typeVal[item.coupon_type] = itemVal
  44 + }
36 }) 45 })
37 code = code.join(','); 46 code = code.join(',');
38 - this.triggerEvent('confirmselect', { code, amount}) 47 + this.triggerEvent('confirmselect', { code, amount, typeVal})
39 }, 48 },
40 cancel: function () { 49 cancel: function () {
41 this.triggerEvent('cancel') 50 this.triggerEvent('cancel')
@@ -30,6 +30,7 @@ Page({ @@ -30,6 +30,7 @@ Page({
30 storeId: 0, 30 storeId: 0,
31 skup: '', 31 skup: '',
32 coupons: [], 32 coupons: [],
  33 + selectCouponData: {},
33 selectCouponCode: '', 34 selectCouponCode: '',
34 selectCouponAmount: 0, 35 selectCouponAmount: 0,
35 selectingCoupon: false, 36 selectingCoupon: false,
@@ -101,22 +102,35 @@ Page({ @@ -101,22 +102,35 @@ Page({
101 selectPromotionAmount: amount, 102 selectPromotionAmount: amount,
102 isManualSelectPro: true, 103 isManualSelectPro: true,
103 }); 104 });
104 - if(code) { 105 +
  106 + let typeArr = Object.keys(this.data.selectCouponData);
  107 + let selectCouponCode = '';
  108 + let selectCouponAmount = 0;
  109 + let selectCouponData = {};
  110 + if(code) { //选择促销时 只保留运费券
  111 + if (typeArr.length > 0 && typeArr.includes('110')) {
  112 + selectCouponCode = this.data.selectCouponData[110].code;
  113 + selectCouponAmount = this.data.selectCouponData[110].amount;
  114 + selectCouponData[110] = this.data.selectCouponData[110]
  115 + }
105 this.setData({ 116 this.setData({
106 // 重置优惠券 117 // 重置优惠券
107 - selectCouponAmount: 0,  
108 - selectCouponCode: '', 118 + selectCouponData,
  119 + selectCouponAmount,
  120 + selectCouponCode,
109 isManualSelect: false 121 isManualSelect: false
110 }); 122 });
  123 +
  124 + }
111 this.orderCompute({ 125 this.orderCompute({
112 - promotion_id: code 126 + promotion_id: code,
  127 + code: this.data.selectCouponCode
113 }) 128 })
114 - }  
115 -  
116 }, 129 },
117 confirmSelectCoupon({detail}) { 130 confirmSelectCoupon({detail}) {
118 let code = detail.code; 131 let code = detail.code;
119 let amount = detail.amount || 0; 132 let amount = detail.amount || 0;
  133 + let typeVal = detail.typeVal;
120 let couponsList = this.data.couponList; 134 let couponsList = this.data.couponList;
121 if (couponsList){ 135 if (couponsList){
122 couponsList.forEach((item, index) => { 136 couponsList.forEach((item, index) => {
@@ -129,21 +143,28 @@ Page({ @@ -129,21 +143,28 @@ Page({
129 } 143 }
130 this.setData({ 144 this.setData({
131 couponsList, 145 couponsList,
  146 + selectCouponData: typeVal,
132 selectCouponAmount: amount, 147 selectCouponAmount: amount,
133 selectCouponCode: code, 148 selectCouponCode: code,
134 selectingCoupon: false, 149 selectingCoupon: false,
135 isManualSelect: true 150 isManualSelect: true
136 }); 151 });
137 if(code) { 152 if(code) {
  153 + let typeArr = Object.keys(typeVal);
  154 + if (typeArr.length > 0 && typeArr.includes('100')) { // 选择优惠券时才重置
138 this.setData({ 155 this.setData({
139 // 重置促销 156 // 重置促销
140 selectPromotionCode: 0, 157 selectPromotionCode: 0,
141 selectPromotionAmount: 0, 158 selectPromotionAmount: 0,
142 isManualSelectPro: false 159 isManualSelectPro: false
143 }); 160 });
144 - this.orderCompute({code})  
145 } 161 }
146 162
  163 + }
  164 + this.orderCompute({
  165 + code,
  166 + promotion_id: this.data.selectPromotionCode || ''
  167 + })
147 }, 168 },
148 async orderCompute({ 169 async orderCompute({
149 code = '', 170 code = '',
@@ -244,12 +265,18 @@ Page({ @@ -244,12 +265,18 @@ Page({
244 if (data && data.couponList && data.couponList.length > 0){ 265 if (data && data.couponList && data.couponList.length > 0){
245 let coupons = []; 266 let coupons = [];
246 let couponsAmount = 0; 267 let couponsAmount = 0;
  268 + let selectedCoupons = {};
247 data.couponList.forEach((item, index) => { 269 data.couponList.forEach((item, index) => {
248 let selected = item.selected; 270 let selected = item.selected;
249 if (selected === 'Y'){ 271 if (selected === 'Y'){
250 item.isChosen = true; 272 item.isChosen = true;
251 couponsAmount += parseFloat(item.coupon_value_str); 273 couponsAmount += parseFloat(item.coupon_value_str);
252 coupons.push(item.coupon_code); 274 coupons.push(item.coupon_code);
  275 + let itemVal = {
  276 + code: item.coupon_code,
  277 + amount: parseFloat(item.coupon_value_str)
  278 + }
  279 + selectedCoupons[item.coupon_type] = itemVal
253 }else { 280 }else {
254 item.isChosen = false; 281 item.isChosen = false;
255 } 282 }
@@ -257,6 +284,7 @@ Page({ @@ -257,6 +284,7 @@ Page({
257 284
258 data.selectCouponAmount = couponsAmount; 285 data.selectCouponAmount = couponsAmount;
259 data.selectCouponCode = coupons.join(','); 286 data.selectCouponCode = coupons.join(',');
  287 + data.selectCouponData = selectedCoupons;
260 } 288 }
261 if (data && data.promotionList && data.promotionList.length > 0) { 289 if (data && data.promotionList && data.promotionList.length > 0) {
262 let promotions = 0; 290 let promotions = 0;