|
|
|
|
|
var $ = require('yoho-jquery'),
|
|
|
dbClass = 'data-bind',
|
|
|
$chosePanel = $('.chose-panel');
|
|
|
|
|
|
module.exports = function(data, callback) {
|
|
|
render(data);
|
|
|
callback && callback();
|
|
|
};
|
|
|
function render(data) {
|
|
|
if (data.cartInfo) {
|
|
|
$chosePanel.removeClass(dbClass);
|
|
|
var cartInfo = data.cartInfo;
|
|
|
var thumbClone = $chosePanel.find('.thumb').remove();
|
|
|
for (var i = 0; i < cartInfo.thumbs.length; i++) {
|
|
|
var thumbEle = thumbClone.clone();
|
|
|
thumbEle.attr('src', cartInfo.thumbs[i].img)
|
|
|
if (i != 0) {
|
|
|
thumbEle.addClass('hide');
|
|
|
}
|
|
|
$chosePanel.find('.basic-info').prepend(thumbEle);
|
|
|
}
|
|
|
$chosePanel.find('.text-info>.name').text(cartInfo.name);
|
|
|
$chosePanel.find('.sale-price').text(cartInfo.salePrice);
|
|
|
if (!cartInfo.price) {
|
|
|
$chosePanel.find('.sale-price').addClass('no-price');
|
|
|
} else {
|
|
|
$chosePanel.find('.market-price').text(cartInfo.price).removeClass(dbClass);
|
|
|
}
|
|
|
var colorsClone = $chosePanel.find('.color-list>.size-row').remove();
|
|
|
var colorClone = colorsClone.find('li').remove();
|
|
|
for (var i = 0; i < cartInfo.colors.length; i++) {
|
|
|
var colors = cartInfo.colors[i];
|
|
|
var colorsEle = colorsClone.clone();
|
|
|
colorsEle.attr('id', colors.id).attr('data-index', i);
|
|
|
if (i != 0) {
|
|
|
colorsEle.addClass('hide');
|
|
|
}
|
|
|
for (var o = 0; o < colors.color.length; o++) {
|
|
|
var color = colors.color[o];
|
|
|
var colorEle = colorClone.clone();
|
|
|
colorEle.attr('data-num', color.colorNum).text(color.name);
|
|
|
if (color.chosed) {
|
|
|
colorEle.addClass('chosed');
|
|
|
}
|
|
|
if (!color.colorNum) {
|
|
|
colorEle.addClass('zero-stock');
|
|
|
}
|
|
|
colorsEle.append(colorEle);
|
|
|
}
|
|
|
$chosePanel.find('.color-list').append(colorsEle);
|
|
|
}
|
|
|
var sizesClone = $chosePanel.find('.size-list>.size-row').remove();
|
|
|
var sizeClone = sizesClone.find('li').remove();
|
|
|
for (var i = 0; i < cartInfo.sizes.length; i++) {
|
|
|
var sizes = cartInfo.sizes[i];
|
|
|
var sizesEle = sizesClone.clone();
|
|
|
if (i != 0) {
|
|
|
sizesEle.addClass('hide');
|
|
|
}
|
|
|
for (var o = 0; o < sizes.size.length; o++) {
|
|
|
var size = sizes.size[o];
|
|
|
var sizeEle = sizeClone.clone();
|
|
|
sizeEle.attr('data-num', size.sizeNum).attr('data-id', size.id).attr('data-skuid', size.skuId).text(size.name);
|
|
|
if (size.chosed) {
|
|
|
sizeEle.addClass('chosed');
|
|
|
}
|
|
|
if (!size.sizeNum) {
|
|
|
sizeEle.addClass('zero-stock');
|
|
|
}
|
|
|
sizesEle.append(sizeEle);
|
|
|
}
|
|
|
$chosePanel.find('.size-list').append(sizesEle);
|
|
|
}
|
|
|
}
|
|
|
if (data.tickets) {
|
|
|
$chosePanel.find('.infos').addClass('tickets-info');
|
|
|
$chosePanel.find('.color-list>.name').text('日期');
|
|
|
$chosePanel.find('.size-list>.name').text('区域');
|
|
|
} else {
|
|
|
$chosePanel.find('.color-list>.name').text('颜色');
|
|
|
$chosePanel.find('.size-list>.name').text('尺码');
|
|
|
}
|
|
|
if (data.single) {
|
|
|
$chosePanel.find('.size-list').addClass('hide');
|
|
|
}
|
|
|
if (data.cartInfo.promotionId) {
|
|
|
$('.btn-minus,.btn-plus').find('span').addClass('disabled');
|
|
|
}
|
|
|
$('#limitNum').val(data.limit);
|
|
|
$('#promotionId').val(promotionId);
|
|
|
$('#single').val(single);
|
|
|
$('#chose-btn-sure').text(data.tickets ? '立即购买' : '加入购物车')
|
|
|
|
|
|
} |
...
|
...
|
|