Authored by 梁志锋

Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop

@@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
6 6
7 var $ = require('jquery'), 7 var $ = require('jquery'),
8 Handlebars = require('yoho.handlebars'), 8 Handlebars = require('yoho.handlebars'),
  9 + Hammer = require('yoho.hammer'),
9 ellipsis = require('mlellipsis'), 10 ellipsis = require('mlellipsis'),
10 loading = require('../plugin/loading'), 11 loading = require('../plugin/loading'),
11 tip = require('../plugin/tip'), 12 tip = require('../plugin/tip'),
@@ -17,14 +18,13 @@ var page = 1, @@ -17,14 +18,13 @@ var page = 1,
17 18
18 var conponTmpl = Handlebars.compile($('#tmpl-coupon').html()), 19 var conponTmpl = Handlebars.compile($('#tmpl-coupon').html()),
19 conponNotAvaliableTmpl = Handlebars.compile($('#tmpl-coupon-not-avaliable').html()), 20 conponNotAvaliableTmpl = Handlebars.compile($('#tmpl-coupon-not-avaliable').html()),
20 - $newCoupon = $('#new-coupon'); 21 + $newCoupon = $('#new-coupon'),
  22 + $couponList = $('#coupon-list');
21 23
22 var winH = $(window).height(); 24 var winH = $(window).height();
23 25
24 require('../common'); 26 require('../common');
25 27
26 -// conponNotAvaliableTmpl = Handlebars.compile($('#tmpl-coupon-not-avaliable').html()),  
27 -  
28 function fixedLayOut() { 28 function fixedLayOut() {
29 var $null = $('.null'), 29 var $null = $('.null'),
30 navH = $('.nav-title').height(), 30 navH = $('.nav-title').height(),
@@ -53,13 +53,14 @@ $newCoupon.on('submit', function() { @@ -53,13 +53,14 @@ $newCoupon.on('submit', function() {
53 url: '/cart/index/couponSearch', 53 url: '/cart/index/couponSearch',
54 data: $this.serialize() 54 data: $this.serialize()
55 }).then(function(res) { 55 }).then(function(res) {
  56 + if (res.message) {
  57 + tip.show(res.message);
  58 + }
56 if (res.code === 200) { 59 if (res.code === 200) {
57 tip.show('优惠券可用'); 60 tip.show('优惠券可用');
58 orderInfo('couponCode', res.data.coupon_code); 61 orderInfo('couponCode', res.data.coupon_code);
59 orderInfo('couponName', res.data.coupon_title); 62 orderInfo('couponName', res.data.coupon_title);
60 window.location.href = '/cart/index/orderEnsure'; 63 window.location.href = '/cart/index/orderEnsure';
61 - } else {  
62 - tip.show(res.message || '网络错误');  
63 } 64 }
64 }).fail(function() { 65 }).fail(function() {
65 tip.show('网络错误'); 66 tip.show('网络错误');
@@ -67,30 +68,7 @@ $newCoupon.on('submit', function() { @@ -67,30 +68,7 @@ $newCoupon.on('submit', function() {
67 return false; 68 return false;
68 }); 69 });
69 70
70 -$('#coupon-list').on('click', '.employ-main', function() {  
71 - var $this = $(this);  
72 - var couponCode = $this.data('coupon-code');  
73 -  
74 - $.ajax({  
75 - method: 'POST',  
76 - url: '/cart/index/couponSearch',  
77 - data: {  
78 - couponCode: couponCode  
79 - }  
80 - }).then(function(res) {  
81 - if (res.code === 200) {  
82 -  
83 - //tip.show('优惠券可用');  
84 - orderInfo('couponCode', res.data.coupon_code);  
85 - orderInfo('couponName', res.data.coupon_title);  
86 - window.location.href = '/cart/index/orderEnsure';  
87 - } else {  
88 - tip.show(res.message || '网络错误');  
89 - }  
90 - }).fail(function() {  
91 - tip.show('网络错误');  
92 - });  
93 -}).on('touchstart', '.employ-main', function() { 71 +$couponList.on('touchstart', '.employ-main', function() {
94 var $this = $(this); 72 var $this = $(this);
95 73
96 $this.siblings().removeClass('focus'); 74 $this.siblings().removeClass('focus');
@@ -164,10 +142,37 @@ function getCouponHandle(coupons) { @@ -164,10 +142,37 @@ function getCouponHandle(coupons) {
164 } 142 }
165 }); 143 });
166 144
167 - $('#coupon-list').append(conponTmpl({ 145 + $couponList.append(conponTmpl({
168 coupons: coupons 146 coupons: coupons
169 - })); 147 + })).find('.employ-main').each(function(i, elem) {
  148 + var employHammer = new Hammer(elem);
170 149
  150 + employHammer.on('tap', function(e) {
  151 + var $this = $(e.srcEvent.currentTarget);
  152 + var couponCode = $this.data('coupon-code');
  153 +
  154 + $.ajax({
  155 + method: 'POST',
  156 + url: '/cart/index/couponSearch',
  157 + data: {
  158 + couponCode: couponCode
  159 + }
  160 + }).then(function(res) {
  161 + if (res.message) {
  162 + tip.show(res.message);
  163 + }
  164 + if (res.code === 200) {
  165 +
  166 + //tip.show('优惠券可用');
  167 + orderInfo('couponCode', res.data.coupon_code);
  168 + orderInfo('couponName', res.data.coupon_title);
  169 + window.location.href = '/cart/index/orderEnsure';
  170 + }
  171 + }).fail(function() {
  172 + tip.show('网络错误');
  173 + });
  174 + });
  175 + });
171 176
172 if (notAvailableCoupons.length) { 177 if (notAvailableCoupons.length) {
173 $('.not-avaliable-coupon-line').show(); 178 $('.not-avaliable-coupon-line').show();
@@ -201,14 +206,14 @@ function getCouponDate() { @@ -201,14 +206,14 @@ function getCouponDate() {
201 } 206 }
202 }).then(getCouponHandle).fail(function() { 207 }).then(getCouponHandle).fail(function() {
203 page -= 1; 208 page -= 1;
204 - tip.show('加载优惠券失败'); 209 +
  210 + // tip.show('加载优惠券失败');
205 }).always(function() { 211 }).always(function() {
206 isGetData = false; 212 isGetData = false;
207 loading.hideLoadingMask(); 213 loading.hideLoadingMask();
208 }); 214 });
209 } 215 }
210 216
211 -  
212 getCouponDate(); 217 getCouponDate();
213 218
214 // $(window).scroll(function() { 219 // $(window).scroll(function() {