Authored by lijing

重构完成

'use strict';
const index = (req, res ,next) => {
const headerModel = require('../../../doraemon/models/header'); // 头部model
const indexModel = require('../models/ticketsConfirm');
const ticketsConfirm = (req, res) => {
let headerData = headerModel.setNav({
navTitle: '确认订单'
});
... ... @@ -8,15 +11,56 @@ const index = (req, res ,next) => {
let responseData = {
pageHeader: headerData,
module: 'cart',
page: 'index-editor',
page: 'tickets-confirm',
title: '确认订单',
pageFooter: true,
localCss: true
// pageFooter: true,
localCss: true,
navBtn: false
};
let params = {
uid: req.user.uid,
productSku: req.body.productSku,
buyNumber: req.body.buyNumber,
useYohoCoin: 0,
yohoCoinMode: true
};
res.render('ticketsConfirm', responseData);
}
indexModel.ticketsConfirm(params).then(result => {
res.render('ticketsConfirm', Object.assign(responseData, result));
});
};
const submitTicket = (req, res) => {
let params = {
uid: req.user.uid,
productSku: req.body.productSku,
buyNumber: req.body.buyNumber,
mobile: req.body.mobile,
useYohoCoin: req.body.useYohoCoin
};
indexModel.submitTicket(params).then(result => {
res.json(result);
});
};
const checkTickets = (req, res) => {
let params = {
uid: req.user.uid,
productSku: req.body.productSku,
buyNumber: req.body.buyNumber,
useYohoCoin: 0
};
indexModel.checkTickets(params).then(result => {
res.json(result);
});
};
module.exports = {
index
};
\ No newline at end of file
ticketsConfirm,
submitTicket,
checkTickets
};
... ...
'use strict';
const api = global.yoho.API;
const helpers = global.yoho.helpers;
// 展览票(单日票)skn
const SINGLE_TICKETS_SKN = 51335912;
const checkTickets = (param) => {
return api.get('', {
method: 'app.shopping.ticket',
uid: param.uid,
product_sku: param.productSku,
buy_number: param.buyNumber,
use_yoho_coin: param.useYohoCoin,
yoho_coin_mode: param.yohoCoinMode ? param.yohoCoinMode : 0
}, {
code: 200
}).then((result) => {
return result;
});
};
const yohoCoinCompute = ($orderCompute) => {
let $yohoCoinData = {
totalYohoCoinNum: 0,
yohoCoin: 0,
useYohoCoin: 0,
yohoCoinClick: 0,
yohoCoinMsg: '',
yoho_coin_pay_rule: []
};
if (!$orderCompute || !$orderCompute.yoho_coin_pay_rule) {
return $yohoCoinData;
}
$yohoCoinData = {
totalYohoCoinNum: $orderCompute.total_yoho_coin_num ? $orderCompute.total_yoho_coin_num : 0,
yohoCoin: $orderCompute.yoho_coin ? $orderCompute.yoho_coin : 0,
useYohoCoin: $orderCompute.use_yoho_coin ? $orderCompute.use_yoho_coin : 0,
yohoCoinClick: 0,
yohoCoinMsg: '',
yoho_coin_pay_rule: $orderCompute.yoho_coin_pay_rule
};
if ($yohoCoinData.totalYohoCoinNum < 100) {
$yohoCoinData.yohoCoinMsg = '共' + $yohoCoinData.totalYohoCoinNum +
'有货币,满' + $orderCompute.yoho_coin_pay_rule.num_limit + '可用';
} else if ($yohoCoinData.useYohoCoin > 0 || $yohoCoinData.yohoCoin > 0) {
$yohoCoinData.yohoCoinMsg = '可抵¥' +
$yohoCoinData.useYohoCoin > 0 ? $yohoCoinData.useYohoCoin : $yohoCoinData.yohoCoin;
$yohoCoinData.yohoCoinClick = 1;
} else {
$yohoCoinData.yohoCoinMsg = '不满足有货币使用条件';
}
return $yohoCoinData;
};
const ticketsConfirm = (param) => {
return api.all([
checkTickets(param)
]).then((result) => {
let resu = {
goods: [],
productSku: param.productSku,
buyNumber: param.buyNumber,
orderEnsurePage: true
};
if (result && result[0] && result[0].data) {
let bulid = [];
result[0].data.goods_list.forEach((val) => {
bulid.push({
tickets: true,
id: val.product_sku,
thumb: helpers.image(val.goods_images, 120, 160),
name: val.product_name,
color: val.color_name,
size: val.product_skn == SINGLE_TICKETS_SKN ? '' : val.size_name,
count: val.buy_number,
price: parseInt(val.last_price).toFixed(2)
});
resu.goods = bulid;
});
resu.cartPayData = result[0].data.shopping_cart_data.promotion_formula_list;
resu.price = parseInt(result[0].data.shopping_cart_data.last_order_amount).toFixed(2);
resu.yohoCoinCompute = yohoCoinCompute(result[0].data.shopping_cart_data);
}
return resu;
});
};
// 门票下单
const submitTicket = (param) => {
return api.get('', {
method: 'app.shopping.submitTicket',
uid: param.uid,
product_sku: param.productSku,
buy_number: param.buyNumber,
mobile: param.mobile,
use_yoho_coin: 0,
qhy_union: ''
}, {
code: 200
}).then((result) => {
return result;
});
};
module.exports = {
ticketsConfirm,
submitTicket,
checkTickets
};
... ...
... ... @@ -64,6 +64,12 @@ router.post('/index/new/giftinfo', indexController.giftinfo); // 获取购物车
router.get('/home/orders/paynew', authMW, payController.payCenter);
// 门票确认
router.get('/index/ticketsConfirm', authMW, ticketsConfirmController.index);
router.post('/index/ticketsConfirm', authMW, ticketsConfirmController.ticketsConfirm);
// 门票下单
router.post('/index/submitTicket', ticketsConfirmController.submitTicket);
// 添加门票
router.post('/index/checkTickets', ticketsConfirmController.checkTickets);
module.exports = router;
... ...
... ... @@ -25,7 +25,7 @@
<section class="block goods-bottom">
{{#each goods}}
{{> me/order/good}}
{{> tickets/good}}
{{/each}}
</section>
... ... @@ -35,7 +35,7 @@
<li class="coin" data-yoho-coin="{{yohoCoinCompute.yohoCoin}}" data-yoho-coin-click={{yohoCoinCompute.yohoCoinClick}}>
<span class="title">有货币</span>
<span class="desc msg">{{yohoCoinCompute.yohoCoinMsg}}</span>
<span class="yoho-coin-help"></span>
<span class="yoho-coin-help">?</span>
{{#if yohoCoinCompute.useYohoCoin}}
<span class="coin-check">
<i class="iconfont checkbox icon-cb-radio"></i>
... ...
<div class="order-good" data-id="{{id}}" data-skn="{{skn}}">
<div class="thumb-wrap">
{{#if link}}
<a href="{{link}}"><img class="thumb lazy" data-original="{{thumb}}"></a>
{{else}}
<img class="thumb lazy" data-original="{{thumb}}">
{{/if}}
<p class="tag{{#if gift}} gift-tag{{/if}}{{#if advanceBuy}} advance-buy-tag{{/if}}"></p>
</div>
<div class="deps">
<p class="name row">{{name}}</p>
<p class="row">
{{#if color}}
<span class="color">
{{#if tickets}}日期{{else}}颜色{{/if}}:{{color}}
</span>
{{/if}}
{{#if size}}
<span class="size">
{{#if tickets}}区域{{else}}尺码{{/if}}:{{size}}
</span>
{{/if}}
</p>
{{#if isLimitSkn}}
<p class="limit">不支持7天无理由退换货</p>
{{/if}}
<p class="row price-wrap">
<span class="price">
¥{{price}}
</span>
<span class="count">
×{{count}}
</span>
{{#if appearDate}}
<span class="appear-date">上市期:{{appearDate}}</span>
{{/if}}
</p>
</div>
</div>
\ No newline at end of file
... ...
/**
* 订单确认
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/11/12
*/
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload'),
cookie = require('yoho-cookie');
var tip = require('../plugin/tip'),
loading = require('../plugin/loading'),
order = require('./order-info'),
richTip = require('../plugin/rich-tip');
var $invoice = $('.invoice'),
$couponUse = $('.coupon-use.used'),
$addressWrap = $('.address-wrap'),
$coinCheck = $('.coin-check'),
$coinLi = $('li.coin'),
$subBlock = $('.sub-block'),
$ticketsMobile = $('#mobile'),
payType,
queryString = $.queryString(),
orderInfo = order.orderInfo,
isSubmiting,
dispatchInfo,
total,
isTickets = $('#ticketsPage').val(),
productSku = $('#productSku').val(),
buyNumber = $('#buyNumber').val(),
headerTop = $('#yoho-header').outerHeight(),
isYohoCoinClick = $coinLi.data('yoho-coin-click') * 1, // 判断有货币是否可以单击
addressTop = $('.address-wrap').outerHeight();
var orderCont = cookie.get('order-info') && JSON.parse(cookie.get('order-info'));
var invoiceCont = {
7: '服装',
1: '图书',
9: '配件',
11: '日用品',
3: '办公用品',
6: '体育用品',
10: '数码产品'
},
invoicesType = {
1: '纸质',
2: '电子'
};
require('../common');
lazyLoad();
// 初始化发票信息
function invoiceInit() {
if (orderCont.invoiceType) {
$('.invoice-type').text(invoiceCont[orderCont.invoiceType] + '(' + invoicesType[orderCont.invoicesType] + ')');
} else {
$('.invoice-type').text('服装(电子)');
}
}
function getQueryParam() {
var queryArray = location.search.substr(1).split('&'),
i,
subArr = [],
obj = {};
for (i = 0; i < queryArray.length; i++) {
subArr = queryArray[i].split('=');
obj[subArr[0]] = subArr[1];
subArr = [];
}
return obj;
}
function isLimitGood() {
return getQueryParam().limitproductcode;
}
if (window.getUid() !== orderInfo('uid')) {
order.init();
window.location.reload();
}
if ($couponUse.data('name') !== orderInfo('couponName')) {
orderInfo('couponCode', null);
orderInfo('couponName', null);
}
// 来自购物车的链接默认不使用优惠券
if (document.referrer && document.referrer.indexOf('/cart/index/index') !== -1) {
orderInfo('couponCode', null);
orderInfo('couponName', null);
}
isLimitGood() && (function() {
var a = [];
var data = getQueryParam();
data.type = 'limitcode';
a.push(data);
orderInfo('skuList', JSON.stringify(a));
orderInfo('limitUrlSufix', location.search);
}());
if (queryString.cartType || queryString.carttype || !orderInfo('cartType')) {
orderInfo('cartType', queryString.cartType || queryString.carttype || 'ordinary');
}
// function dispacthTapEvt(e) {
// var $cur = $(e.target).closest('li');
// if ($cur.length === 0 || $cur.hasClass('chosed')) {
// return;
// }
// $cur.siblings('li.chosed').removeClass('chosed');
// $cur.addClass('chosed');
// }
$('.checkbox').on('touchstart', function(e) {
var $this = $(this);
if ($(e.target).closest('.coin-check').length && !isYohoCoinClick) {
return true;
}
if ($this.hasClass('icon-cb-radio')) {
$this.removeClass('icon-cb-radio').addClass('icon-radio');
return;
}
if ($this.hasClass('icon-radio')) {
$this.removeClass('icon-radio').addClass('icon-cb-radio');
}
});
$invoice.on('touchend', '.checkbox', function() {
var $this = $(this);
if ($this.hasClass('icon-cb-radio')) {
$invoice.addClass('focus');
orderInfo('invoiceText', '');
orderInfo('invoiceType', '7');
orderInfo('receiverMobile', $('.user-mobile').val());
orderInfo('invoicesType', '2');
orderInfo('invoiceTitle', '个人');
}
if ($this.hasClass('icon-radio')) {
$invoice.removeClass('focus');
orderInfo('invoiceText', null);
orderInfo('invoiceType', null);
orderInfo('receiverMobile', null);
orderInfo('invoicesType', null);
orderInfo('invoiceTitle', null);
}
orderCont = cookie.get('order-info') && JSON.parse(cookie.get('order-info'));
invoiceInit();
});
function updateDeliverId(id) {
var $moreJit = $('.more-jit a').get(0),
url;
if ($moreJit) {
url = $moreJit.href;
} else {
return;
}
if (url.indexOf('deliveryId') < 0) {
$moreJit.href = url + '&deliveryId=' + id;
} else {
$moreJit.href = url.replace(/deliveryId=(\d)/, 'deliveryId=' + id);
}
}
function orderCompute() {
var yohoCoin = orderInfo('yohoCoin'),
deliverId = orderInfo('deliveryId'),
data = {
cartType: orderInfo('cartType') || 'ordinary',
deliveryId: orderInfo('deliveryId'),
paymentType: orderInfo('paymentType'),
couponCode: orderInfo('couponCode'),
yohoCoin: yohoCoin,
skuList: isLimitGood() ? orderInfo('skuList') : undefined
};
// 门票
if (isTickets) {
data = {
type: 'tickets',
productSku: productSku,
buyNumber: buyNumber,
yohoCoin: yohoCoin
};
}
loading.showLoadingMask();
$.ajax({
method: 'POST',
url: '/cart/index/new/orderCompute',
data: data
}).then(function(res) {
if ($.type(res) !== 'object') {
window.location.reload();
} else {
if (typeof res.last_order_amount !== undefined) {
res.last_order_amount = (+res.last_order_amount).toFixed(2);
}
if (res.use_yoho_coin) {
$coinCheck.find('em').html('- ¥ ' + res.use_yoho_coin);
$coinCheck.find('em').show();
}
$coinLi.find('.msg').html(res.yohoCoinCompute.yohoCoinMsg);
isYohoCoinClick = res.yohoCoinCompute.yohoCoinClick * 1;
$('.coin').data('yoho-coin', res.yohoCoinCompute.yohoCoin);
total = '';
if (res.promotion_formula_list) {
$.each(res.promotion_formula_list, function(index, value) {
total += '<li>' +
'<p>' + value.promotion + '</p>' +
'<span>' + value.promotion_amount + '</span>' +
'</li>';
});
$('.price-cost span').html('¥' + res.last_order_amount);
$('.bill span').html('¥' + res.last_order_amount);
$('.total').html(total);
}
updateDeliverId(deliverId);
}
}).fail(function() {
window.location.reload();
}).always(function() {
loading.hideLoadingMask();
});
}
function submitOrder() {
var invoiceText = $invoice.find('[name="invoice-title"]').val() || orderInfo('invoiceText'),
msg = $('#msg').find('input').val() || orderInfo('msg');
if (isSubmiting) {
return false;
}
// if (orderInfo('invoice')) {
// if (!invoiceText) {
// tip.show('请输入发票抬头');
// return;
// }
// if (invoiceText.length > 30) {
// tip.show('发票抬头不得超过30个汉字');
// return;
// }
// }
if (msg) {
if (msg.length > 40) {
tip.show('留言不得超过40个汉字');
return;
}
}
loading.showLoadingMask();
isSubmiting = true;
$.ajax({
method: 'POST',
url: '/cart/index/new/orderSub',
data: {
addressId: orderInfo('addressId'),
cartType: orderInfo('cartType') || 'ordinary',
deliveryId: orderInfo('deliveryId'),
deliveryTimeId: orderInfo('deliveryTimeId'),
invoiceText: orderInfo('invoice') ? invoiceText : null,
invoiceType: orderInfo('invoice') ? ($invoice.find('.invoice-type').val() ||
orderInfo('invoiceType')) : null,
msg: msg,
paymentTypeId: orderInfo('paymentTypeId'),
paymentType: orderInfo('paymentType'), // 支付方式
couponCode: orderInfo('couponCode'),
yohoCoin: orderInfo('yohoCoin'),
skuList: isLimitGood() ? orderInfo('skuList') : undefined
}
}).then(function(res) {
var url;
if (!res) {
tip.show('系统繁忙,请稍后再试!');
return;
}
if (res.code === 200) {
if (payType === 2) {
// 货到付款的进入订单页面
url = '/home/orderDetail?order_code=' + res.data.order_code;
} else {
url = '/home/orders/paynew?order_code=' + res.data.order_code;
}
/* tar add 161116 */
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_SC_TOPAY_CLICK',
param: JSON.stringify({
C_ID: window._ChannelVary[cookie.get('_Channel')],
ORDER_CODE: res.data.order_code + '',
PRD_NUM: $('#goods-num').val(),
ORDER_AMOUNT: res.data.order_amount
})
}, true);
}
/* tar add 190222 */
if (window._fxcmd) {
window._fxcmd.push(['trackOrder', {
oid: res.data.order_code,
otp: res.data.order_amount,
u_info: cookie.get('_UID'),
u_type: cookie.get('_isNewUser') ? 1 : 0
}, []]);
}
cookie.remove(['order-info', 'activity-info']);
window.location.href = url;
} else if (res.code === 409) {
richTip.show(res.message, res.buttons);
} else if (res.message) {
tip.show(res.message);
}
}).fail(function() {
tip.show('系统繁忙,请稍后再试!');
}).always(function() {
isSubmiting = false;
loading.hideLoadingMask();
});
}
// 界面点击,状态存 cookie
if (!orderInfo('addressId')) {
orderInfo('addressId', $addressWrap.data('id'));
}
$('.delivery-id').on('touchend', 'li', function() {
orderInfo('deliveryId', $(this).data('id'));
// 实付金额发生变化,使用有货币为0
orderInfo('yohoCoin', 0);
$('.coin').find('.checkbox').removeClass('icon-cb-radio').addClass('icon-radio');
orderCompute();
});
$('.payment-type').on('touchend', 'li', function() {
var $paymentType = $('.icon-cb-radio', this);
orderInfo('paymentTypeId', $paymentType.data('id')); // 支付方式id
orderInfo('paymentType', $paymentType.data('payment-type')); // 支付方式
});
$('.dispatch-time').on('touchend', 'li', function() {
orderInfo('deliveryTimeId', $(this).data('id'));
});
$('.yoho-coin-help-dialog-bg, .yoho-coin-footer').on('touchend', function(e) {
e.preventDefault();
$('.yoho-coin-help-dialog-bg').addClass('hide');
$('.yoho-coin-help-dialog').addClass('hide');
});
$('.coin').on('touchend', function(e) {
var $this = $(this);
if ($(e.target).closest('.yoho-coin-help').length) {
$('.yoho-coin-help-dialog-bg').removeClass('hide');
$('.yoho-coin-help-dialog').removeClass('hide');
return true;
}
if ($(e.target).closest('.coin-check').length <= 0) {
return false;
}
if (!isYohoCoinClick) {
return true;
}
if ($this.find('.checkbox').hasClass('icon-cb-radio')) {
orderInfo('yohoCoin', $this.data('yoho-coin'));
$this.find('.can-use').hide();
} else {
orderInfo('yohoCoin', 0);
$this.find('.coin-check em').hide();
$this.find('.can-use').show();
$this.find('.used').hide();
}
orderCompute();
});
$invoice.on('touchend', '.checkbox', function(e) {
var $this = $(this);
orderInfo('invoice', $this.hasClass('icon-cb-radio'));
e.preventDefault();
e.stopPropagation();
});
$invoice.find('[name="invoice-title"]').on('blur', function() {
orderInfo('invoiceText', $(this).val());
}).end().find('.invoice-type').on('change', function() {
orderInfo('invoiceType', $(this).val());
});
$('#msg').find('textarea').on('blur', function() {
orderInfo('msg', $(this).val());
});
$('form').on('submit', function() {
return false;
});
// xwg 2016/3/21 13:22
$('.dispatch').on('touchend', 'h3', function() {
if ($(this).siblings('ul').is(':hidden')) {
$('.dispatch h3').removeClass('border-none');
$(this).addClass('border-none');
$('.down').removeClass('hide');
$('.up').addClass('hide');
$('.up', this).removeClass('hide');
$('.down', this).addClass('hide');
$('.dispatch ul').hide();
$(this).siblings('ul').show();
} else {
$(this).removeClass('border-none');
$('.down', this).removeClass('hide');
$('.up', this).addClass('hide');
$(this).siblings('ul').hide();
}
});
$subBlock.on('touchstart', 'li', function() {
// 送货时间提示语li,不响应事件
if ($(this).hasClass('dispatch-time-info')) {
return true;
}
$.each($(this).parents('ul').find('i'), function() {
$(this).parents('ul').find('i').removeClass('icon-cb-radio').addClass('icon-radio');
});
let self = $(this);
setTimeout(function() {
self.parents('ul').hide();
}, 300);
$('.down').removeClass('hide');
$('.up').addClass('hide');
$('.dispatch h3').removeClass('border-none');
dispatchInfo = $(this).find('span').html();
$(this).parents('.sub-block').find('h3 span').html(dispatchInfo);
if ($(this).find('i').hasClass('icon-cb-radio')) {
$(this).find('i').addClass('icon-radio');
} else if ($(this).find('i').hasClass('icon-radio')) {
$(this).find('i').addClass('icon-cb-radio');
}
});
$('.bill a').on('touchstart', function() {
var $paymentType;
if (isTickets) {
ticketsConfirm(); // eslint-disable-line
return;
}
$paymentType = $('.payment-type .icon-cb-radio');
orderInfo('paymentTypeId', $paymentType.data('id')); // 支付方式id
orderInfo('paymentType', $paymentType.data('payment-type')); // 支付方式
payType = $paymentType.data('payment-type');
submitOrder();
});
function phoneHidden(phone) {
phone = phone || '';
return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
}
$('.info-phone').html(phoneHidden($('.info-phone').html()));
if (orderInfo('address') && orderInfo('address').is_support === 'N') {
orderInfo('deliveryId', $('.delivery-id .icon-cb-radio').data('id'));
orderCompute();
}
// 电子票下单
function ticketsConfirm() {
var data = {
productSku: productSku,
buyNumber: buyNumber,
mobile: $ticketsMobile.val(),
useYohoCoin: orderInfo('yohoCoin')
};
if (!$ticketsMobile.val()) {
tip.show('手机号必填');
return;
}
$.ajax({
url: '/cart/index/submitTicket',
type: 'POST',
dataType: 'json',
data: data,
success: function(ticket) {
// 下单成功调整支付页面
if (ticket.code === 200) {
window.location.href = '/home/orders/paynew?order_code=' + ticket.data.order_code;
} else {
tip.show(ticket.message);
}
},
error: function() {
tip.show('网络异常~');
}
});
}
// 校验手机号
$ticketsMobile.blur(function() {
var reg = /^[0123456789]{1,30}$/;
var mobile = $ticketsMobile.val();
if (!reg.test(mobile)) {
tip.show('手机号码不正确!');
}
});
// 初始化发票信息内容
invoiceInit();
$(window).scroll(function() {
if ($(this).scrollTop() >= (headerTop + addressTop)) {
$('.address-bottom').show();
} else {
$('.address-bottom').hide();
}
});
... ...
/**
* 订单确认
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/11/12
*/
var $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload'),
cookie = require('yoho-cookie');
var tip = require('../plugin/tip'),
loading = require('../plugin/loading'),
order = require('./order-info'),
richTip = require('../plugin/rich-tip');
var $invoice = $('.invoice'),
$couponUse = $('.coupon-use.used'),
$addressWrap = $('.address-wrap'),
$coinCheck = $('.coin-check'),
$coinLi = $('li.coin'),
$subBlock = $('.sub-block'),
$ticketsMobile = $('#mobile'),
payType,
queryString = $.queryString(),
orderInfo = order.orderInfo,
isSubmiting,
dispatchInfo,
total,
isTickets = $('#ticketsPage').val(),
productSku = $('#productSku').val(),
buyNumber = $('#buyNumber').val(),
headerTop = $('#yoho-header').outerHeight(),
isYohoCoinClick = $coinLi.data('yoho-coin-click') * 1, // 判断有货币是否可以单击
addressTop = $('.address-wrap').outerHeight();
var orderCont = cookie.get('order-info') && JSON.parse(cookie.get('order-info'));
var invoiceCont = {
7: '服装',
1: '图书',
9: '配件',
11: '日用品',
3: '办公用品',
6: '体育用品',
10: '数码产品'
},
invoicesType = {
1: '纸质',
2: '电子'
};
require('../common');
lazyLoad();
// 初始化发票信息
function invoiceInit() {
if (orderCont.invoiceType) {
$('.invoice-type').text(invoiceCont[orderCont.invoiceType] + '(' + invoicesType[orderCont.invoicesType] + ')');
} else {
$('.invoice-type').text('服装(电子)');
}
}
function getQueryParam() {
var queryArray = location.search.substr(1).split('&'),
i,
subArr = [],
obj = {};
for (i = 0; i < queryArray.length; i++) {
subArr = queryArray[i].split('=');
obj[subArr[0]] = subArr[1];
subArr = [];
}
return obj;
}
function isLimitGood() {
return getQueryParam().limitproductcode;
}
if (window.getUid() !== orderInfo('uid')) {
order.init();
window.location.reload();
}
if ($couponUse.data('name') !== orderInfo('couponName')) {
orderInfo('couponCode', null);
orderInfo('couponName', null);
}
// 来自购物车的链接默认不使用优惠券
if (document.referrer && document.referrer.indexOf('/cart/index/index') !== -1) {
orderInfo('couponCode', null);
orderInfo('couponName', null);
}
isLimitGood() && (function() {
var a = [];
var data = getQueryParam();
data.type = 'limitcode';
a.push(data);
orderInfo('skuList', JSON.stringify(a));
orderInfo('limitUrlSufix', location.search);
}());
if (queryString.cartType || queryString.carttype || !orderInfo('cartType')) {
orderInfo('cartType', queryString.cartType || queryString.carttype || 'ordinary');
}
// function dispacthTapEvt(e) {
// var $cur = $(e.target).closest('li');
// if ($cur.length === 0 || $cur.hasClass('chosed')) {
// return;
// }
// $cur.siblings('li.chosed').removeClass('chosed');
// $cur.addClass('chosed');
// }
$('.checkbox').on('touchstart', function(e) {
var $this = $(this);
if ($(e.target).closest('.coin-check').length && !isYohoCoinClick) {
return true;
}
if ($this.hasClass('icon-cb-radio')) {
$this.removeClass('icon-cb-radio').addClass('icon-radio');
return;
}
if ($this.hasClass('icon-radio')) {
$this.removeClass('icon-radio').addClass('icon-cb-radio');
}
});
$invoice.on('touchend', '.checkbox', function() {
var $this = $(this);
if ($this.hasClass('icon-cb-radio')) {
$invoice.addClass('focus');
orderInfo('invoiceText', '');
orderInfo('invoiceType', '7');
orderInfo('receiverMobile', $('.user-mobile').val());
orderInfo('invoicesType', '2');
orderInfo('invoiceTitle', '个人');
}
if ($this.hasClass('icon-radio')) {
$invoice.removeClass('focus');
orderInfo('invoiceText', null);
orderInfo('invoiceType', null);
orderInfo('receiverMobile', null);
orderInfo('invoicesType', null);
orderInfo('invoiceTitle', null);
}
orderCont = cookie.get('order-info') && JSON.parse(cookie.get('order-info'));
invoiceInit();
});
function updateDeliverId(id) {
var $moreJit = $('.more-jit a').get(0),
url;
if ($moreJit) {
url = $moreJit.href;
} else {
return;
}
if (url.indexOf('deliveryId') < 0) {
$moreJit.href = url + '&deliveryId=' + id;
} else {
$moreJit.href = url.replace(/deliveryId=(\d)/, 'deliveryId=' + id);
}
}
function orderCompute() {
var yohoCoin = orderInfo('yohoCoin'),
deliverId = orderInfo('deliveryId'),
data = {
cartType: orderInfo('cartType') || 'ordinary',
deliveryId: orderInfo('deliveryId'),
paymentType: orderInfo('paymentType'),
couponCode: orderInfo('couponCode'),
yohoCoin: yohoCoin,
skuList: isLimitGood() ? orderInfo('skuList') : undefined
};
// 门票
if (isTickets) {
data = {
type: 'tickets',
productSku: productSku,
buyNumber: buyNumber,
yohoCoin: yohoCoin
};
}
loading.showLoadingMask();
$.ajax({
method: 'POST',
url: '/cart/index/new/orderCompute',
data: data
}).then(function(res) {
if ($.type(res) !== 'object') {
window.location.reload();
} else {
if (typeof res.last_order_amount !== undefined) {
res.last_order_amount = (+res.last_order_amount).toFixed(2);
}
if (res.use_yoho_coin) {
$coinCheck.find('em').html('- ¥ ' + res.use_yoho_coin);
$coinCheck.find('em').show();
}
$coinLi.find('.msg').html(res.yohoCoinCompute.yohoCoinMsg);
isYohoCoinClick = res.yohoCoinCompute.yohoCoinClick * 1;
$('.coin').data('yoho-coin', res.yohoCoinCompute.yohoCoin);
total = '';
if (res.promotion_formula_list) {
$.each(res.promotion_formula_list, function(index, value) {
total += '<li>' +
'<p>' + value.promotion + '</p>' +
'<span>' + value.promotion_amount + '</span>' +
'</li>';
});
$('.price-cost span').html('¥' + res.last_order_amount);
$('.bill span').html('¥' + res.last_order_amount);
$('.total').html(total);
}
updateDeliverId(deliverId);
}
}).fail(function() {
window.location.reload();
}).always(function() {
loading.hideLoadingMask();
});
}
function submitOrder() {
var invoiceText = $invoice.find('[name="invoice-title"]').val() || orderInfo('invoiceText'),
msg = $('#msg').find('input').val() || orderInfo('msg');
if (isSubmiting) {
return false;
}
// if (orderInfo('invoice')) {
// if (!invoiceText) {
// tip.show('请输入发票抬头');
// return;
// }
// if (invoiceText.length > 30) {
// tip.show('发票抬头不得超过30个汉字');
// return;
// }
// }
if (msg) {
if (msg.length > 40) {
tip.show('留言不得超过40个汉字');
return;
}
}
loading.showLoadingMask();
isSubmiting = true;
$.ajax({
method: 'POST',
url: '/cart/index/new/orderSub',
data: {
addressId: orderInfo('addressId'),
cartType: orderInfo('cartType') || 'ordinary',
deliveryId: orderInfo('deliveryId'),
deliveryTimeId: orderInfo('deliveryTimeId'),
invoiceText: orderInfo('invoice') ? invoiceText : null,
invoiceType: orderInfo('invoice') ? ($invoice.find('.invoice-type').val() ||
orderInfo('invoiceType')) : null,
msg: msg,
paymentTypeId: orderInfo('paymentTypeId'),
paymentType: orderInfo('paymentType'), // 支付方式
couponCode: orderInfo('couponCode'),
yohoCoin: orderInfo('yohoCoin'),
skuList: isLimitGood() ? orderInfo('skuList') : undefined
}
}).then(function(res) {
var url;
if (!res) {
tip.show('系统繁忙,请稍后再试!');
return;
}
if (res.code === 200) {
if (payType === 2) {
// 货到付款的进入订单页面
url = '/home/orderDetail?order_code=' + res.data.order_code;
} else {
url = '/home/orders/paynew?order_code=' + res.data.order_code;
}
/* tar add 161116 */
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_SC_TOPAY_CLICK',
param: JSON.stringify({
C_ID: window._ChannelVary[cookie.get('_Channel')],
ORDER_CODE: res.data.order_code + '',
PRD_NUM: $('#goods-num').val(),
ORDER_AMOUNT: res.data.order_amount
})
}, true);
}
/* tar add 190222 */
if (window._fxcmd) {
window._fxcmd.push(['trackOrder', {
oid: res.data.order_code,
otp: res.data.order_amount,
u_info: cookie.get('_UID'),
u_type: cookie.get('_isNewUser') ? 1 : 0
}, []]);
}
cookie.remove(['order-info', 'activity-info']);
window.location.href = url;
} else if (res.code === 409) {
richTip.show(res.message, res.buttons);
} else if (res.message) {
tip.show(res.message);
}
}).fail(function() {
tip.show('系统繁忙,请稍后再试!');
}).always(function() {
isSubmiting = false;
loading.hideLoadingMask();
});
}
// 界面点击,状态存 cookie
if (!orderInfo('addressId')) {
orderInfo('addressId', $addressWrap.data('id'));
}
$('.delivery-id').on('touchend', 'li', function() {
orderInfo('deliveryId', $(this).data('id'));
// 实付金额发生变化,使用有货币为0
orderInfo('yohoCoin', 0);
$('.coin').find('.checkbox').removeClass('icon-cb-radio').addClass('icon-radio');
orderCompute();
});
$('.payment-type').on('touchend', 'li', function() {
var $paymentType = $('.icon-cb-radio', this);
orderInfo('paymentTypeId', $paymentType.data('id')); // 支付方式id
orderInfo('paymentType', $paymentType.data('payment-type')); // 支付方式
});
$('.dispatch-time').on('touchend', 'li', function() {
orderInfo('deliveryTimeId', $(this).data('id'));
});
$('.yoho-coin-help-dialog-bg, .yoho-coin-footer').on('touchend', function(e) {
e.preventDefault();
$('.yoho-coin-help-dialog-bg').addClass('hide');
$('.yoho-coin-help-dialog').addClass('hide');
});
$('.coin').on('touchend', function(e) {
var $this = $(this);
if ($(e.target).closest('.yoho-coin-help').length) {
$('.yoho-coin-help-dialog-bg').removeClass('hide');
$('.yoho-coin-help-dialog').removeClass('hide');
return true;
}
if ($(e.target).closest('.coin-check').length <= 0) {
return false;
}
if (!isYohoCoinClick) {
return true;
}
if ($this.find('.checkbox').hasClass('icon-cb-radio')) {
orderInfo('yohoCoin', $this.data('yoho-coin'));
$this.find('.can-use').hide();
} else {
orderInfo('yohoCoin', 0);
$this.find('.coin-check em').hide();
$this.find('.can-use').show();
$this.find('.used').hide();
}
orderCompute();
});
$invoice.on('touchend', '.checkbox', function(e) {
var $this = $(this);
orderInfo('invoice', $this.hasClass('icon-cb-radio'));
e.preventDefault();
e.stopPropagation();
});
$invoice.find('[name="invoice-title"]').on('blur', function() {
orderInfo('invoiceText', $(this).val());
}).end().find('.invoice-type').on('change', function() {
orderInfo('invoiceType', $(this).val());
});
$('#msg').find('textarea').on('blur', function() {
orderInfo('msg', $(this).val());
});
$('form').on('submit', function() {
return false;
});
// xwg 2016/3/21 13:22
$('.dispatch').on('touchend', 'h3', function() {
if ($(this).siblings('ul').is(':hidden')) {
$('.dispatch h3').removeClass('border-none');
$(this).addClass('border-none');
$('.down').removeClass('hide');
$('.up').addClass('hide');
$('.up', this).removeClass('hide');
$('.down', this).addClass('hide');
$('.dispatch ul').hide();
$(this).siblings('ul').show();
} else {
$(this).removeClass('border-none');
$('.down', this).removeClass('hide');
$('.up', this).addClass('hide');
$(this).siblings('ul').hide();
}
});
$subBlock.on('touchstart', 'li', function() {
// 送货时间提示语li,不响应事件
if ($(this).hasClass('dispatch-time-info')) {
return true;
}
$.each($(this).parents('ul').find('i'), function() {
$(this).parents('ul').find('i').removeClass('icon-cb-radio').addClass('icon-radio');
});
let self = $(this);
setTimeout(function() {
self.parents('ul').hide();
}, 300);
$('.down').removeClass('hide');
$('.up').addClass('hide');
$('.dispatch h3').removeClass('border-none');
dispatchInfo = $(this).find('span').html();
$(this).parents('.sub-block').find('h3 span').html(dispatchInfo);
if ($(this).find('i').hasClass('icon-cb-radio')) {
$(this).find('i').addClass('icon-radio');
} else if ($(this).find('i').hasClass('icon-radio')) {
$(this).find('i').addClass('icon-cb-radio');
}
});
$('.bill a').on('touchstart', function() {
var $paymentType;
if (isTickets) {
ticketsConfirm(); // eslint-disable-line
return;
}
$paymentType = $('.payment-type .icon-cb-radio');
orderInfo('paymentTypeId', $paymentType.data('id')); // 支付方式id
orderInfo('paymentType', $paymentType.data('payment-type')); // 支付方式
payType = $paymentType.data('payment-type');
submitOrder();
});
function phoneHidden(phone) {
phone = phone || '';
return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
}
$('.info-phone').html(phoneHidden($('.info-phone').html()));
if (orderInfo('address') && orderInfo('address').is_support === 'N') {
orderInfo('deliveryId', $('.delivery-id .icon-cb-radio').data('id'));
orderCompute();
}
// 电子票下单
function ticketsConfirm() {
var data = {
productSku: productSku,
buyNumber: buyNumber,
mobile: $ticketsMobile.val(),
useYohoCoin: orderInfo('yohoCoin')
};
if (!$ticketsMobile.val()) {
tip.show('手机号必填');
return;
}
$.ajax({
url: '/cart/index/submitTicket',
type: 'POST',
dataType: 'json',
data: data,
success: function(ticket) {
// 下单成功调整支付页面
if (ticket.code === 200) {
window.location.href = '/home/orders/paynew?order_code=' + ticket.data.order_code;
} else {
tip.show(ticket.message);
}
},
error: function() {
tip.show('网络异常~');
}
});
}
// 校验手机号
$ticketsMobile.blur(function() {
var reg = /^[0123456789]{1,30}$/;
var mobile = $ticketsMobile.val();
if (!reg.test(mobile)) {
tip.show('手机号码不正确!');
}
});
// 初始化发票信息内容
invoiceInit();
$(window).scroll(function() {
if ($(this).scrollTop() >= (headerTop + addressTop)) {
$('.address-bottom').show();
} else {
$('.address-bottom').hide();
}
});
require('./order-ensure');
\ No newline at end of file
... ...
require('cart/tickets-confirm.page.css');
require('./order-ensure');
... ...
@import "order-ensure";
@import "index";
... ...