...
|
...
|
@@ -10,6 +10,7 @@ |
|
|
// 增加init函数,异步请求的接口需要重新初始化一下选择列表
|
|
|
// 异步渲染的模板统一插入 #chose-panel ,兼容页面多个选择框
|
|
|
|
|
|
|
|
|
var $ = require('yoho-jquery'),
|
|
|
tip = require('../plugin/tip'),
|
|
|
loading = require('../plugin/loading');
|
...
|
...
|
@@ -37,7 +38,14 @@ var $chosePanel = $('#chose-panel'), |
|
|
$choseArea,
|
|
|
$cartBar,
|
|
|
$soonSoldOut = $('.soonSoldOut-tag'),
|
|
|
$yohoPage = $('.yoho-page');
|
|
|
$yohoPage = $('.yoho-page'),
|
|
|
|
|
|
// 门票 限购数量
|
|
|
ticketsLimit = $('#limitNum').val() || 0,
|
|
|
single = $('#single').val() || 0,
|
|
|
$productSku = $('#productSku'),
|
|
|
$buyNumber = $('#buyNumber'),
|
|
|
$buyNowForm = $('#buyNowForm');
|
|
|
|
|
|
// 购物车编辑标相关变量
|
|
|
var isEdit,
|
...
|
...
|
@@ -66,7 +74,6 @@ function init() { |
|
|
hasChooseColor = false;
|
|
|
hasChooseSize = false;
|
|
|
$curSizeBlock = null;
|
|
|
|
|
|
queryString = $.queryString();
|
|
|
$imgsThumb = $('.chose-panel').find('.thumb');
|
|
|
$choseArea = $('.chose-panel .main .chose-items');
|
...
|
...
|
@@ -126,7 +133,35 @@ function removePannel() { |
|
|
}
|
|
|
}
|
|
|
|
|
|
// 检查门票选择
|
|
|
function checkTickets() {
|
|
|
if (!hasChooseColor && !hasChooseSize) {
|
|
|
if (single) {
|
|
|
tip.show('请选择日期~');
|
|
|
} else {
|
|
|
tip.show('请选择日期和区域~');
|
|
|
}
|
|
|
return false;
|
|
|
} else if (!hasChooseColor) {
|
|
|
tip.show('请选择日期~');
|
|
|
return false;
|
|
|
} else if (!hasChooseSize && !single) {
|
|
|
tip.show('请选择区域~');
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
function checkColorSizeNum() {
|
|
|
|
|
|
if (ticketsLimit) {
|
|
|
|
|
|
// 门票
|
|
|
if (!checkTickets()) {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!hasChooseColor && !hasChooseSize) {
|
|
|
tip.show('请选择颜色和尺码~');
|
|
|
return false;
|
...
|
...
|
@@ -140,8 +175,6 @@ function checkColorSizeNum() { |
|
|
return true;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function show(html, cb) {
|
|
|
if (html) {
|
|
|
$chosePanel.html(html);
|
...
|
...
|
@@ -174,7 +207,7 @@ function updateConformButtonClassAndText() { |
|
|
$chosed = $allChoseItems.find('.chosed');
|
|
|
if ($chosed.closest('.zero-stock').length === 2) {
|
|
|
$('#chose-btn-sure').css('background-color', '#c0c0c0').html('已售罄');
|
|
|
} else if (limitProductCode) {
|
|
|
} else if (limitProductCode || ticketsLimit) {
|
|
|
$('#chose-btn-sure').css('background-color', '#eb0313').html('立即购买');
|
|
|
} else {
|
|
|
$('#chose-btn-sure').css('background-color', '#eb0313').html(isEdit ? '确认' : '加入购物车');
|
...
|
...
|
@@ -184,7 +217,14 @@ function updateConformButtonClassAndText() { |
|
|
// 显示剩余件数
|
|
|
function displayGoodNum(curGoodNum) {
|
|
|
|
|
|
// 数量大于0
|
|
|
// 门票限购
|
|
|
if (ticketsLimit) {
|
|
|
$allChoseItems.find('.num .left-num').html('限购' + ticketsLimit + '件');
|
|
|
$leftNum.val(curGoodNum);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 数量大于
|
|
|
if (curGoodNum > 0) {
|
|
|
if ($soonSoldOut.length > 0) {
|
|
|
$allChoseItems.find('.num .left-num').html('即将售罄');
|
...
|
...
|
@@ -204,6 +244,7 @@ function displayGoodNum(curGoodNum) { |
|
|
// 老的选中尺码去掉勾选,新的选中尺码加上勾选
|
|
|
function changeSizeChosed(newSizeIndex) {
|
|
|
var sizes,
|
|
|
queryString,
|
|
|
i;
|
|
|
|
|
|
if (curColorIndex && $curSizeBlock && $curSizeBlock.length > 0) {
|
...
|
...
|
@@ -247,6 +288,38 @@ function changeColorChosed(newColorIndex) { |
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
// 添加门票
|
|
|
function addTickets(productSku, buyNumber) {
|
|
|
var data = {
|
|
|
productSku: productSku,
|
|
|
buyNumber: buyNumber
|
|
|
};
|
|
|
|
|
|
// 校验电子票
|
|
|
$.ajax({
|
|
|
url: '/cart/index/checkTickets',
|
|
|
dataType: 'json',
|
|
|
data: data,
|
|
|
type: 'post',
|
|
|
success: function(addRestult) {
|
|
|
if (addRestult.code !== 200) {
|
|
|
if (addRestult.code === 401) {
|
|
|
window.location.href = '//m.yohobuy.com/signin.html?refer=' + window.location.href;
|
|
|
}
|
|
|
tip.show(addRestult.message);
|
|
|
} else {
|
|
|
$productSku.val(productSku);
|
|
|
$buyNumber.val(buyNumber);
|
|
|
$buyNowForm.submit();
|
|
|
}
|
|
|
},
|
|
|
error: function() {
|
|
|
tip.show('网络异常~');
|
|
|
}
|
|
|
|
|
|
});
|
|
|
}
|
|
|
|
|
|
init();
|
|
|
|
|
|
|
...
|
...
|
@@ -327,6 +400,20 @@ $yohoPage.on('touchstart', '.color-list .block', function() { |
|
|
|
|
|
// 设置按钮的样式和文字
|
|
|
updateConformButtonClassAndText();
|
|
|
|
|
|
// 展览票
|
|
|
if (ticketsLimit && single) {
|
|
|
// 选中日期
|
|
|
$curSizeBlock = $('.size-list .size-row .block').eq(index + 1);
|
|
|
$curSizeBlock.addClass('chosed');
|
|
|
|
|
|
// 显示剩余数量
|
|
|
displayGoodNum($curColorBlock.data('num'));
|
|
|
hasChooseSize = true;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
|
|
|
}).on('touchstart', '.size-list .block', function() {
|
|
|
var $this = $(this),
|
|
|
index,
|
...
|
...
|
@@ -391,7 +478,7 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (num === 1 || (leftNum - 0) === 0) {
|
|
|
if (num === 1 || leftNum - 0 === 0) {
|
|
|
tip.show('您选择的数量不能为零~');
|
|
|
return;
|
|
|
}
|
...
|
...
|
@@ -402,9 +489,10 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
|
|
|
|
|
$num.val(num - 1);
|
|
|
}).on('touchstart', '.btn-plus', function() {
|
|
|
var num = parseInt($num.val(), 10);
|
|
|
var num = parseInt($num.val(), 10),
|
|
|
maxTips = ticketsLimit ? '每人只可购买' + ticketsLimit + '张当日门票' : '您选择的数量超过了最大库存量~';
|
|
|
|
|
|
leftNum = $('#left-num').val();
|
|
|
leftNum = ticketsLimit || $('#left-num').val();
|
|
|
|
|
|
if (!checkColorSizeNum()) {
|
|
|
return;
|
...
|
...
|
@@ -416,7 +504,7 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
|
|
|
|
|
// TODO:库存数验证
|
|
|
if (num > leftNum - 1) {
|
|
|
tip.show('您选择的数量超过了最大库存量~');
|
|
|
tip.show(maxTips);
|
|
|
return;
|
|
|
}
|
|
|
$num.val(num + 1);
|
...
|
...
|
@@ -458,9 +546,18 @@ $yohoPage.on('touchstart', '.btn-minus', function() { |
|
|
return false;
|
|
|
}
|
|
|
|
|
|
confirming = true;
|
|
|
if (!ticketsLimit) {
|
|
|
confirming = true;
|
|
|
}
|
|
|
|
|
|
loading.showLoadingMask();
|
|
|
|
|
|
// 立即购买门票
|
|
|
if (ticketsLimit) {
|
|
|
addTickets(productSku, buyNumber);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 针对是否处于编辑模式设置不同的url和需要post的数据
|
|
|
if (isEdit) {
|
|
|
cartGoodData = {
|
...
|
...
|
|