Authored by 毕凯

修改优惠券使用方式

  1 +/**
  2 + * 订单信息读取
  3 + * @author: bikai<kai.bi@yoho.cn>
  4 + * @date: 2015/12/14
  5 + */
  6 +var info = window.cookie('order-info'),
  7 + orderInfo;
  8 +
  9 +// info 必须是 JSON 字符串
  10 +try {
  11 + info = JSON.parse(orderInfo);
  12 +} catch (e) {
  13 + info = {};
  14 +}
  15 +
  16 +orderInfo = function(key, value) {
  17 + if (value === undefined) {
  18 + return info[key];
  19 + }
  20 + info[key] = value;
  21 + window.setCookie('order-info', JSON.stringify(info));
  22 +};
  23 +
  24 +module.export = orderInfo;
  1 +/**
  2 + * 优惠券选择
  3 + * @author: bikai<kai.bi@yoho.cn>
  4 + * @date: 2015/12/10
  5 + */
  6 +
1 var $ = require('jquery'), 7 var $ = require('jquery'),
2 Handlebars = require('yoho.handlebars'), 8 Handlebars = require('yoho.handlebars'),
3 ellipsis = require('mlellipsis'), 9 ellipsis = require('mlellipsis'),
4 loading = require('../plugin/loading'), 10 loading = require('../plugin/loading'),
5 - tip = require('../plugin/tip'); 11 + tip = require('../plugin/tip'),
  12 + orderInfo = require('./order-info');
6 13
7 var page = 1, 14 var page = 1,
8 canGetCoupon = true, 15 canGetCoupon = true,
@@ -21,9 +28,10 @@ $('#search-coupon').on('submit', function() { @@ -21,9 +28,10 @@ $('#search-coupon').on('submit', function() {
21 }).then(function(res) { 28 }).then(function(res) {
22 if (res.code === 200) { 29 if (res.code === 200) {
23 tip.show('优惠券可用'); 30 tip.show('优惠券可用');
  31 + orderInfo('couponCode', res.data.coupon_code);
24 window.location.href = '/shoppingCart/orderEnsure?coupon_code=' + res.data.coupon_code; 32 window.location.href = '/shoppingCart/orderEnsure?coupon_code=' + res.data.coupon_code;
25 } else { 33 } else {
26 - tip.show(res.msg); 34 + tip.show(res.message);
27 } 35 }
28 }).fail(function() { 36 }).fail(function() {
29 tip.show('网络错误'); 37 tip.show('网络错误');
@@ -31,6 +39,10 @@ $('#search-coupon').on('submit', function() { @@ -31,6 +39,10 @@ $('#search-coupon').on('submit', function() {
31 return false; 39 return false;
32 }); 40 });
33 41
  42 +$('#coupon-list').on('touchend', 'employ-main', function() {
  43 + orderInfo('couponCode', $(this).data('coupon-code'));
  44 +});
  45 +
34 function getCouponHandle(coupons) { 46 function getCouponHandle(coupons) {
35 var notAvailableCoupons = []; 47 var notAvailableCoupons = [];
36 48
@@ -11,7 +11,7 @@ @@ -11,7 +11,7 @@
11 <script id="tmpl-coupon" type="text/tmpl"> 11 <script id="tmpl-coupon" type="text/tmpl">
12 \{{#coupons}} 12 \{{#coupons}}
13 \{{^ notAvailable}} 13 \{{^ notAvailable}}
14 - <a class="employ-main" href="/shoppingCart/orderEnsure?coupon_code={{ coupon_code}}"> 14 + <a class="employ-main" data-coupon-code="{{ coupon_code}}" href="/shoppingCart/orderEnsure?coupon_code={{ coupon_code}}">
15 <span>\{{ money}}</span> 15 <span>\{{ money}}</span>
16 <p class="coupon-name">\{{ coupon_name}}</p> 16 <p class="coupon-name">\{{ coupon_name}}</p>
17 <p>有效期:\{{ couponValidity}}</p> 17 <p>有效期:\{{ couponValidity}}</p>