Authored by 郭成尧

order-ensure-class-add

@@ -8,6 +8,7 @@ const $ = require('yoho-jquery'); @@ -8,6 +8,7 @@ const $ = require('yoho-jquery');
8 const lazyLoad = require('yoho-jquery-lazyload'); 8 const lazyLoad = require('yoho-jquery-lazyload');
9 const cookie = require('yoho-cookie'); 9 const cookie = require('yoho-cookie');
10 const qs = require('yoho-qs'); 10 const qs = require('yoho-qs');
  11 +const OrderEnsure = require('./cartbuynow/order-ensure');
11 12
12 let tip = require('plugin/tip'), 13 let tip = require('plugin/tip'),
13 loading = require('plugin/loading'), 14 loading = require('plugin/loading'),
@@ -27,9 +28,6 @@ let $invoice = $('.invoice'), @@ -27,9 +28,6 @@ let $invoice = $('.invoice'),
27 isSubmiting, 28 isSubmiting,
28 dispatchInfo, 29 dispatchInfo,
29 total, 30 total,
30 - isTickets = $('#ticketsPage').val(),  
31 - productSku = $('#productSku').val(),  
32 - buyNumber = $('#buyNumber').val(),  
33 headerTop = $('#yoho-header').outerHeight(), 31 headerTop = $('#yoho-header').outerHeight(),
34 isYohoCoinClick = $coinLi.data('yoho-coin-click') * 1, // 判断有货币是否可以单击 32 isYohoCoinClick = $coinLi.data('yoho-coin-click') * 1, // 判断有货币是否可以单击
35 addressTop = $('.address-wrap').outerHeight(), 33 addressTop = $('.address-wrap').outerHeight(),
@@ -37,8 +35,7 @@ let $invoice = $('.invoice'), @@ -37,8 +35,7 @@ let $invoice = $('.invoice'),
37 delivery = 0, 35 delivery = 0,
38 $noPrintPrice = $('.no-print-price'); 36 $noPrintPrice = $('.no-print-price');
39 37
40 -let $invoiceType = $('.invoice-type');  
41 -let $userMobile = $('.user-mobile'); 38 +new OrderEnsure(order);
42 39
43 require('common'); 40 require('common');
44 41
@@ -47,78 +44,6 @@ lazyLoad(); @@ -47,78 +44,6 @@ lazyLoad();
47 // 存 COOKIE 44 // 存 COOKIE
48 orderInfo('product_sku', qs.product_sku); 45 orderInfo('product_sku', qs.product_sku);
49 46
50 -function getQueryParam() {  
51 - let queryArray = location.search.substr(1).split('&'),  
52 - i,  
53 - subArr = [],  
54 - obj = {};  
55 -  
56 - for (i = 0; i < queryArray.length; i++) {  
57 - subArr = queryArray[i].split('=');  
58 - obj[subArr[0]] = subArr[1];  
59 - subArr = [];  
60 - }  
61 -  
62 - return obj;  
63 -}  
64 -  
65 -function isLimitGood() {  
66 - return getQueryParam().limitproductcode;  
67 -}  
68 -  
69 -// 电子票下单  
70 -function _ticketsConfirm() {  
71 - let data = {  
72 - productSku: productSku,  
73 - buyNumber: buyNumber,  
74 - mobile: $ticketsMobile.val(),  
75 - useYohoCoin: orderInfo('use_yoho_coin')  
76 - };  
77 -  
78 - if (!$ticketsMobile.val()) {  
79 - tip.show('手机号必填');  
80 - return;  
81 - }  
82 -  
83 - $.ajax({  
84 - url: '/cart/index/submitTicket',  
85 - type: 'POST',  
86 - dataType: 'json',  
87 - data: data,  
88 - success: function(ticket) {  
89 -  
90 - // 下单成功调整支付页面  
91 - if (ticket.code === 200) {  
92 - window.location.href = '/home/orders/paynew?order_code=' + ticket.data.order_code;  
93 - } else {  
94 - tip.show(ticket.message);  
95 - }  
96 -  
97 - },  
98 - error: function() {  
99 - tip.show('网络异常~');  
100 - }  
101 - });  
102 -}  
103 -  
104 -  
105 -if (window.getUid() !== orderInfo('uid')) {  
106 - order.init();  
107 - window.location.reload();  
108 -}  
109 -  
110 -isLimitGood() && (function() {  
111 - let a = [];  
112 -  
113 - let data = getQueryParam();  
114 -  
115 - data.type = 'limitcode';  
116 -  
117 - a.push(data);  
118 - orderInfo('skuList', JSON.stringify(a));  
119 - orderInfo('limitUrlSufix', location.search);  
120 -}());  
121 -  
122 if (queryString.cartType || queryString.carttype || !orderInfo('cartType')) { 47 if (queryString.cartType || queryString.carttype || !orderInfo('cartType')) {
123 orderInfo('cartType', queryString.cartType || queryString.carttype || 'ordinary'); 48 orderInfo('cartType', queryString.cartType || queryString.carttype || 'ordinary');
124 } 49 }
@@ -140,32 +65,6 @@ $('.checkbox').on('touchstart', function(e) { @@ -140,32 +65,6 @@ $('.checkbox').on('touchstart', function(e) {
140 } 65 }
141 }); 66 });
142 67
143 -/**  
144 - * 是否需要开发票  
145 - */  
146 -$invoice.on('touchend', '.checkbox', function(e) {  
147 - let $this = $(this);  
148 -  
149 - orderInfo('invoice', $this.hasClass('icon-cb-radio'));  
150 - if ($this.hasClass('icon-cb-radio')) {  
151 - $invoice.addClass('focus');  
152 - $invoiceType.html('电子发票(个人)<i class="iconfont">&#xe614;</i>');  
153 - orderInfo('receiverMobile', $userMobile.val());  
154 - orderInfo('invoices_type', 2);  
155 - }  
156 - if ($this.hasClass('icon-radio')) {  
157 - $invoice.removeClass('focus');  
158 - $invoiceType.html('');  
159 - orderInfo('invoices_title', null);  
160 - orderInfo('invoices_type', null);  
161 - orderInfo('receiverMobile', null);  
162 - orderInfo('buyerTaxNumber', null);  
163 - }  
164 - e.preventDefault();  
165 - e.stopPropagation();  
166 -});  
167 -  
168 -  
169 function updateDeliverWay(deliver_way) { 68 function updateDeliverWay(deliver_way) {
170 let $moreJit = $('.more-jit a').get(0), 69 let $moreJit = $('.more-jit a').get(0),
171 url; 70 url;
@@ -193,8 +92,7 @@ function orderCompute() { @@ -193,8 +92,7 @@ function orderCompute() {
193 delivery_way: orderInfo('delivery_way'), 92 delivery_way: orderInfo('delivery_way'),
194 payment_type: orderInfo('payment_type'), 93 payment_type: orderInfo('payment_type'),
195 coupon_code: orderInfo('coupon_code'), 94 coupon_code: orderInfo('coupon_code'),
196 - use_yoho_coin: use_yoho_coin,  
197 - skuList: isLimitGood() ? orderInfo('skuList') : void 0 95 + use_yoho_coin: use_yoho_coin
198 }; 96 };
199 97
200 loading.showLoadingMask(); 98 loading.showLoadingMask();
@@ -493,11 +391,6 @@ $subBlock.on('touchstart', 'li', function() { @@ -493,11 +391,6 @@ $subBlock.on('touchstart', 'li', function() {
493 $('.bill a').on('touchstart', function() { 391 $('.bill a').on('touchstart', function() {
494 let $paymentType; 392 let $paymentType;
495 393
496 - if (isTickets) {  
497 - _ticketsConfirm();  
498 - return;  
499 - }  
500 -  
501 $paymentType = $('.payment-type .icon-cb-radio'); 394 $paymentType = $('.payment-type .icon-cb-radio');
502 orderInfo('payment_id', $paymentType.data('id')); // 支付方式id 395 orderInfo('payment_id', $paymentType.data('id')); // 支付方式id
503 orderInfo('payment_type', $paymentType.data('payment-type')); // 支付方式 396 orderInfo('payment_type', $paymentType.data('payment-type')); // 支付方式
  1 +// import qs from 'yoho-qs';
  2 +
  3 +class OrderEnsure {
  4 + constructor(order) { // 参数为使用哪个 cookie
  5 + this.order = order;
  6 + this.orderInfo = order.orderInfo;
  7 +
  8 + this.selector = {
  9 + invoice: $('.invoice'),
  10 + invoiceType: $('.invoice-type'),
  11 + userMobile: $('.user-mobile')
  12 + };
  13 +
  14 + this.init();
  15 + this.bindEvents();
  16 + }
  17 +
  18 + init() {
  19 + if (window.getUid() !== this.orderInfo('uid')) {
  20 + this.order.init();
  21 + window.location.reload();
  22 + }
  23 + }
  24 +
  25 + bindEvents() {
  26 + this.selector.invoice.on('click', '.checkbox', this.needInvoice.bind(this));
  27 + }
  28 +
  29 + /**
  30 + * 是否需要开发票
  31 + */
  32 + needInvoice(event) {
  33 + let $this = $(event.currentTarget);
  34 +
  35 + this.orderInfo('invoice', $this.hasClass('icon-cb-radio'));
  36 + if ($this.hasClass('icon-cb-radio')) {
  37 + this.selector.invoice.addClass('focus');
  38 + this.selector.invoiceType.html('电子发票(个人)<i class="iconfont">&#xe614;</i>');
  39 + this.orderInfo('receiverMobile', this.selector.userMobile.val());
  40 + this.orderInfo('invoices_type', 2);
  41 + }
  42 + if ($this.hasClass('icon-radio')) {
  43 + this.selector.invoice.removeClass('focus');
  44 + this.selector.invoiceType.html('');
  45 + this.orderInfo('invoices_title', null);
  46 + this.orderInfo('invoices_type', null);
  47 + this.orderInfo('receiverMobile', null);
  48 + this.orderInfo('buyerTaxNumber', null);
  49 + }
  50 + event.preventDefault();
  51 + event.stopPropagation();
  52 + }
  53 +}
  54 +
  55 +module.exports = OrderEnsure;
@@ -4,9 +4,11 @@ @@ -4,9 +4,11 @@
4 * @date: 2015/11/12 4 * @date: 2015/11/12
5 */ 5 */
6 require('cart/order-ensure.page.css'); 6 require('cart/order-ensure.page.css');
7 -let $ = require('yoho-jquery'),  
8 - lazyLoad = require('yoho-jquery-lazyload'),  
9 - cookie = require('yoho-cookie'); 7 +const $ = require('yoho-jquery');
  8 +const lazyLoad = require('yoho-jquery-lazyload');
  9 +const cookie = require('yoho-cookie');
  10 +const qs = require('yoho-qs');
  11 +const OrderEnsure = require('./cartbuynow/order-ensure');
10 12
11 let tip = require('plugin/tip'), 13 let tip = require('plugin/tip'),
12 loading = require('plugin/loading'), 14 loading = require('plugin/loading'),
@@ -36,36 +38,14 @@ let $invoice = $('.invoice'), @@ -36,36 +38,14 @@ let $invoice = $('.invoice'),
36 delivery = 0, 38 delivery = 0,
37 $noPrintPrice = $('.no-print-price'); 39 $noPrintPrice = $('.no-print-price');
38 40
39 -let $invoiceType = $('.invoice-type');  
40 -let $userMobile = $('.user-mobile'); 41 +new OrderEnsure(order);
41 42
42 require('common'); 43 require('common');
43 44
44 lazyLoad(); 45 lazyLoad();
45 46
46 -function getQueryParam() {  
47 - let queryArray = location.search.substr(1).split('&'),  
48 - i,  
49 - subArr = [],  
50 - obj = {};  
51 -  
52 - for (i = 0; i < queryArray.length; i++) {  
53 - subArr = queryArray[i].split('=');  
54 - obj[subArr[0]] = subArr[1];  
55 - subArr = [];  
56 - }  
57 -  
58 - return obj;  
59 -}  
60 -  
61 function isLimitGood() { 47 function isLimitGood() {
62 - return getQueryParam().limitproductcode;  
63 -}  
64 -  
65 -  
66 -if (window.getUid() !== orderInfo('uid')) {  
67 - order.init();  
68 - window.location.reload(); 48 + return qs.limitproductcode;
69 } 49 }
70 50
71 // 来自购物车的链接默认不使用优惠券 51 // 来自购物车的链接默认不使用优惠券
@@ -78,7 +58,7 @@ if (document.referrer && document.referrer.indexOf('/cart/index/index') !== -1) @@ -78,7 +58,7 @@ if (document.referrer && document.referrer.indexOf('/cart/index/index') !== -1)
78 isLimitGood() && (function() { 58 isLimitGood() && (function() {
79 let a = []; 59 let a = [];
80 60
81 - let data = getQueryParam(); 61 + let data = qs;
82 62
83 data.type = 'limitcode'; 63 data.type = 'limitcode';
84 64
@@ -108,31 +88,6 @@ $('.checkbox').on('touchstart', function(e) { @@ -108,31 +88,6 @@ $('.checkbox').on('touchstart', function(e) {
108 } 88 }
109 }); 89 });
110 90
111 -/**  
112 - * 是否需要开发票  
113 - */  
114 -$invoice.on('touchend', '.checkbox', function(e) {  
115 - let $this = $(this);  
116 -  
117 - orderInfo('invoice', $this.hasClass('icon-cb-radio'));  
118 - if ($this.hasClass('icon-cb-radio')) {  
119 - $invoice.addClass('focus');  
120 - $invoiceType.html('电子发票(个人)<i class="iconfont">&#xe614;</i>');  
121 - orderInfo('receiverMobile', $userMobile.val());  
122 - orderInfo('invoices_type', 2);  
123 - }  
124 - if ($this.hasClass('icon-radio')) {  
125 - $invoice.removeClass('focus');  
126 - $invoiceType.html('');  
127 - orderInfo('invoices_title', null);  
128 - orderInfo('invoices_type', null);  
129 - orderInfo('receiverMobile', null);  
130 - orderInfo('buyerTaxNumber', null);  
131 - }  
132 - e.preventDefault();  
133 - e.stopPropagation();  
134 -});  
135 -  
136 function updateDeliverId(id) { 91 function updateDeliverId(id) {
137 let $moreJit = $('.more-jit a').get(0), 92 let $moreJit = $('.more-jit a').get(0),
138 url; 93 url;