...
|
...
|
@@ -29,10 +29,14 @@ var colTxt = { |
|
|
hover: '取消收藏'
|
|
|
};
|
|
|
|
|
|
var oldtatus = {
|
|
|
txt: '已领取',
|
|
|
html: '<a class="coupon-btn">去使用</a>'
|
|
|
};
|
|
|
|
|
|
var $saleReturn = $('#saleReturn');
|
|
|
|
|
|
var dialogTpl = require('hbs/product/coupon-dialog.hbs');
|
|
|
var couponItemTpl = require('hbs/product/coupon-item.hbs');
|
|
|
|
|
|
bindEvent.add(function() {
|
|
|
var $imgShow = $('#img-show'),
|
...
|
...
|
@@ -61,6 +65,8 @@ bindEvent.add(function() { |
|
|
|
|
|
var maxStock = -1; // 记录当前选中的颜色-尺码的库存量,若为-1,代表未选择尺码
|
|
|
|
|
|
var brandDomain = $('.home').attr('href');
|
|
|
|
|
|
var Alert = require('../common/dialog').Alert;
|
|
|
|
|
|
var Dialog = require('../common/dialog').Dialog;
|
...
|
...
|
@@ -69,65 +75,78 @@ bindEvent.add(function() { |
|
|
|
|
|
var $couponItem = $('.coupon-item');
|
|
|
|
|
|
var $coupons = $couponItem.map(function(i) {
|
|
|
var $this = $(this);
|
|
|
|
|
|
return {
|
|
|
couponId: $this.data('id'),
|
|
|
couponName: $this.data('name'),
|
|
|
amount: $this.data('amount'),
|
|
|
acquireStatus: $this.data('status'),
|
|
|
rule4ShortName: $this.data('rule'),
|
|
|
i: i
|
|
|
};
|
|
|
}).get();
|
|
|
|
|
|
var newCoupons = $.grep($coupons, function(val) {
|
|
|
return val.acquireStatus === 1;
|
|
|
});
|
|
|
function openCouponDialog(e) {
|
|
|
var $coupons = $couponItem.map(function(i) {
|
|
|
var $this = $(this);
|
|
|
|
|
|
return {
|
|
|
couponId: $this.data('id'),
|
|
|
couponName: $this.data('name'),
|
|
|
amount: $this.data('amount'),
|
|
|
acquireStatus: $this.data('status'),
|
|
|
rule4ShortName: $this.data('rule'),
|
|
|
i: i
|
|
|
};
|
|
|
}).get();
|
|
|
|
|
|
var newCoupons = $.grep($coupons, function(val) {
|
|
|
return val.acquireStatus === 1;
|
|
|
});
|
|
|
|
|
|
var oldCoupons = $.grep($coupons, function(val) {
|
|
|
return val.acquireStatus === 3;
|
|
|
});
|
|
|
var oldCoupons = $.grep($coupons, function(val) {
|
|
|
return val.acquireStatus === 3;
|
|
|
});
|
|
|
|
|
|
var json = {
|
|
|
newList: {
|
|
|
title: '可以领取的券',
|
|
|
body: newCoupons
|
|
|
var couponData = {
|
|
|
newList: {
|
|
|
title: '可以领取的券',
|
|
|
body: newCoupons
|
|
|
|
|
|
},
|
|
|
oldList: {
|
|
|
title: '已领取的券',
|
|
|
body: oldCoupons
|
|
|
}
|
|
|
};
|
|
|
},
|
|
|
oldList: {
|
|
|
title: '已领取的券',
|
|
|
body: oldCoupons
|
|
|
}
|
|
|
};
|
|
|
|
|
|
$moreCoupon.on('click', function() {
|
|
|
new Dialog({
|
|
|
content: dialogTpl({coupon: json}),
|
|
|
content: dialogTpl({coupon: couponData}),
|
|
|
className: 'coupon-big'
|
|
|
}).show();
|
|
|
});
|
|
|
|
|
|
$(document).on('click', '.status', function() {
|
|
|
var $this = $(this);
|
|
|
var id = $this.data('id');
|
|
|
var i = $this.data('i');
|
|
|
var status = $this.data('status');
|
|
|
|
|
|
console.log(i);
|
|
|
e.stopPropagation();
|
|
|
}
|
|
|
|
|
|
$this.data('status', 9);
|
|
|
});
|
|
|
|
|
|
function imgShow(src) {
|
|
|
$imgShow.attr('src', src);
|
|
|
}
|
|
|
|
|
|
function getCouponAsync(cid) {
|
|
|
var uid = getUid(); // eslint-disable-line
|
|
|
|
|
|
if (!uid || !cid) {
|
|
|
return $.Deferred().reject().promise(); // eslint-disable-line
|
|
|
}
|
|
|
|
|
|
return $.getJSON('/product/detail/coupon', {
|
|
|
couponId: cid
|
|
|
}).then(function(result) {
|
|
|
var defer = $.Deferred(); //eslint-disable-line
|
|
|
result.code === 200 ? defer.resolve() : defer.reject();
|
|
|
return defer.promise();
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function jumpUrl(url) {
|
|
|
window.location.href = url;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取当前选择的商品数目
|
|
|
* @return [Number]
|
|
|
*/
|
|
|
|
|
|
function getNum() {
|
|
|
return +$num.text();
|
|
|
}
|
...
|
...
|
@@ -557,6 +576,29 @@ bindEvent.add(function() { |
|
|
}
|
|
|
}());
|
|
|
|
|
|
// 打开优惠券列表
|
|
|
$moreCoupon.on('click', openCouponDialog);
|
|
|
|
|
|
// 优惠券的领取
|
|
|
$(document).on('click', '.status', function() {
|
|
|
var $this = $(this);
|
|
|
var couponId = $this.data('id');
|
|
|
var status = $this.data('status');
|
|
|
var i = $this.data('i');
|
|
|
var $item = $($couponItem.get(i));
|
|
|
|
|
|
switch (status) {
|
|
|
case 1:
|
|
|
getCouponAsync(couponId).then(function() {
|
|
|
$this.find('.coupon-status').text(oldtatus.txt);
|
|
|
$this.find('.coupon-go').empty().append(oldtatus.html);
|
|
|
$item.data('status', 3);
|
|
|
});
|
|
|
break;
|
|
|
default:
|
|
|
jumpUrl(brandDomain);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
// yas
|
...
|
...
|
|