Authored by 郭成尧

order-ensure-class-add

... ... @@ -8,6 +8,7 @@ const $ = require('yoho-jquery');
const lazyLoad = require('yoho-jquery-lazyload');
const cookie = require('yoho-cookie');
const qs = require('yoho-qs');
const OrderEnsure = require('./cartbuynow/order-ensure');
let tip = require('plugin/tip'),
loading = require('plugin/loading'),
... ... @@ -27,9 +28,6 @@ let $invoice = $('.invoice'),
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(),
... ... @@ -37,8 +35,7 @@ let $invoice = $('.invoice'),
delivery = 0,
$noPrintPrice = $('.no-print-price');
let $invoiceType = $('.invoice-type');
let $userMobile = $('.user-mobile');
new OrderEnsure(order);
require('common');
... ... @@ -47,78 +44,6 @@ lazyLoad();
// 存 COOKIE
orderInfo('product_sku', qs.product_sku);
function getQueryParam() {
let 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;
}
// 电子票下单
function _ticketsConfirm() {
let data = {
productSku: productSku,
buyNumber: buyNumber,
mobile: $ticketsMobile.val(),
useYohoCoin: orderInfo('use_yoho_coin')
};
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('网络异常~');
}
});
}
if (window.getUid() !== orderInfo('uid')) {
order.init();
window.location.reload();
}
isLimitGood() && (function() {
let a = [];
let 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');
}
... ... @@ -140,32 +65,6 @@ $('.checkbox').on('touchstart', function(e) {
}
});
/**
* 是否需要开发票
*/
$invoice.on('touchend', '.checkbox', function(e) {
let $this = $(this);
orderInfo('invoice', $this.hasClass('icon-cb-radio'));
if ($this.hasClass('icon-cb-radio')) {
$invoice.addClass('focus');
$invoiceType.html('电子发票(个人)<i class="iconfont">&#xe614;</i>');
orderInfo('receiverMobile', $userMobile.val());
orderInfo('invoices_type', 2);
}
if ($this.hasClass('icon-radio')) {
$invoice.removeClass('focus');
$invoiceType.html('');
orderInfo('invoices_title', null);
orderInfo('invoices_type', null);
orderInfo('receiverMobile', null);
orderInfo('buyerTaxNumber', null);
}
e.preventDefault();
e.stopPropagation();
});
function updateDeliverWay(deliver_way) {
let $moreJit = $('.more-jit a').get(0),
url;
... ... @@ -193,8 +92,7 @@ function orderCompute() {
delivery_way: orderInfo('delivery_way'),
payment_type: orderInfo('payment_type'),
coupon_code: orderInfo('coupon_code'),
use_yoho_coin: use_yoho_coin,
skuList: isLimitGood() ? orderInfo('skuList') : void 0
use_yoho_coin: use_yoho_coin
};
loading.showLoadingMask();
... ... @@ -493,11 +391,6 @@ $subBlock.on('touchstart', 'li', function() {
$('.bill a').on('touchstart', function() {
let $paymentType;
if (isTickets) {
_ticketsConfirm();
return;
}
$paymentType = $('.payment-type .icon-cb-radio');
orderInfo('payment_id', $paymentType.data('id')); // 支付方式id
orderInfo('payment_type', $paymentType.data('payment-type')); // 支付方式
... ...
// import qs from 'yoho-qs';
class OrderEnsure {
constructor(order) { // 参数为使用哪个 cookie
this.order = order;
this.orderInfo = order.orderInfo;
this.selector = {
invoice: $('.invoice'),
invoiceType: $('.invoice-type'),
userMobile: $('.user-mobile')
};
this.init();
this.bindEvents();
}
init() {
if (window.getUid() !== this.orderInfo('uid')) {
this.order.init();
window.location.reload();
}
}
bindEvents() {
this.selector.invoice.on('click', '.checkbox', this.needInvoice.bind(this));
}
/**
* 是否需要开发票
*/
needInvoice(event) {
let $this = $(event.currentTarget);
this.orderInfo('invoice', $this.hasClass('icon-cb-radio'));
if ($this.hasClass('icon-cb-radio')) {
this.selector.invoice.addClass('focus');
this.selector.invoiceType.html('电子发票(个人)<i class="iconfont">&#xe614;</i>');
this.orderInfo('receiverMobile', this.selector.userMobile.val());
this.orderInfo('invoices_type', 2);
}
if ($this.hasClass('icon-radio')) {
this.selector.invoice.removeClass('focus');
this.selector.invoiceType.html('');
this.orderInfo('invoices_title', null);
this.orderInfo('invoices_type', null);
this.orderInfo('receiverMobile', null);
this.orderInfo('buyerTaxNumber', null);
}
event.preventDefault();
event.stopPropagation();
}
}
module.exports = OrderEnsure;
... ...
... ... @@ -4,9 +4,11 @@
* @date: 2015/11/12
*/
require('cart/order-ensure.page.css');
let $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload'),
cookie = require('yoho-cookie');
const $ = require('yoho-jquery');
const lazyLoad = require('yoho-jquery-lazyload');
const cookie = require('yoho-cookie');
const qs = require('yoho-qs');
const OrderEnsure = require('./cartbuynow/order-ensure');
let tip = require('plugin/tip'),
loading = require('plugin/loading'),
... ... @@ -36,36 +38,14 @@ let $invoice = $('.invoice'),
delivery = 0,
$noPrintPrice = $('.no-print-price');
let $invoiceType = $('.invoice-type');
let $userMobile = $('.user-mobile');
new OrderEnsure(order);
require('common');
lazyLoad();
function getQueryParam() {
let 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();
return qs.limitproductcode;
}
// 来自购物车的链接默认不使用优惠券
... ... @@ -78,7 +58,7 @@ if (document.referrer && document.referrer.indexOf('/cart/index/index') !== -1)
isLimitGood() && (function() {
let a = [];
let data = getQueryParam();
let data = qs;
data.type = 'limitcode';
... ... @@ -108,31 +88,6 @@ $('.checkbox').on('touchstart', function(e) {
}
});
/**
* 是否需要开发票
*/
$invoice.on('touchend', '.checkbox', function(e) {
let $this = $(this);
orderInfo('invoice', $this.hasClass('icon-cb-radio'));
if ($this.hasClass('icon-cb-radio')) {
$invoice.addClass('focus');
$invoiceType.html('电子发票(个人)<i class="iconfont">&#xe614;</i>');
orderInfo('receiverMobile', $userMobile.val());
orderInfo('invoices_type', 2);
}
if ($this.hasClass('icon-radio')) {
$invoice.removeClass('focus');
$invoiceType.html('');
orderInfo('invoices_title', null);
orderInfo('invoices_type', null);
orderInfo('receiverMobile', null);
orderInfo('buyerTaxNumber', null);
}
e.preventDefault();
e.stopPropagation();
});
function updateDeliverId(id) {
let $moreJit = $('.more-jit a').get(0),
url;
... ...