Showing
6 changed files
with
87 additions
and
32 deletions
static/js/shopping-cart/order-info.js
0 → 100644
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, |
@@ -16,43 +23,48 @@ ellipsis.init(); | @@ -16,43 +23,48 @@ ellipsis.init(); | ||
16 | $('#search-coupon').on('submit', function() { | 23 | $('#search-coupon').on('submit', function() { |
17 | $.ajax({ | 24 | $.ajax({ |
18 | method: 'POST', | 25 | method: 'POST', |
19 | - url: '', | 26 | + url: '/shoppingCart/coupon', |
20 | data: $(this).serialize() | 27 | data: $(this).serialize() |
21 | }).then(function(res) { | 28 | }).then(function(res) { |
22 | - if (res.avaliable) { | ||
23 | - $('#coupon-list').html(conponTmpl({ | ||
24 | - coupons: res.coupons | ||
25 | - })); | ||
26 | - $('#coupon-list-not').html(''); | 29 | + if (res.code === 200) { |
30 | + tip.show('优惠券可用'); | ||
31 | + orderInfo('couponCode', res.data.coupon_code); | ||
32 | + window.location.href = '/shoppingCart/orderEnsure?coupon_code=' + res.data.coupon_code; | ||
27 | } else { | 33 | } else { |
28 | - tip.show(res.msg); | 34 | + tip.show(res.message); |
29 | } | 35 | } |
36 | + }).fail(function() { | ||
37 | + tip.show('网络错误'); | ||
30 | }); | 38 | }); |
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 | ||
37 | // 后端需要返回一个 coupons 列表,如下 | 49 | // 后端需要返回一个 coupons 列表,如下 |
38 | // notAvailable 表示不可用的优惠券 | 50 | // notAvailable 表示不可用的优惠券 |
39 | - coupons = [{ | ||
40 | - money: '99', | ||
41 | - coupon_name: '满XX-减去吴悠右腿有益于有2222', | ||
42 | - couponValidity: '20150129-20150430', | ||
43 | - coupon_id: '22222' | ||
44 | - }, { | ||
45 | - money: '99', | ||
46 | - coupon_name: '满XX-减去吴悠右腿有益于有2222', | ||
47 | - couponValidity: '20150129-20150430', | ||
48 | - coupon_id: '2222233' | ||
49 | - }, { | ||
50 | - money: '99', | ||
51 | - coupon_name: 'NONO满XX-减去吴悠右腿有益于有2222', | ||
52 | - couponValidity: '20150129-20150430', | ||
53 | - coupon_id: '2222233', | ||
54 | - notAvailable: 1 | ||
55 | - }]; | 51 | + // coupons = [{ |
52 | + // money: '99', | ||
53 | + // coupon_name: '满XX-减去吴悠右腿有益于有2222', | ||
54 | + // couponValidity: '20150129-20150430', | ||
55 | + // coupon_id: '22222' | ||
56 | + // }, { | ||
57 | + // money: '99', | ||
58 | + // coupon_name: '满XX-减去吴悠右腿有益于有2222', | ||
59 | + // couponValidity: '20150129-20150430', | ||
60 | + // coupon_id: '2222233' | ||
61 | + // }, { | ||
62 | + // money: '99', | ||
63 | + // coupon_name: 'NONO满XX-减去吴悠右腿有益于有2222', | ||
64 | + // couponValidity: '20150129-20150430', | ||
65 | + // coupon_id: '2222233', | ||
66 | + // notAvailable: 1 | ||
67 | + // }]; | ||
56 | 68 | ||
57 | // coupons 是个列表,如果不是列表,可能是服务器错误,这次翻页加载不算 | 69 | // coupons 是个列表,如果不是列表,可能是服务器错误,这次翻页加载不算 |
58 | if (!$.isArray(coupons)) { | 70 | if (!$.isArray(coupons)) { |
@@ -106,9 +118,8 @@ function getCouponDate() { | @@ -106,9 +118,8 @@ function getCouponDate() { | ||
106 | $.ajax({ | 118 | $.ajax({ |
107 | type: 'POST', | 119 | type: 'POST', |
108 | url: '/home/couponData', | 120 | url: '/home/couponData', |
109 | - dataType: 'html', | 121 | + dataType: 'json', |
110 | data: { | 122 | data: { |
111 | - statuss: status, | ||
112 | page: page | 123 | page: page |
113 | } | 124 | } |
114 | }).then(getCouponHandle).fail(function() { | 125 | }).then(getCouponHandle).fail(function() { |
@@ -163,6 +163,20 @@ | @@ -163,6 +163,20 @@ | ||
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||
166 | + #msg { | ||
167 | + padding-top: pxToRem(20px); | ||
168 | + input { | ||
169 | + padding: pxToRem(10px); | ||
170 | + width: pxToRem(580px); | ||
171 | + height: pxToRem(50px); | ||
172 | + outline: 0; | ||
173 | + border: 0; | ||
174 | + border: 1px solid #f7f7f7; | ||
175 | + border-radius: pxToRem(4px); | ||
176 | + } | ||
177 | + | ||
178 | + } | ||
179 | + | ||
166 | .total { | 180 | .total { |
167 | font-size: 22rem / $pxConvertRem; | 181 | font-size: 22rem / $pxConvertRem; |
168 | margin-top: 20rem / $pxConvertRem; | 182 | margin-top: 20rem / $pxConvertRem; |
@@ -97,6 +97,12 @@ | @@ -97,6 +97,12 @@ | ||
97 | {{/if}} | 97 | {{/if}} |
98 | </ul> | 98 | </ul> |
99 | 99 | ||
100 | + <form id="msg" action="" method="post"> | ||
101 | + <input type="text" name="msg" value="" placeholder="留言"> | ||
102 | + </form> | ||
103 | + </section> | ||
104 | + | ||
105 | + <section class="block"> | ||
100 | <ul class="total"> | 106 | <ul class="total"> |
101 | <li> | 107 | <li> |
102 | <span>总价</span> | 108 | <span>总价</span> |
1 | {{> layout/header}} | 1 | {{> layout/header}} |
2 | <div class="yoho-page select-coupon-page my-coupon-page"> | 2 | <div class="yoho-page select-coupon-page my-coupon-page"> |
3 | <form id="search-coupon" method="POST" action=""> | 3 | <form id="search-coupon" method="POST" action=""> |
4 | - <input type="text" name="coupon-code" value="" placeholder="输入优惠券码"> | 4 | + <input type="text" name="couponCode" value="" placeholder="输入优惠券码"> |
5 | <button type="submit" class="submit">确定</button> | 5 | <button type="submit" class="submit">确定</button> |
6 | </form> | 6 | </form> |
7 | <div id="coupon-list" class="coupon-list"></div> | 7 | <div id="coupon-list" class="coupon-list"></div> |
@@ -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_id={{ coupon_id}}"> | 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> |
@@ -33,7 +33,7 @@ class ShoppingCartController extends AbstractAction | @@ -33,7 +33,7 @@ class ShoppingCartController extends AbstractAction | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * 加入购物车 | 35 | * 加入购物车 |
36 | - * | 36 | + * |
37 | * @param string productSku 商品的SKU | 37 | * @param string productSku 商品的SKU |
38 | * @param int buyNumber 购买数量 | 38 | * @param int buyNumber 购买数量 |
39 | * @param int promotionId 促销ID, 加价购有关 | 39 | * @param int promotionId 促销ID, 加价购有关 |
@@ -53,10 +53,10 @@ class ShoppingCartController extends AbstractAction | @@ -53,10 +53,10 @@ class ShoppingCartController extends AbstractAction | ||
53 | $promotionId = $this->post('promotionId', 0); | 53 | $promotionId = $this->post('promotionId', 0); |
54 | $isEdit = $this->post('isEdit', 0); | 54 | $isEdit = $this->post('isEdit', 0); |
55 | $uid = $this->getUid(true); | 55 | $uid = $this->getUid(true); |
56 | - | 56 | + |
57 | // 执行加入购物车操作 | 57 | // 执行加入购物车操作 |
58 | $result = CartModel::addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid, $shoppingKey); | 58 | $result = CartModel::addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid, $shoppingKey); |
59 | - | 59 | + |
60 | // 设置加入购物车凭证到客户端浏览器 | 60 | // 设置加入购物车凭证到客户端浏览器 |
61 | if (isset($result['data']['shopping_key'])) { | 61 | if (isset($result['data']['shopping_key'])) { |
62 | $this->setCookie('_spk', $shoppingKey); | 62 | $this->setCookie('_spk', $shoppingKey); |
-
Please register or login to post a comment