Authored by 梁志锋

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

... ... @@ -6,6 +6,7 @@
var $ = require('jquery'),
Handlebars = require('yoho.handlebars'),
Hammer = require('yoho.hammer'),
ellipsis = require('mlellipsis'),
loading = require('../plugin/loading'),
tip = require('../plugin/tip'),
... ... @@ -17,14 +18,13 @@ var page = 1,
var conponTmpl = Handlebars.compile($('#tmpl-coupon').html()),
conponNotAvaliableTmpl = Handlebars.compile($('#tmpl-coupon-not-avaliable').html()),
$newCoupon = $('#new-coupon');
$newCoupon = $('#new-coupon'),
$couponList = $('#coupon-list');
var winH = $(window).height();
require('../common');
// conponNotAvaliableTmpl = Handlebars.compile($('#tmpl-coupon-not-avaliable').html()),
function fixedLayOut() {
var $null = $('.null'),
navH = $('.nav-title').height(),
... ... @@ -53,13 +53,14 @@ $newCoupon.on('submit', function() {
url: '/cart/index/couponSearch',
data: $this.serialize()
}).then(function(res) {
if (res.message) {
tip.show(res.message);
}
if (res.code === 200) {
tip.show('优惠券可用');
orderInfo('couponCode', res.data.coupon_code);
orderInfo('couponName', res.data.coupon_title);
window.location.href = '/cart/index/orderEnsure';
} else {
tip.show(res.message || '网络错误');
}
}).fail(function() {
tip.show('网络错误');
... ... @@ -67,30 +68,7 @@ $newCoupon.on('submit', function() {
return false;
});
$('#coupon-list').on('click', '.employ-main', function() {
var $this = $(this);
var couponCode = $this.data('coupon-code');
$.ajax({
method: 'POST',
url: '/cart/index/couponSearch',
data: {
couponCode: couponCode
}
}).then(function(res) {
if (res.code === 200) {
//tip.show('优惠券可用');
orderInfo('couponCode', res.data.coupon_code);
orderInfo('couponName', res.data.coupon_title);
window.location.href = '/cart/index/orderEnsure';
} else {
tip.show(res.message || '网络错误');
}
}).fail(function() {
tip.show('网络错误');
});
}).on('touchstart', '.employ-main', function() {
$couponList.on('touchstart', '.employ-main', function() {
var $this = $(this);
$this.siblings().removeClass('focus');
... ... @@ -164,10 +142,37 @@ function getCouponHandle(coupons) {
}
});
$('#coupon-list').append(conponTmpl({
$couponList.append(conponTmpl({
coupons: coupons
}));
})).find('.employ-main').each(function(i, elem) {
var employHammer = new Hammer(elem);
employHammer.on('tap', function(e) {
var $this = $(e.srcEvent.currentTarget);
var couponCode = $this.data('coupon-code');
$.ajax({
method: 'POST',
url: '/cart/index/couponSearch',
data: {
couponCode: couponCode
}
}).then(function(res) {
if (res.message) {
tip.show(res.message);
}
if (res.code === 200) {
//tip.show('优惠券可用');
orderInfo('couponCode', res.data.coupon_code);
orderInfo('couponName', res.data.coupon_title);
window.location.href = '/cart/index/orderEnsure';
}
}).fail(function() {
tip.show('网络错误');
});
});
});
if (notAvailableCoupons.length) {
$('.not-avaliable-coupon-line').show();
... ... @@ -201,14 +206,14 @@ function getCouponDate() {
}
}).then(getCouponHandle).fail(function() {
page -= 1;
tip.show('加载优惠券失败');
// tip.show('加载优惠券失败');
}).always(function() {
isGetData = false;
loading.hideLoadingMask();
});
}
getCouponDate();
// $(window).scroll(function() {
... ...