Showing
4 changed files
with
130 additions
and
54 deletions
@@ -12,6 +12,30 @@ const crypto = global.yoho.crypto; | @@ -12,6 +12,30 @@ const crypto = global.yoho.crypto; | ||
12 | 12 | ||
13 | const easypayApi = require('./easypay-api'); | 13 | const easypayApi = require('./easypay-api'); |
14 | 14 | ||
15 | + | ||
16 | +const _hadelUseYohoCoin = (info) => { | ||
17 | + let limitCoin = _.get(info, 'yoho_coin_pay_rule.num_limit', 0); | ||
18 | + | ||
19 | + if (info) { | ||
20 | + info.canUseCoinNum = _.round(info.yoho_coin * 100); | ||
21 | + info.usedCoinNum = _.round(info.use_yoho_coin * 100); | ||
22 | + | ||
23 | + if (!info.canUseCoinNum) { | ||
24 | + let coinErrorTip = ''; | ||
25 | + | ||
26 | + if (info.total_yoho_coin_num > limitCoin) { | ||
27 | + coinErrorTip = '抱歉,您的订单实付款不满足有货币使用条件'; | ||
28 | + } else { | ||
29 | + coinErrorTip = `抱歉,您的有货币不足,有货币满${limitCoin}个方可使用`; | ||
30 | + } | ||
31 | + | ||
32 | + info.coinErrorTip = coinErrorTip; | ||
33 | + } | ||
34 | + } | ||
35 | + | ||
36 | + return info; | ||
37 | +}; | ||
38 | + | ||
15 | const _handelPaymentInfo = (d) => { | 39 | const _handelPaymentInfo = (d) => { |
16 | let resData = {}; | 40 | let resData = {}; |
17 | 41 | ||
@@ -70,7 +94,7 @@ const _handelPaymentInfo = (d) => { | @@ -70,7 +94,7 @@ const _handelPaymentInfo = (d) => { | ||
70 | paymentWay: d.payment_way, | 94 | paymentWay: d.payment_way, |
71 | deliveryTime: d.delivery_time, | 95 | deliveryTime: d.delivery_time, |
72 | deliveryWay: d.delivery_way, | 96 | deliveryWay: d.delivery_way, |
73 | - shoppingCartData: d.shopping_cart_data, | 97 | + shoppingCartData: _hadelUseYohoCoin(d.shopping_cart_data), |
74 | invoices: d.invoices | 98 | invoices: d.invoices |
75 | }); | 99 | }); |
76 | 100 |
@@ -270,6 +270,24 @@ | @@ -270,6 +270,24 @@ | ||
270 | <div class="using-coin coin-trigger hide"> | 270 | <div class="using-coin coin-trigger hide"> |
271 | <ul> | 271 | <ul> |
272 | <li> | 272 | <li> |
273 | + {{#if coinErrorTip}} | ||
274 | + <span class="red">{{coinErrorTip}}</span> | ||
275 | + {{^}} | ||
276 | + 有货币满<span class="red">{{yoho_coin_pay_rule.num_limit}}</span>个即可使用,每次使用有货币为<span class="red">{{yoho_coin_pay_rule.num_limit}}</span>的整数倍 | ||
277 | + {{/if}} | ||
278 | + | ||
279 | + <i class="iconfont help-icon"></i> | ||
280 | + <div class="coin-tip-help"> | ||
281 | + <p>有货币使用条件:</p> | ||
282 | + <p>1.订单金额大于20元(含) 2.有货币数量大于{{yoho_coin_pay_rule.num_limit}}个(含) 3.有货币支付不得超过每笔订单应付金额的{{yoho_coin_pay_rule.max_pay_rate_desc}}</p> | ||
283 | + <p>备注:使用有货币数量为{{yoho_coin_pay_rule.num_limit}}的整数倍,100有货币抵1元</p> | ||
284 | + </div> | ||
285 | + </li> | ||
286 | + <li>您当前共有有货币 <span class="red">{{total_yoho_coin_num}}</span> 个,可用 <span class="red">{{canUseCoinNum}}</span> 个</li> | ||
287 | + <li> | ||
288 | + <p{{#if coinErrorTip}} class="coin-use-hide"{{/if}}>本次使用有货币<span class="coin-box">{{canUseCoinNum}}</span>个,抵扣 <span class="red">¥{{yoho_coin}}</span></p> | ||
289 | + </li> | ||
290 | + {{!-- <li> | ||
273 | 使用有货币:<input id="coin-used" class="coin-used" type="text" data-max="{{hasCoin}}">个 | 291 | 使用有货币:<input id="coin-used" class="coin-used" type="text" data-max="{{hasCoin}}">个 |
274 | </li> | 292 | </li> |
275 | <li class="coin-sum-row"> | 293 | <li class="coin-sum-row"> |
@@ -277,14 +295,16 @@ | @@ -277,14 +295,16 @@ | ||
277 | </li> | 295 | </li> |
278 | <li class="coin-tip-row"> | 296 | <li class="coin-tip-row"> |
279 | <span id="coin-tip" class="coin-tip vhide"></span> | 297 | <span id="coin-tip" class="coin-tip vhide"></span> |
280 | - </li> | 298 | + </li> --}} |
281 | </ul> | 299 | </ul> |
282 | 300 | ||
283 | <p class="btns"> | 301 | <p class="btns"> |
284 | <span id="coin-sure" class="coin-sure sure-btn">确定</span> | 302 | <span id="coin-sure" class="coin-sure sure-btn">确定</span> |
285 | <span id="coin-cancel" class="coin-cancel cancel-btn">取消</span> | 303 | <span id="coin-cancel" class="coin-cancel cancel-btn">取消</span> |
304 | + <a href="/help/?category_id=87" class="coin-help" target="_blank">有货币使用规则?</a> | ||
286 | </p> | 305 | </p> |
287 | </div> | 306 | </div> |
307 | + <input id="coin-used" type="hidden" data-coin="{{usedCoinNum}}" data-max={{canUseCoinNum}}> | ||
288 | </li> | 308 | </li> |
289 | </ul> | 309 | </ul> |
290 | </div> | 310 | </div> |
@@ -16,16 +16,7 @@ var couponsTpl = Hbs.compile($('#coupons-tpl').html()); | @@ -16,16 +16,7 @@ var couponsTpl = Hbs.compile($('#coupons-tpl').html()); | ||
16 | var promotionTpl = Hbs.compile($('#promotion-list-tpl').html()); | 16 | var promotionTpl = Hbs.compile($('#promotion-list-tpl').html()); |
17 | 17 | ||
18 | var $coin = $('#coin-used'); | 18 | var $coin = $('#coin-used'); |
19 | -var $coinTip = $('#coin-tip'); | ||
20 | var $coinSure = $('#coin-sure'); | 19 | var $coinSure = $('#coin-sure'); |
21 | -var coinMax = +$coin.data('max'); | ||
22 | -var coinStatus = { | ||
23 | - err: '请输入一个正整数', | ||
24 | - max: '您的有货币不足', | ||
25 | - success: '抵扣', | ||
26 | - maxUse: '您最多使用', | ||
27 | - muPostfix: '个有货币' | ||
28 | -}; | ||
29 | 20 | ||
30 | var queryInfo; | 21 | var queryInfo; |
31 | var pkgCache = {}; | 22 | var pkgCache = {}; |
@@ -178,63 +169,35 @@ if ($('#use-coupons').length) { | @@ -178,63 +169,35 @@ if ($('#use-coupons').length) { | ||
178 | } | 169 | } |
179 | 170 | ||
180 | // 有货币 | 171 | // 有货币 |
172 | +if ($coin) { | ||
173 | + $coin.data($coin.data()); // 防止人为更改有货币使用数量 | ||
174 | +} | ||
175 | + | ||
181 | $('#use-coin, #coin-sure, #coin-cancel').click(function() { | 176 | $('#use-coin, #coin-sure, #coin-cancel').click(function() { |
182 | $('.coin-trigger').toggleClass('hide'); | 177 | $('.coin-trigger').toggleClass('hide'); |
183 | }); | 178 | }); |
184 | 179 | ||
185 | -$coin.on('propertychange input', function() { | ||
186 | - var c = $.trim($coin.val()); | ||
187 | - var err = true; | ||
188 | - | ||
189 | - if (c === '') { | 180 | +$coinSure.click(function() { |
181 | + var data = $coin.data(); | ||
190 | 182 | ||
191 | - // 输入框为空,确定按钮不可点 | ||
192 | - $coinTip.addClass('vhide'); | ||
193 | - $coinTip.text(coinStatus.err); | 183 | + if ($coinSure.hasClass('disable') || |
184 | + data.coin === data.max) { | ||
194 | return; | 185 | return; |
195 | - } else if (!/^[1-9]\d*$/.test(c)) { | ||
196 | - | ||
197 | - // 验证输入不为正整数 | ||
198 | - $coinTip.text(coinStatus.err); | ||
199 | - } else if (+c > coinMax) { | ||
200 | - | ||
201 | - // 有货币不足 | ||
202 | - $coinTip.text(coinStatus.max); | ||
203 | - } else if (+c > $('#sum-row').data('amount') * 100) { | ||
204 | - | ||
205 | - // 输入的有货币大于订单额度 | ||
206 | - $coinTip.text(coinStatus.maxUse + ($('#sum-row').data('amount') * 100) + coinStatus.muPostfix); | ||
207 | - } else { | ||
208 | - err = false; | ||
209 | - $coinTip.text(coinStatus.success + (c / 100).toFixed(2) + '元'); | ||
210 | - | ||
211 | - // 已使用面板的数据显示更新 | ||
212 | - // $coinUsed.html(c); | ||
213 | - // $coinDeduction.html((c / 100).toFixed(2)); | ||
214 | } | 186 | } |
215 | 187 | ||
216 | - if (err) { | ||
217 | - $coinSure.addClass('disable'); | ||
218 | - $coinTip.removeClass('vhide'); | ||
219 | - } else { | ||
220 | - $coinSure.removeClass('disable'); | ||
221 | - $coinTip.addClass('vhide'); | ||
222 | - } | ||
223 | -}); | ||
224 | - | ||
225 | -$coinSure.click(function() { | ||
226 | - if ($coinSure.hasClass('disable')) { | ||
227 | - return; | ||
228 | - } | ||
229 | - $coin.data('coin', $.trim($coin.val())); | 188 | + $coin.data('coin', data.max); |
230 | 189 | ||
231 | // coin change trigger compute | 190 | // coin change trigger compute |
232 | compute(); | 191 | compute(); |
233 | }); | 192 | }); |
234 | 193 | ||
235 | $('#coin-cancel').click(function() { | 194 | $('#coin-cancel').click(function() { |
236 | - $coin.val('').data('coin', ''); | ||
237 | - $coinTip.addClass('vhide').text(''); | 195 | + var data = $coin.data(); |
196 | + | ||
197 | + if (data.coin * 1 === 0) { | ||
198 | + return; | ||
199 | + } | ||
200 | + $coin.data('coin', 0); | ||
238 | 201 | ||
239 | // coin cancel trigger compute | 202 | // coin cancel trigger compute |
240 | compute(); | 203 | compute(); |
@@ -492,6 +492,75 @@ | @@ -492,6 +492,75 @@ | ||
492 | } | 492 | } |
493 | } | 493 | } |
494 | 494 | ||
495 | + .using-coin { | ||
496 | + text-align: left; | ||
497 | + | ||
498 | + li { | ||
499 | + padding-bottom: 10px; | ||
500 | + } | ||
501 | + | ||
502 | + .red { | ||
503 | + color: #db6976; | ||
504 | + } | ||
505 | + | ||
506 | + .help-icon { | ||
507 | + float: right; | ||
508 | + cursor: pointer; | ||
509 | + | ||
510 | + &:hover + .coin-tip-help { | ||
511 | + display: block; | ||
512 | + } | ||
513 | + } | ||
514 | + | ||
515 | + .coin-tip-help { | ||
516 | + width: 310px; | ||
517 | + padding: 6px; | ||
518 | + border: 1px solid #000; | ||
519 | + background-color: #fff; | ||
520 | + position: absolute; | ||
521 | + margin-left: 56px; | ||
522 | + margin-top: 10px; | ||
523 | + display: none; | ||
524 | + } | ||
525 | + | ||
526 | + .coin-use-hide { | ||
527 | + color: #d4d4d4; | ||
528 | + } | ||
529 | + | ||
530 | + .coin-box { | ||
531 | + display: inline-block; | ||
532 | + width: 70px; | ||
533 | + height: 24px; | ||
534 | + line-height: 24px; | ||
535 | + text-align: center; | ||
536 | + border: 1px solid #d4d4d4; | ||
537 | + margin: 0 6px; | ||
538 | + } | ||
539 | + | ||
540 | + .btns { | ||
541 | + margin-top: 10px; | ||
542 | + text-align: left; | ||
543 | + | ||
544 | + span { | ||
545 | + padding: 4px 14px; | ||
546 | + cursor: pointer; | ||
547 | + border: 1px solid #ccc; | ||
548 | + } | ||
549 | + | ||
550 | + .sure-btn { | ||
551 | + color: #fff; | ||
552 | + background-color: #000; | ||
553 | + border-color: #000; | ||
554 | + margin-right: 20px; | ||
555 | + } | ||
556 | + | ||
557 | + .coin-help { | ||
558 | + float: right; | ||
559 | + color: #5291f7; | ||
560 | + } | ||
561 | + } | ||
562 | + } | ||
563 | + | ||
495 | .coin-sum-row, | 564 | .coin-sum-row, |
496 | .coin-tip-row { | 565 | .coin-tip-row { |
497 | padding: 10px 0; | 566 | padding: 10px 0; |
-
Please register or login to post a comment