...
|
...
|
@@ -10,56 +10,37 @@ |
|
|
// 异步渲染的模板统一插入 #chose-panel ,兼容页面多个选择框
|
|
|
|
|
|
var $ = require('jquery'),
|
|
|
Handlebars = require('yoho.handlebars'),
|
|
|
tip = require('../plugin/tip'),
|
|
|
loading = require('../plugin/loading');
|
|
|
|
|
|
var panelTmpl,
|
|
|
$chosePanel = $('#chose-panel'),
|
|
|
var $chosePanel = $('#chose-panel'),
|
|
|
$num,
|
|
|
$chosed,
|
|
|
|
|
|
// re = /\d+/,
|
|
|
leftNum,
|
|
|
confirming,
|
|
|
hasChooseColor = false,
|
|
|
hasChooseSize = false,
|
|
|
curColorIndex,
|
|
|
curSizeIndex,
|
|
|
$curSizeRow,
|
|
|
$curSizeBlock = null,
|
|
|
$sizeRowList = $('.size-list ul');
|
|
|
|
|
|
// 读取模板
|
|
|
$.get('/cart/index/giftinfoTpl', function(html) {
|
|
|
if (!html) {
|
|
|
tip.show('网络错误');
|
|
|
return;
|
|
|
}
|
|
|
panelTmpl = Handlebars.compile(html);
|
|
|
}).fail(function() {
|
|
|
tip.show('网络错误');
|
|
|
});
|
|
|
hasChooseColor,
|
|
|
hasChooseSize,
|
|
|
$curSizeBlock,
|
|
|
$sizeRowList;
|
|
|
|
|
|
//初始化购物车面板显示
|
|
|
function init() {
|
|
|
var $firstRow;
|
|
|
|
|
|
//$colorList = $('.chose-panel .color-list ul>li');
|
|
|
//$sizeList = $('.chose-panel .size-list ul>li');
|
|
|
//firstColorId = $colorList.eq(0).data('id');
|
|
|
//$sizeList.each(function() {
|
|
|
// colorIndex = $(this).data('colorid');
|
|
|
//
|
|
|
// if (colorIndex === firstColorId) {
|
|
|
// $(this).removeClass('hide');
|
|
|
// }
|
|
|
//});
|
|
|
|
|
|
var $firstRow = $sizeRowList.eq(0);
|
|
|
|
|
|
hasChooseColor = false;
|
|
|
hasChooseSize = false;
|
|
|
$curSizeBlock = null;
|
|
|
$sizeRowList = $('.size-list ul');
|
|
|
$firstRow = $sizeRowList.eq(0);
|
|
|
$firstRow.toggleClass('hide');
|
|
|
$curSizeRow = $firstRow;
|
|
|
}
|
|
|
init();
|
|
|
|
|
|
function checkColorSizeNum() {
|
|
|
if (!hasChooseColor && !hasChooseSize) {
|
...
|
...
|
@@ -75,11 +56,9 @@ function checkColorSizeNum() { |
|
|
return true;
|
|
|
}
|
|
|
|
|
|
init();
|
|
|
|
|
|
function show(data) {
|
|
|
if (data) {
|
|
|
$chosePanel.html(panelTmpl(data));
|
|
|
function show(html) {
|
|
|
if (html) {
|
|
|
$chosePanel.html(html);
|
|
|
init();
|
|
|
}
|
|
|
$('.chose-panel').show();
|
...
|
...
|
@@ -88,20 +67,55 @@ function show(data) { |
|
|
$num = $('#good-num');
|
|
|
}
|
|
|
|
|
|
////显示当前Panel
|
|
|
//function show() {
|
|
|
// $('.chose-panel').show();
|
|
|
//
|
|
|
// $('body').css('overflow', 'hidden');
|
|
|
// $num = $('#good-num');
|
|
|
//}
|
|
|
|
|
|
//隐藏当前Panel
|
|
|
function hide() {
|
|
|
$('.chose-panel').hide();
|
|
|
$('body').css('overflow', 'auto');
|
|
|
}
|
|
|
|
|
|
//修改加入购物车的文字和背景
|
|
|
function updateConformButtonClassAndText() {
|
|
|
$chosed = $('.chose-items').find('.chosed');
|
|
|
if (2 === $chosed.closest('.zero-stock').length) {
|
|
|
$('#chose-btn-sure').css('background-color', '#c0c0c0');
|
|
|
$('#chose-btn-sure').html('已售罄');
|
|
|
} else {
|
|
|
$('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
$('#chose-btn-sure').html('确定');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//重置颜色块的库存为0的样式
|
|
|
function resetColorZeroStock($siblingBlock) {
|
|
|
var numArray = ($curSizeBlock.data('numstr') + '').split('/'),
|
|
|
i;
|
|
|
|
|
|
if (!hasChooseSize) {
|
|
|
$siblingBlock.find('ul>li').each(function() {
|
|
|
$(this).removeClass('zero-stock');
|
|
|
if ('0' === $(this).data('num')) {
|
|
|
$(this).addClass('zero-stock');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
for (i = 0; i < numArray.length; i++) {
|
|
|
if ('0' === numArray[i]) {
|
|
|
$siblingBlock.find('.block').eq(i).addClass('zero-stock');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 选择了颜色切换商品图片
|
|
|
function changeGoodImgWhenClickColor() {
|
|
|
if (hasChooseColor && curColorIndex) {
|
|
|
$('.chose-panel').find('.thumb').addClass('hide').eq(curColorIndex).removeClass('hide');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
init();
|
|
|
|
|
|
$('.yoho-page').on('touchstart', '.chose-panel', function(e) {
|
|
|
var $cur = $(e.target);
|
|
|
|
...
|
...
|
@@ -143,11 +157,6 @@ $('.color-list').on('touchstart', '.block', function(e) { |
|
|
} else {
|
|
|
hasChooseColor = true;
|
|
|
|
|
|
//根据颜色切换图片
|
|
|
if ($this.closest('.block-list').hasClass('color-list')) {
|
|
|
$('.chose-panel').find('.thumb').addClass('hide').eq(index).removeClass('hide');
|
|
|
}
|
|
|
|
|
|
//把当前选中颜色对应的尺码那一行显示出来
|
|
|
$sizeRowList.addClass('hide');
|
|
|
$curSizeRow.removeClass('hide').addClass('show');
|
...
|
...
|
@@ -180,91 +189,22 @@ $('.color-list').on('touchstart', '.block', function(e) { |
|
|
curColorIndex = index;
|
|
|
|
|
|
// 设置按钮的样式和文字
|
|
|
$chosed = $('.chose-items').find('.chosed');
|
|
|
if (2 === $chosed.closest('.zero-stock').length) {
|
|
|
$('#chose-btn-sure').css('background-color', '#c0c0c0');
|
|
|
$('#chose-btn-sure').html('已售罄');
|
|
|
} else {
|
|
|
$('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
$('#chose-btn-sure').html('确定');
|
|
|
}
|
|
|
|
|
|
/**if ($chosed.length === 0) {
|
|
|
$this.closest('ul>li').each(function() {
|
|
|
$(this).removeClass('zero-stock');
|
|
|
if ('0' === $(this).data('num')) {
|
|
|
$(this).addClass('zero-stock');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$siblingBlock.find('ul>li').each(function() {
|
|
|
$(this).removeClass('zero-stock');
|
|
|
if ('0' === $(this).data('num')) {
|
|
|
$(this).addClass('zero-stock');
|
|
|
}
|
|
|
});
|
|
|
} else if ($chosed.length === 1 && $this.hasClass('chosed')) {
|
|
|
$sizeList.addClass('hide');
|
|
|
|
|
|
//切换尺码信息
|
|
|
$sizeList.each(function() {
|
|
|
colorIndex = $(this).data('colorid');
|
|
|
if (colorIndex === $this.data('id')) {
|
|
|
$(this).removeClass('hide');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
numArray = ($chosed.data('numstr') + '').split('/');
|
|
|
$siblingBlock.find('.block').removeClass('zero-stock');
|
|
|
for (i = 0; i < numArray.length; i++) {
|
|
|
if ('0' === numArray[i]) {
|
|
|
$siblingBlock.find('.block').eq(i).addClass('zero-stock');
|
|
|
}
|
|
|
}
|
|
|
} else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
|
|
|
$('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
$('#chose-btn-sure').html('确定');
|
|
|
|
|
|
$siblingBlock.find('ul>li').each(function() {
|
|
|
$(this).removeClass('zero-stock');
|
|
|
if ('0' === $(this).data('num')) {
|
|
|
$(this).addClass('zero-stock');
|
|
|
}
|
|
|
});
|
|
|
$that.find('.num .left-num').html('');
|
|
|
} else if ($chosed.length === 2) {
|
|
|
$siblingBlock.find('.block').removeClass('zero-stock');
|
|
|
for (i = 0; i < currentNumArray.length; i++) {
|
|
|
if ('0' === currentNumArray[i]) {
|
|
|
$siblingBlock.find('.block').eq(i).addClass('zero-stock');
|
|
|
}
|
|
|
}
|
|
|
numArray = ($siblingBlock.find('.chosed').data('numstr') + '').split('/');
|
|
|
$that.find('.num .left-num').html('剩余' + numArray[index] + '件');
|
|
|
if (2 === $chosed.closest('.zero-stock').length) {
|
|
|
$('#chose-btn-sure').css('background-color', '#c0c0c0');
|
|
|
$('#chose-btn-sure').html('已售罄');
|
|
|
} else {
|
|
|
$('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
$('#chose-btn-sure').html('确定');
|
|
|
}
|
|
|
}**/
|
|
|
updateConformButtonClassAndText();
|
|
|
|
|
|
// 修改颜色时修改商品图片
|
|
|
changeGoodImgWhenClickColor();
|
|
|
});
|
|
|
|
|
|
$('.size-list').on('touchstart', '.block', function(e) {
|
|
|
var $this = $(this),
|
|
|
$that = $(e.target).closest('.chose-items'),
|
|
|
index,
|
|
|
$colorChosed,
|
|
|
curGoodNum;
|
|
|
|
|
|
var $siblingBlock = $this.closest('.block-list').siblings(':first');
|
|
|
|
|
|
$this.siblings('.chosed').removeClass('chosed');
|
|
|
index = $this.index();
|
|
|
|
|
|
$colorChosed = $siblingBlock.find('.chosed');
|
|
|
$curSizeRow = $sizeRowList.eq(index);
|
|
|
|
|
|
// 当前尺码已经是选中状态,再点击时
|
...
|
...
|
@@ -275,11 +215,6 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
|
$('#left-num').val(0);
|
|
|
hasChooseSize = false;
|
|
|
|
|
|
// 去掉已经选中颜色的 数量为0的样式
|
|
|
if ($colorChosed.length > 0) {
|
|
|
$colorChosed.removeClass('zero-stock').addClass('zero-stock');
|
|
|
}
|
|
|
|
|
|
// 当前尺码不是选中状态,选中时
|
|
|
} else {
|
|
|
hasChooseSize = true;
|
...
|
...
|
@@ -296,10 +231,10 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
|
$that.find('.num .left-num').html('剩余' + curGoodNum + '件');
|
|
|
$('#left-num').val(curGoodNum);
|
|
|
} else {
|
|
|
$colorChosed.removeClass('zero-stock').addClass('zero-stock');
|
|
|
$that.find('.num .left-num').html('');
|
|
|
$('#left-num').val(0);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
$this.toggleClass('chosed');
|
...
|
...
|
@@ -307,78 +242,10 @@ $('.size-list').on('touchstart', '.block', function(e) { |
|
|
$curSizeBlock = $this;
|
|
|
|
|
|
// 设置按钮的样式和文字
|
|
|
$chosed = $('.chose-items').find('.chosed');
|
|
|
if (2 === $chosed.closest('.zero-stock').length) {
|
|
|
$('#chose-btn-sure').css('background-color', '#c0c0c0');
|
|
|
$('#chose-btn-sure').html('已售罄');
|
|
|
} else {
|
|
|
$('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
$('#chose-btn-sure').html('确定');
|
|
|
}
|
|
|
|
|
|
/**if ($chosed.length === 0) {
|
|
|
$this.closest('ul>li').each(function() {
|
|
|
$(this).removeClass('zero-stock');
|
|
|
if ('0' === $(this).data('num')) {
|
|
|
$(this).addClass('zero-stock');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$siblingBlock.find('ul>li').each(function() {
|
|
|
$(this).removeClass('zero-stock');
|
|
|
if ('0' === $(this).data('num')) {
|
|
|
$(this).addClass('zero-stock');
|
|
|
}
|
|
|
});
|
|
|
} else if ($chosed.length === 1 && $this.hasClass('chosed')) {
|
|
|
if ($this.closest('.block-list').hasClass('color-list')) {
|
|
|
|
|
|
$sizeList.addClass('hide');
|
|
|
|
|
|
//切换尺码信息
|
|
|
$sizeList.each(function() {
|
|
|
colorIndex = $(this).data('colorid');
|
|
|
if (colorIndex === $this.data('id')) {
|
|
|
$(this).removeClass('hide');
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
numArray = ($chosed.data('numstr') + '').split('/');
|
|
|
$siblingBlock.find('.block').removeClass('zero-stock');
|
|
|
for (i = 0; i < numArray.length; i++) {
|
|
|
if ('0' === numArray[i]) {
|
|
|
$siblingBlock.find('.block').eq(i).addClass('zero-stock');
|
|
|
}
|
|
|
}
|
|
|
} else if ($chosed.length === 1 && !$this.hasClass('chosed')) {
|
|
|
$('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
$('#chose-btn-sure').html('确定');
|
|
|
updateConformButtonClassAndText();
|
|
|
|
|
|
$siblingBlock.find('ul>li').each(function() {
|
|
|
$(this).removeClass('zero-stock');
|
|
|
if ('0' === $(this).data('num')) {
|
|
|
$(this).addClass('zero-stock');
|
|
|
}
|
|
|
});
|
|
|
$that.find('.num .left-num').html('');
|
|
|
} else if ($chosed.length === 2) {
|
|
|
$siblingBlock.find('.block').removeClass('zero-stock');
|
|
|
for (i = 0; i < currentNumArray.length; i++) {
|
|
|
if ('0' === currentNumArray[i]) {
|
|
|
$siblingBlock.find('.block').eq(i).addClass('zero-stock');
|
|
|
}
|
|
|
}
|
|
|
numArray = ($siblingBlock.find('.chosed').data('numstr') + '').split('/');
|
|
|
$that.find('.num .left-num').html('剩余' + numArray[index] + '件');
|
|
|
if (2 === $chosed.closest('.zero-stock').length) {
|
|
|
$('#chose-btn-sure').css('background-color', '#c0c0c0');
|
|
|
$('#chose-btn-sure').html('已售罄');
|
|
|
} else {
|
|
|
$('#chose-btn-sure').css('background-color', '#eb0313');
|
|
|
$('#chose-btn-sure').html('确定');
|
|
|
}
|
|
|
}**/
|
|
|
// 重置颜色块的样式
|
|
|
resetColorZeroStock($siblingBlock);
|
|
|
|
|
|
});
|
|
|
|
...
|
...
|
@@ -426,6 +293,7 @@ $('#chose-btn-sure').on('touchstart', function() { |
|
|
numInCart = $('.num-tag').html() - 0,
|
|
|
num = $num.val();
|
|
|
|
|
|
//颜色尺码没有选择
|
|
|
if (!checkColorSizeNum()) {
|
|
|
return;
|
|
|
}
|
...
|
...
|
|