Authored by 郭成尧

useCouponCode-goback

@@ -301,13 +301,13 @@ exports.couponList = (req, res, next) => { @@ -301,13 +301,13 @@ exports.couponList = (req, res, next) => {
301 /** 301 /**
302 * 购物车输入优惠券码使用优惠券 302 * 购物车输入优惠券码使用优惠券
303 */ 303 */
304 -exports.couponSearch = (req, res, next) => { 304 +exports.useCouponCode = (req, res, next) => {
305 let couponCode = req.body.couponCode || ''; 305 let couponCode = req.body.couponCode || '';
306 let uid = req.user.uid; 306 let uid = req.user.uid;
307 307
308 co(function* () { 308 co(function* () {
309 if (req.xhr) { 309 if (req.xhr) {
310 - let result = yield cartModel.searchCoupon(uid, couponCode); 310 + let result = yield cartModel.useCouponCode(uid, couponCode);
311 311
312 res.json(result); 312 res.json(result);
313 } else { 313 } else {
@@ -276,7 +276,7 @@ exports.getCouponList = uid => { @@ -276,7 +276,7 @@ exports.getCouponList = uid => {
276 ); 276 );
277 }; 277 };
278 278
279 -exports.searchCoupon = (uid, couponCode) => { 279 +exports.useCouponCode = (uid, couponCode) => {
280 let result = {code: 400, message: '出错啦~'}; 280 let result = {code: 400, message: '出错啦~'};
281 281
282 if (!couponCode) { 282 if (!couponCode) {
@@ -38,7 +38,7 @@ router.post('/index/new/orderCompute', authMW, order.orderCompute); // 结算页 @@ -38,7 +38,7 @@ router.post('/index/new/orderCompute', authMW, order.orderCompute); // 结算页
38 router.post('/index/new/orderSub', authMW, order.orderSub); // 订单提交 38 router.post('/index/new/orderSub', authMW, order.orderSub); // 订单提交
39 router.get('/index/new/selectCoupon', authMW, order.selectCoupon); // 选择优惠券 页面 39 router.get('/index/new/selectCoupon', authMW, order.selectCoupon); // 选择优惠券 页面
40 router.get('/index/new/couponList', order.couponList); // [ajax]获取优惠券列表 40 router.get('/index/new/couponList', order.couponList); // [ajax]获取优惠券列表
41 -router.post('/index/new/couponSearch', order.couponSearch); // [ajax]购物车输入优惠券码使用优惠券 41 +router.post('/index/new/useCouponCode', order.useCouponCode); // [ajax]购物车输入优惠券码使用优惠券
42 router.get('/index/new/selectAddress', authMW, order.selectAddress); // 选择地址 42 router.get('/index/new/selectAddress', authMW, order.selectAddress); // 选择地址
43 router.get('/index/new/invoiceInfo', authMW, order.invoiceInfo); // 发票信息 43 router.get('/index/new/invoiceInfo', authMW, order.invoiceInfo); // 发票信息
44 router.get('/index/new/jitDetail', authMW, order.jitDetail); // JIT 拆单配送信息 44 router.get('/index/new/jitDetail', authMW, order.jitDetail); // JIT 拆单配送信息
@@ -24,8 +24,8 @@ @@ -24,8 +24,8 @@
24 <div id="couponUnavailable" class="coupon-list"></div> 24 <div id="couponUnavailable" class="coupon-list"></div>
25 </div> 25 </div>
26 <div class="use-coupon-btn-group"> 26 <div class="use-coupon-btn-group">
27 - <button class="pull-left use">使用</button>  
28 - <button class="pull-right not-use">不使用</button> 27 + <button id="useCoupon" class="pull-left use">使用</button>
  28 + <button id="notUseCoupon" class="pull-right not-use">不使用</button>
29 </div> 29 </div>
30 </div> 30 </div>
31 <script id="tmpl-no-coupon" type="text/tmpl"> 31 <script id="tmpl-no-coupon" type="text/tmpl">
@@ -19,6 +19,8 @@ let isGetData; @@ -19,6 +19,8 @@ let isGetData;
19 let $newCoupon = $('#new-coupon'), 19 let $newCoupon = $('#new-coupon'),
20 linkUrl = document.referrer, 20 linkUrl = document.referrer,
21 $couponList = $('#couponAvailable'); 21 $couponList = $('#couponAvailable');
  22 +let $useCoupon = $('#useCoupon');
  23 +let $notUseCoupon = $('#notUseCoupon');
22 24
23 let winH = $(window).height(); 25 let winH = $(window).height();
24 26
@@ -49,6 +51,9 @@ function goToBack() { @@ -49,6 +51,9 @@ function goToBack() {
49 } 51 }
50 } 52 }
51 53
  54 +/**
  55 + * 输入优惠券码兑换优惠券
  56 + */
52 $newCoupon.on('submit', function() { 57 $newCoupon.on('submit', function() {
53 let $this = $(this); 58 let $this = $(this);
54 59
@@ -58,7 +63,7 @@ $newCoupon.on('submit', function() { @@ -58,7 +63,7 @@ $newCoupon.on('submit', function() {
58 } 63 }
59 $.ajax({ 64 $.ajax({
60 method: 'POST', 65 method: 'POST',
61 - url: '/cart/index/new/couponSearch', 66 + url: '/cart/index/new/useCouponCode',
62 data: $this.serialize() 67 data: $this.serialize()
63 }).then(function(res) { 68 }).then(function(res) {
64 if (res.message) { 69 if (res.message) {
@@ -66,12 +71,9 @@ $newCoupon.on('submit', function() { @@ -66,12 +71,9 @@ $newCoupon.on('submit', function() {
66 } 71 }
67 if (res.code === 200) { 72 if (res.code === 200) {
68 tip.show('优惠券可用'); 73 tip.show('优惠券可用');
69 -  
70 - // 实付金额发生变化,使用有货币为0  
71 - orderInfo('yohoCoin', 0);  
72 - orderInfo('couponCode', res.data.coupon_code);  
73 - orderInfo('couponName', res.data.coupon_title);  
74 - goToBack(); 74 + setTimeout(function() {
  75 + location.reload();
  76 + }, 500);
75 } 77 }
76 }).fail(function() { 78 }).fail(function() {
77 tip.show('网络错误'); 79 tip.show('网络错误');
@@ -79,34 +81,20 @@ $newCoupon.on('submit', function() { @@ -79,34 +81,20 @@ $newCoupon.on('submit', function() {
79 return false; 81 return false;
80 }); 82 });
81 83
82 -$couponList.on('touchstart', '.employ-main', function() {  
83 - let $this = $(this);  
84 -  
85 - $this.siblings().removeClass('focus');  
86 - $this.addClass('focus');  
87 -}).on('touchend touchcancel', '.employ-main', function() {  
88 - let $this = $(this);  
89 -  
90 - $this.siblings().removeClass('focus');  
91 - $this.removeClass('focus');  
92 -});  
93 -  
94 -$('body').on('touchend', '.not-use', function() {  
95 - orderInfo('couponCode', null);  
96 - orderInfo('couponName', null);  
97 -  
98 - // 实付金额发生变化,使用有货币为0  
99 - orderInfo('yohoCoin', 0); 84 +/**
  85 + * 使用优惠券 TODO
  86 + */
  87 +$useCoupon.on('click', function() {
  88 + orderInfo('coupon_code');
100 goToBack(); 89 goToBack();
101 }); 90 });
102 91
103 -  
104 -$newCoupon.find('input').on('input', function() {  
105 - if ($(this).val() !== '') {  
106 - $newCoupon.find('.submit').css('background', '#444');  
107 - } else {  
108 - $newCoupon.find('.submit').css('background', '#b0b0b0');  
109 - } 92 +/**
  93 + * 不使用优惠券 TODO
  94 + */
  95 +$notUseCoupon.on('click', function() {
  96 + orderInfo('coupon_code', null);
  97 + goToBack();
110 }); 98 });
111 99
112 function getCouponHandle(allCoupons) { 100 function getCouponHandle(allCoupons) {
@@ -141,20 +129,13 @@ function getCouponHandle(allCoupons) { @@ -141,20 +129,13 @@ function getCouponHandle(allCoupons) {
141 129
142 $.ajax({ 130 $.ajax({
143 method: 'POST', 131 method: 'POST',
144 - url: '/cart/index/new/couponSearch', 132 + url: '/cart/index/new/useCouponCode',
145 data: { 133 data: {
146 couponCode: couponCode 134 couponCode: couponCode
147 } 135 }
148 }).then(function(res) { 136 }).then(function(res) {
149 if (res.code === 200) { 137 if (res.code === 200) {
150 -  
151 - // tip.show('优惠券可用');  
152 - orderInfo('couponCode', res.data.coupon_code);  
153 - orderInfo('couponName', res.data.coupon_title);  
154 -  
155 - // 实付金额发生变化,使用有货币为0  
156 - orderInfo('yohoCoin', 0);  
157 - goToBack(); 138 + tip.show('这边逻辑要改!');
158 } else if (res.message) { 139 } else if (res.message) {
159 tip.show(res.message); 140 tip.show(res.message);
160 } 141 }
@@ -169,8 +150,6 @@ function getCouponHandle(allCoupons) { @@ -169,8 +150,6 @@ function getCouponHandle(allCoupons) {
169 $('#couponUnavailable').append(conponNotAvaliableTmpl({ 150 $('#couponUnavailable').append(conponNotAvaliableTmpl({
170 notAvailableCoupons: notAvailableCoupons 151 notAvailableCoupons: notAvailableCoupons
171 })); 152 }));
172 - window.rePosFooter();  
173 -  
174 } 153 }
175 154
176 function getCouponDate() { 155 function getCouponDate() {
@@ -196,9 +175,3 @@ function getCouponDate() { @@ -196,9 +175,3 @@ function getCouponDate() {
196 } 175 }
197 176
198 getCouponDate(); 177 getCouponDate();
199 -  
200 -// $(window).scroll(function() {  
201 -// if ($(window).scrollTop() + $(window).height() > $('body').height() * 0.9) {  
202 -// getCouponDate();  
203 -// }  
204 -// });