gift-advance.js
2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* 赠品/加价购
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/23
*/
let $ = require('yoho-jquery'),
ellipsis = require('yoho-mlellipsis'),
lazyLoad = require('yoho-jquery-lazyload'),
Hammer = require('yoho-hammer'),
tip = require('plugin/tip'),
loading = require('plugin/loading'),
chosePanel = require('common/chose-panel-new');
let $page = $('.gift-advance-page'),
queryString = $.queryString();
require('common');
lazyLoad($('.lazy'));
ellipsis.init();
function getProductInfo(skn, promotionId) {
loading.showLoadingMask();
$.post('/cart/index/new/giftinfo', {
skn: skn,
promotionId: promotionId
}).then(function(data) {
if (!data) {
tip.show('网络错误');
return;
}
chosePanel.show({
data,
disableNum: true
}).then(result => {
if (result && result.sku) {
let goodData,
url;
if (queryString.edit) {
url = '/cart/index/new/modifyPriceGift';
goodData = {
new_product_sku: result.sku.skuId,
new_product_skn: result.skn,
buy_number: result.buyNum,
selected: true,
promotionId,
isEdit: 1
};
} else {
url = '/cart/index/add';
goodData = {
productSku: result.sku.skuId,
new_product_skn: skn,
buyNumber: result.buyNum,
promotionId
};
}
$.ajax({
method: 'POST',
url: url,
data: goodData
}).done(function(res) {
if (res && res.code === 200) {
window.location.href = '/cart/index/index';
}
}).fail(function() {
tip.show('网络出了点问题~');
});
}
}, () =>{});
}, function() {
tip.show('网络错误');
}).always(function() {
loading.hideLoadingMask();
});
}
$page.find('.chose').each(function(i, elem) {
let choseHammer = new Hammer(elem);
choseHammer.on('tap', function(e) {
let $this = $(e.target),
id = $this.closest('.gift-advance-good').data('id'),
promotionId = $this.closest('.advance-block').data('promotion-id');
getProductInfo(id, promotionId);
});
});
setTimeout(function() {
$('.gift-advance-good .name').each(function() {
this.mlellipsis(2);
});
}, 0);