Authored by 郝肖肖

合商品详情页分支门票

... ... @@ -136,7 +136,7 @@ const _getChannelResource = (params) => {
if (result && result.code === 200) {
return resourcesProcess(result.data.list);
} else {
logger.error('api index content resource code no 200');
logger.error('index resouce is not 200');
return result;
}
});
... ... @@ -156,7 +156,7 @@ const _getLeftNav = (choosed) => {
if (result && result.code === 200) {
return _processSideBar(result.data, choosed);
} else {
logger.error('api left nav code no 200');
logger.error('sidebar code is not 200');
return result;
}
});
... ... @@ -191,7 +191,7 @@ const _getChannelList = () => {
});
return Object.keys(list).length ? list : channelList;
} else {
logger.error('api channel select data code no 200');
logger.error('channel select code is not 200');
return channelList;
}
});
... ... @@ -210,7 +210,7 @@ const _getChannelBg = () => {
if (result && result.code === 200) {
return result.data.length && result.data[0] && result.data[0].data && result.data[0].data.list[0];
} else {
logger.error('api background img of channel select page code no 200');
logger.error('channel select background code is not 200');
return {
src: ''
};
... ...
... ... @@ -12,6 +12,8 @@ const comment = require('./consult-comment');
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const SINGLE_TICKETS_SKN = 51257524;// 展览票
/**
* 获取用户数据信息
* @param {[string]} uid
... ... @@ -150,6 +152,9 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => {
dest.goodsName = origin.productName;
// 是否是虚拟商品
dest.virtualGoods = origin.attribute * 1 === 3 ? true : false;
// 用户未登录时
if (!uid) {
let params = {};
... ... @@ -507,6 +512,31 @@ const _detailDataPkg = (origin, uid, vipLevel, ua) => {
dest.introUrl = '/product/detail/intro/' + origin.erpProductId;
dest.id = origin.id;
// 虚拟商品(门票)
if (origin.attribute * 1 === 3) {
dest.tickets = true;
dest.ticketsConfirm = helpers.urlFormat('/cart/index/ticketsConfirm');
// 展览票
if (origin.erpProductId * 1 === SINGLE_TICKETS_SKN) {
dest.single = true;
} else {
// 套票
dest.package = true;
}
// 购票限制
dest.cartInfo.limit = 4;
// 清空活动
dest.goodsDiscount = [];
// 来自登录页,自动弹出选择框
// if (isset($_GET['product_type']) && $_GET['product_type'] == 'ticket') {
// $result['showPannel'] = true;
// }
}
return dest;
};
... ...
... ... @@ -135,8 +135,7 @@
<a href="{{cartUrl}}" class="num-incart iconfont"><span class="num-tag hide"></span>&#xe62c;</a>
{{#if addToCartUrl}}
<!-- <a id="addtoCart" href="{{addToCartUrl}}" class="addto-cart">加入购物车</a> -->
<a id="addtoCart" href="javascript:;" class="addto-cart">加入购物车</a>
<a id="addtoCart" href="javascript:;" class="addto-cart">{{#if ../tickets}}立即购买{{else}}加入购物车{{/if}}</a>
{{/if}}
{{#if soldOut}}
... ... @@ -183,5 +182,16 @@
<input type="hidden" name="loginUrl" id="loginUrl" value="{{.}}">
{{/loginUrl}}
{{#if tickets}}
<form id="buyNowForm" method="post" action="{{ticketsConfirm}}">
<input type="hidden" name="productSku" id="productSku">
<input type="hidden" name="buyNumber" id="buyNumber">
</form>
{{/if}}
{{#if showPannel}}
<input type="hidden" id="showPannel" value="1">
{{/if}}
</div>
{{/ result}}
... ...
{{#cartInfo}}
<div class="chose-panel">
<div class="main">
<div class="infos">
<div class="infos {{#if ../tickets}}tickets-info{{/if}}">
<div class="basic-info" >
{{#thumbs}}
<img class="thumb {{#unless @first}}hide{{/unless}}" src={{image img 60 60}}>
... ... @@ -18,7 +18,7 @@
</div>
<div class="chose-items">
<div class="color-list block-list">
<span>颜色</span>
<span>{{#if ../tickets}}日期{{else}}颜色{{/if}}</span>
{{# colors}}
<ul id="{{id}}" data-index="{{@index}}" class="size-row clearfix {{#unless @first}}hide{{/unless}}">
{{# color}}
... ... @@ -29,8 +29,8 @@
</ul>
{{/ colors}}
</div>
<div class="size-list block-list">
<span>尺码</span>
<div class="size-list block-list {{#if ../single}}hide{{/if}}">
<span>{{#if ../tickets}}区域{{else}}尺码{{/if}}</span>
{{# sizes}}
<ul class="size-row clearfix {{#unless @first}}hide{{/unless}}">
{{# size}}
... ... @@ -41,7 +41,7 @@
</ul>
{{/ sizes}}
</div>
<p>
<div class="num">
<span>数量</span>
<div class="clearfix">
... ... @@ -55,13 +55,16 @@
</div>
<span class="left-num"></span>
<input id="left-num" type="hidden" value="0">
<input id="limitNum" type="hidden" value="{{limit}}">
</div>
</div>
</div>
<div class="btn-wrap">
<button id="chose-btn-sure" class="btn btn-sure">加入购物车</button>
<button id="chose-btn-sure" class="btn btn-sure">{{#if ../tickets}}立即购买{{else}}加入购物车{{/if}}</button>
</div>
</div>
</div>
{{/cartInfo}}
<input id="promotionId" type="hidden" value="{{promotionId}}">
<input id="single" type="hidden" value="{{single}}">
\ No newline at end of file
... ...
... ... @@ -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;
}
if (!ticketsLimit) {
confirming = true;
}
loading.showLoadingMask();
// 立即购买门票
if (ticketsLimit) {
addTickets(productSku, buyNumber);
return;
}
// 针对是否处于编辑模式设置不同的url和需要post的数据
if (isEdit) {
cartGoodData = {
... ...