Showing
9 changed files
with
589 additions
and
34 deletions
@@ -2,14 +2,19 @@ | @@ -2,14 +2,19 @@ | ||
2 | * @Author: Targaryen | 2 | * @Author: Targaryen |
3 | * @Date: 2017-06-21 10:15:38 | 3 | * @Date: 2017-06-21 10:15:38 |
4 | * @Last Modified by: Targaryen | 4 | * @Last Modified by: Targaryen |
5 | - * @Last Modified time: 2017-06-22 16:59:54 | 5 | + * @Last Modified time: 2017-06-23 11:27:00 |
6 | */ | 6 | */ |
7 | +const _ = require('lodash'); | ||
7 | const co = require('bluebird').coroutine; | 8 | const co = require('bluebird').coroutine; |
8 | const headerModel = require('../../../doraemon/models/header'); | 9 | const headerModel = require('../../../doraemon/models/header'); |
9 | const BuyNowModel = require('../models/BuyNowModel'); | 10 | const BuyNowModel = require('../models/BuyNowModel'); |
11 | +const addressModel = require('../models/address'); | ||
12 | +const userModel = require('../models/user'); | ||
13 | +const orderModel = require('../models/order'); | ||
10 | const utils = '../../../utils'; | 14 | const utils = '../../../utils'; |
11 | const paymentProcess = require(`${utils}/payment-process`); | 15 | const paymentProcess = require(`${utils}/payment-process`); |
12 | const logger = global.yoho.logger; | 16 | const logger = global.yoho.logger; |
17 | +const helpers = global.yoho.helpers; | ||
13 | 18 | ||
14 | // cookie 参数 | 19 | // cookie 参数 |
15 | const actCkOpthn = { | 20 | const actCkOpthn = { |
@@ -65,6 +70,7 @@ class BuyNowController { | @@ -65,6 +70,7 @@ class BuyNowController { | ||
65 | page: 'order-ensure', | 70 | page: 'order-ensure', |
66 | title: '确认订单', | 71 | title: '确认订单', |
67 | width750: true, | 72 | width750: true, |
73 | + product_sku: product_sku, | ||
68 | orderEnsure: paymentProcess.tranformPayment(result.data, orderInfo, null, null, computeData.data) | 74 | orderEnsure: paymentProcess.tranformPayment(result.data, orderInfo, null, null, computeData.data) |
69 | }); | 75 | }); |
70 | 76 | ||
@@ -102,16 +108,6 @@ class BuyNowController { | @@ -102,16 +108,6 @@ class BuyNowController { | ||
102 | * @param {*} next | 108 | * @param {*} next |
103 | */ | 109 | */ |
104 | orderSub(req, res, next) { | 110 | orderSub(req, res, next) { |
105 | - let orderInfo; | ||
106 | - | ||
107 | - try { | ||
108 | - orderInfo = JSON.parse(req.cookies['buynow-order-info']); | ||
109 | - } catch (e) { | ||
110 | - logger.info(`orderEnsure: get buynow-order-info from cookie error:${JSON.stringify(e)}`); | ||
111 | - orderInfo = {}; | ||
112 | - res.clearCookie('buynow-order-info', actCkOpthn); | ||
113 | - } | ||
114 | - | ||
115 | let params = { | 111 | let params = { |
116 | uid: req.user.uid, | 112 | uid: req.user.uid, |
117 | product_sku: req.body.product_sku, | 113 | product_sku: req.body.product_sku, |
@@ -131,13 +127,15 @@ class BuyNowController { | @@ -131,13 +127,15 @@ class BuyNowController { | ||
131 | }; | 127 | }; |
132 | 128 | ||
133 | // 是否开发票 | 129 | // 是否开发票 |
134 | - if (req.body.invoices) { | ||
135 | - params.invoices_title = req.body.invoices_title || '个人'; | ||
136 | - } | ||
137 | - | ||
138 | - // 购买方纳税人识别号 | ||
139 | - if (req.body.invoices && orderInfo.buyerTaxNumber) { | ||
140 | - params.buyerTaxNumber = orderInfo.buyerTaxNumber; | 130 | + if (req.body.invoice) { |
131 | + params.invoices_type = req.body.invoices_type; // 发票类型:纸质 1,电子 2 | ||
132 | + params.invoices_title = req.body.invoices_title || '个人'; // 发票抬头,个人前端不传此值 | ||
133 | + params.receiverMobile = req.body.receiverMobile; // 接收人电话 | ||
134 | + | ||
135 | + // 购买方纳税人识别号 | ||
136 | + if (req.body.buyerTaxNumber) { | ||
137 | + params.buyerTaxNumber = req.body.buyerTaxNumber; | ||
138 | + } | ||
141 | } | 139 | } |
142 | 140 | ||
143 | co(function * () { | 141 | co(function * () { |
@@ -146,6 +144,98 @@ class BuyNowController { | @@ -146,6 +144,98 @@ class BuyNowController { | ||
146 | return res.json(result); | 144 | return res.json(result); |
147 | })().catch(next); | 145 | })().catch(next); |
148 | } | 146 | } |
147 | + | ||
148 | + /** | ||
149 | + * 选择地址 | ||
150 | + * @param {*} req | ||
151 | + * @param {*} res | ||
152 | + * @param {*} next | ||
153 | + */ | ||
154 | + selectAddress(req, res, next) { | ||
155 | + let uid = req.user.uid; | ||
156 | + let product_sku = req.query.product_sku; | ||
157 | + | ||
158 | + co(function * () { | ||
159 | + let address = yield addressModel.addressData(uid); | ||
160 | + let moreUrl = helpers.urlFormat('/cart/index/buynow/orderEnsure', {product_sku: product_sku}); | ||
161 | + | ||
162 | + address = address.data; | ||
163 | + | ||
164 | + let headerData = headerModel.setNav({ | ||
165 | + navTitle: '选择地址', | ||
166 | + navBtn: false, | ||
167 | + backUrl: moreUrl | ||
168 | + }); | ||
169 | + | ||
170 | + res.render('select-address', { | ||
171 | + module: 'buynow', | ||
172 | + page: 'select-address', | ||
173 | + pageHeader: headerData, | ||
174 | + pageFooter: true, | ||
175 | + moreUrl, | ||
176 | + address, | ||
177 | + localCss: true | ||
178 | + }); | ||
179 | + })().catch(next); | ||
180 | + } | ||
181 | + | ||
182 | + /** | ||
183 | + * 填写发票信息 | ||
184 | + * @param {*} req | ||
185 | + * @param {*} res | ||
186 | + * @param {*} next | ||
187 | + */ | ||
188 | + selectInvoice(req, res, next) { | ||
189 | + let product_sku = req.query.product_sku; | ||
190 | + let uid = req.user.uid; | ||
191 | + let orderInfo; | ||
192 | + | ||
193 | + try { | ||
194 | + orderInfo = JSON.parse(req.cookies['order-info']); | ||
195 | + } catch (e) { | ||
196 | + orderInfo = {}; | ||
197 | + } | ||
198 | + | ||
199 | + co(function* () { | ||
200 | + let userData = yield userModel.queryProfile(uid); | ||
201 | + let mobile = _.get(userData, 'data.mobile', ''); | ||
202 | + let addresslist = yield userModel.addressTextData(uid); | ||
203 | + let returnData = orderModel.processInvoiceData(orderInfo, mobile, addresslist); | ||
204 | + let headerData = headerModel.setNav({ | ||
205 | + invoiceNotice: '发票须知', | ||
206 | + navTitle: '发票信息', | ||
207 | + navBtn: false | ||
208 | + }); | ||
209 | + | ||
210 | + res.render('select-invoice', _.assign(returnData, { | ||
211 | + pageHeader: headerData, | ||
212 | + module: 'buynow', | ||
213 | + page: 'select-invoice', | ||
214 | + localCss: true, | ||
215 | + addressMore: helpers.urlFormat('/cart/index/buynow/orderEnsure', {product_sku: product_sku}) | ||
216 | + })); | ||
217 | + })().catch(next); | ||
218 | + } | ||
219 | + | ||
220 | + /** | ||
221 | + * 选择优惠券 | ||
222 | + */ | ||
223 | + selectCoupon(req, res) { | ||
224 | + let headerData = headerModel.setNav({ | ||
225 | + navTitle: '选择优惠券', | ||
226 | + navBtn: false | ||
227 | + }); | ||
228 | + | ||
229 | + res.render('select-coupon', { | ||
230 | + module: 'buynow', | ||
231 | + page: 'select-coupon', | ||
232 | + title: '选择优惠券', | ||
233 | + selectCouponPage: true, | ||
234 | + pageHeader: headerData, | ||
235 | + pageFooter: true, | ||
236 | + localCss: true | ||
237 | + }); | ||
238 | + } | ||
149 | } | 239 | } |
150 | 240 | ||
151 | module.exports = new BuyNowController(); | 241 | module.exports = new BuyNowController(); |
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | * @Author: Targaryen | 2 | * @Author: Targaryen |
3 | * @Date: 2017-06-21 10:15:45 | 3 | * @Date: 2017-06-21 10:15:45 |
4 | * @Last Modified by: Targaryen | 4 | * @Last Modified by: Targaryen |
5 | - * @Last Modified time: 2017-06-22 16:39:09 | 5 | + * @Last Modified time: 2017-06-23 11:25:12 |
6 | */ | 6 | */ |
7 | const api = global.yoho.API; | 7 | const api = global.yoho.API; |
8 | 8 | ||
@@ -117,14 +117,27 @@ class BuyNowModel extends global.yoho.BaseModel { | @@ -117,14 +117,27 @@ class BuyNowModel extends global.yoho.BaseModel { | ||
117 | is_print_price: params.is_print_price || 'N' | 117 | is_print_price: params.is_print_price || 'N' |
118 | }; | 118 | }; |
119 | 119 | ||
120 | + // 发票类型:纸质 1,电子 2 | ||
121 | + if (params.invoices_type) { | ||
122 | + finalParams.invoices_type = params.invoices_type; | ||
123 | + } | ||
124 | + | ||
125 | + // 发票抬头 | ||
120 | if (params.invoices_title) { | 126 | if (params.invoices_title) { |
121 | finalParams.invoices_title = params.invoices_title; | 127 | finalParams.invoices_title = params.invoices_title; |
122 | } | 128 | } |
123 | 129 | ||
130 | + // 发票种类写死明细 | ||
124 | if (params.invoices_type_id) { | 131 | if (params.invoices_type_id) { |
125 | - finalParams.invoices_type_id = 12; // 发票内容写死明细 | 132 | + finalParams.invoice_content = 12; |
133 | + } | ||
134 | + | ||
135 | + // 收票人手机号码 | ||
136 | + if (params.receiverMobile) { | ||
137 | + finalParams.receiverMobile = params.receiverMobile; | ||
126 | } | 138 | } |
127 | 139 | ||
140 | + // 购买方纳税人识别号,需要开具电子发票且发票抬头为单位信息时为必填项 | ||
128 | if (params.buyerTaxNumber) { | 141 | if (params.buyerTaxNumber) { |
129 | finalParams.buyerTaxNumber = params.buyerTaxNumber; | 142 | finalParams.buyerTaxNumber = params.buyerTaxNumber; |
130 | } | 143 | } |
@@ -65,6 +65,9 @@ router.post('/index/new/decrbundle', indexController.decrBundle); // 购物车 | @@ -65,6 +65,9 @@ router.post('/index/new/decrbundle', indexController.decrBundle); // 购物车 | ||
65 | router.get('/index/buynow/orderensure', authMW, BuyNowController.orderEnsure); // 立即购买订单确认页面 | 65 | router.get('/index/buynow/orderensure', authMW, BuyNowController.orderEnsure); // 立即购买订单确认页面 |
66 | router.post('/index/buynow/ordercompute', authMW, BuyNowController.orderCompute); // 立即购买订单重新计算 | 66 | router.post('/index/buynow/ordercompute', authMW, BuyNowController.orderCompute); // 立即购买订单重新计算 |
67 | router.post('/index/buynow/ordersub', authMW, BuyNowController.orderSub); // 立即购买订单提交 | 67 | router.post('/index/buynow/ordersub', authMW, BuyNowController.orderSub); // 立即购买订单提交 |
68 | +router.get('/index/buynow/selectAddress', authMW, BuyNowController.selectAddress); // 选择地址 | ||
69 | +router.get('/index/buynow/selectInvoice', authMW, BuyNowController.selectInvoice); // 发票信息 | ||
70 | + | ||
68 | 71 | ||
69 | // 支付中心 URL,由于微信安全限制,在现有 URL 后追加 new ,通过 subDomain 中间件转发到此 | 72 | // 支付中心 URL,由于微信安全限制,在现有 URL 后追加 new ,通过 subDomain 中间件转发到此 |
70 | router.get('/home/orders/paynew', authMW, payController.payCenter); | 73 | router.get('/home/orders/paynew', authMW, payController.payCenter); |
@@ -6,15 +6,15 @@ | @@ -6,15 +6,15 @@ | ||
6 | <div class="info"> | 6 | <div class="info"> |
7 | <span class="info-name">{{name}}</span> | 7 | <span class="info-name">{{name}}</span> |
8 | <span class="info-phone">{{phoneNum}}</span> | 8 | <span class="info-phone">{{phoneNum}}</span> |
9 | - <a href="/cart/index/new/selectAddress"><span class="info-address">{{addressInfo}}</span></a> | 9 | + <a href="/cart/index/buynow/selectAddress?product_sku={{@root.product_sku}}"><span class="info-address">{{addressInfo}}</span></a> |
10 | <i class="iconfont"></i> | 10 | <i class="iconfont"></i> |
11 | </div> | 11 | </div> |
12 | - <a class="rest" href="/cart/index/new/selectAddress">其他地址<span class="iconfont"></span></a> | 12 | + <a class="rest" href="/cart/index/buynow/selectAddress?product_sku={{@root.product_sku}}">其他地址<span class="iconfont"></span></a> |
13 | </div> | 13 | </div> |
14 | {{else}} | 14 | {{else}} |
15 | <div class="address block address-wrap not-address"> | 15 | <div class="address block address-wrap not-address"> |
16 | <i class="iconfont"></i> | 16 | <i class="iconfont"></i> |
17 | - <a class="choose" href="/cart/index/new/selectAddress">请选择收货地址<span class="iconfont"></span></a> | 17 | + <a class="choose" href="/cart/index/buynow/selectAddress?product_sku={{@root.product_sku}}">请选择收货地址<span class="iconfont"></span></a> |
18 | </div> | 18 | </div> |
19 | {{/if}} | 19 | {{/if}} |
20 | <section class="dispatch block"> | 20 | <section class="dispatch block"> |
@@ -91,7 +91,7 @@ | @@ -91,7 +91,7 @@ | ||
91 | <ul class="sale-invoice"> | 91 | <ul class="sale-invoice"> |
92 | {{#if isOrdinaryCart}} | 92 | {{#if isOrdinaryCart}} |
93 | <li class="coupon"> | 93 | <li class="coupon"> |
94 | - <a href="{{#if isLimit}}javascript:void(0);{{else}}/cart/index/new/selectCoupon{{/if}}"> | 94 | + <a href="{{#if isLimit}}javascript:void(0);{{else}}/cart/index/buynow/selectCoupon?product_sku={{@root.product_sku}}{{/if}}"> |
95 | <span class="title">优惠券/优惠券码</span> | 95 | <span class="title">优惠券/优惠券码</span> |
96 | {{# coupon}} | 96 | {{# coupon}} |
97 | {{#if couponName}} | 97 | {{#if couponName}} |
@@ -139,7 +139,7 @@ | @@ -139,7 +139,7 @@ | ||
139 | <input type="hidden" class="user-mobile" value="{{userMobile}}" /> | 139 | <input type="hidden" class="user-mobile" value="{{userMobile}}" /> |
140 | <span class="title">发票</span> | 140 | <span class="title">发票</span> |
141 | <span class="iconfont checkbox {{#if needInvoice}}icon-cb-radio{{else}}icon-radio{{/if}}"></span> | 141 | <span class="iconfont checkbox {{#if needInvoice}}icon-cb-radio{{else}}icon-radio{{/if}}"></span> |
142 | - <a id="invoice" class="invoice-info" href="/cart/index/new/invoiceInfo"> | 142 | + <a id="invoice" class="invoice-info" href="/cart/index/buynow/selectInvoice?product_sku={{@root.product_sku}}"> |
143 | <span class="title">发票信息</span> | 143 | <span class="title">发票信息</span> |
144 | <span class="invoice-type">明细 <i class="iconfont"></i></span> | 144 | <span class="invoice-type">明细 <i class="iconfont"></i></span> |
145 | </a> | 145 | </a> |
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | * @Author: Targaryen | 2 | * @Author: Targaryen |
3 | * @Date: 2017-06-21 10:30:21 | 3 | * @Date: 2017-06-21 10:30:21 |
4 | * @Last Modified by: Targaryen | 4 | * @Last Modified by: Targaryen |
5 | - * @Last Modified time: 2017-06-22 16:58:56 | 5 | + * @Last Modified time: 2017-06-23 11:23:09 |
6 | */ | 6 | */ |
7 | require('buynow/order-ensure.page.css'); | 7 | require('buynow/order-ensure.page.css'); |
8 | const $ = require('yoho-jquery'); | 8 | const $ = require('yoho-jquery'); |
@@ -264,10 +264,11 @@ function submitOrder() { | @@ -264,10 +264,11 @@ function submitOrder() { | ||
264 | address_id: orderInfo('address_id'), | 264 | address_id: orderInfo('address_id'), |
265 | delivery_way: orderInfo('delivery_way'), | 265 | delivery_way: orderInfo('delivery_way'), |
266 | delivery_time: orderInfo('delivery_time'), | 266 | delivery_time: orderInfo('delivery_time'), |
267 | - invoices: orderInfo('invoice') || null, | 267 | + invoice: orderInfo('invoice') || null, |
268 | invoices_title: orderInfo('invoice') ? invoiceText : null, | 268 | invoices_title: orderInfo('invoice') ? invoiceText : null, |
269 | invoices_type_id: orderInfo('invoice') ? ($invoice.find('.invoice-type').val() || | 269 | invoices_type_id: orderInfo('invoice') ? ($invoice.find('.invoice-type').val() || |
270 | orderInfo('invoices_type_id')) : null, | 270 | orderInfo('invoices_type_id')) : null, |
271 | + receiverMobile: orderInfo('receiverMobile') || null, | ||
271 | msg: msg, | 272 | msg: msg, |
272 | is_print_price: orderInfo('is_print_price'), | 273 | is_print_price: orderInfo('is_print_price'), |
273 | payment_id: orderInfo('payment_id'), | 274 | payment_id: orderInfo('payment_id'), |
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | * @Author: Targaryen | 2 | * @Author: Targaryen |
3 | * @Date: 2017-06-22 13:51:16 | 3 | * @Date: 2017-06-22 13:51:16 |
4 | * @Last Modified by: Targaryen | 4 | * @Last Modified by: Targaryen |
5 | - * @Last Modified time: 2017-06-22 15:40:52 | 5 | + * @Last Modified time: 2017-06-23 11:15:44 |
6 | */ | 6 | */ |
7 | require('common'); | 7 | require('common'); |
8 | let info = window.cookie('buynow-order-info'); | 8 | let info = window.cookie('buynow-order-info'); |
@@ -22,13 +22,11 @@ function init() { | @@ -22,13 +22,11 @@ function init() { | ||
22 | address_id: null, | 22 | address_id: null, |
23 | coupon_code: null, | 23 | coupon_code: null, |
24 | couponName: null, | 24 | couponName: null, |
25 | - invoice: null, | ||
26 | - invoices_title: null, | ||
27 | - invoices_type_id: null, | ||
28 | - invoiceTitle: null, | ||
29 | - receiverMobile: null, | 25 | + invoice: null, // 是否选择了发票 |
26 | + invoices_type: null, // 发票类型: 电子 or 纸质 | ||
27 | + invoices_title: null, // 发票抬头 | ||
28 | + receiverMobile: null, // 接收人电话 | ||
30 | isModifyTel: false, | 29 | isModifyTel: false, |
31 | - invoicesType: null, | ||
32 | msg: null, | 30 | msg: null, |
33 | cartType: 'ordinary' | 31 | cartType: 'ordinary' |
34 | }; | 32 | }; |
public/js/buynow/select-address.page.js
0 → 100644
1 | +/* | ||
2 | + * @Author: Targaryen | ||
3 | + * @Date: 2017-06-23 11:43:18 | ||
4 | + * @Last Modified by: Targaryen | ||
5 | + * @Last Modified time: 2017-06-23 11:43:18 | ||
6 | + */ | ||
7 | + | ||
8 | +require('cart/select-address.page.css'); | ||
9 | +let $ = require('yoho-jquery'), | ||
10 | + orderInfo = require('./order-info').orderInfo; | ||
11 | + | ||
12 | +let $confim = $('.confim-mask'), | ||
13 | + deleteId; | ||
14 | + | ||
15 | +require('../cart/address/address'); | ||
16 | +require('common'); | ||
17 | + | ||
18 | +$('.address-item').on('click', function() { | ||
19 | + let $this = $(this); | ||
20 | + let addressId = decodeURIComponent($this.data('address-id')); | ||
21 | + let address = { | ||
22 | + address_id: addressId, | ||
23 | + consignee: $this.find('.name').text(), | ||
24 | + mobile: $this.find('.tel').text(), | ||
25 | + address_info: $this.find('.address-info').text(), | ||
26 | + is_support: $this.data('is-support') | ||
27 | + }; | ||
28 | + | ||
29 | + orderInfo('address_id', addressId); | ||
30 | + orderInfo('address', address); | ||
31 | + window.location.href = $this.data('href') + (orderInfo('limitUrlSufix') || ''); | ||
32 | + | ||
33 | +}).on('click', '.edit', function() { | ||
34 | + window.location.href = $(this).data('href'); | ||
35 | + return false; | ||
36 | +}).on('click', '.del', function() { | ||
37 | + deleteId = $(this).data('id'); | ||
38 | +}); | ||
39 | + | ||
40 | +$confim.on('click', '.confim', function() { | ||
41 | + if (orderInfo('address_id') === deleteId) { | ||
42 | + orderInfo('address_id', null); | ||
43 | + orderInfo('address', null); | ||
44 | + } | ||
45 | +}); |
public/js/buynow/select-coupon.page.js
0 → 100644
1 | +/* | ||
2 | + * @Author: Targaryen | ||
3 | + * @Date: 2017-06-23 11:43:44 | ||
4 | + * @Last Modified by: Targaryen | ||
5 | + * @Last Modified time: 2017-06-23 11:43:44 | ||
6 | + */ | ||
7 | +require('cart/select-coupon.page.css'); | ||
8 | +let $ = require('yoho-jquery'), | ||
9 | + ellipsis = require('yoho-mlellipsis'), | ||
10 | + loading = require('plugin/loading'), | ||
11 | + tip = require('plugin/tip'), | ||
12 | + conponTmpl = require('cart/select-coupon/coupon.hbs'), | ||
13 | + conponNotAvaliableTmpl = require('cart/select-coupon/coupon-not-avaliable.hbs'), | ||
14 | + orderInfo = require('./order-info').orderInfo; | ||
15 | + | ||
16 | +let isGetData; | ||
17 | + | ||
18 | +let $newCoupon = $('#new-coupon'), | ||
19 | + linkUrl = document.referrer, | ||
20 | + $couponList = $('#coupon-list'); | ||
21 | + | ||
22 | +let winH = $(window).height(); | ||
23 | + | ||
24 | +require('common'); | ||
25 | + | ||
26 | +function fixedLayOut() { | ||
27 | + let $null = $('.null'), | ||
28 | + navH = $('.nav-title').height(), | ||
29 | + nullH = $null.height(); | ||
30 | + | ||
31 | + if ($null.length === 0) { | ||
32 | + return false; | ||
33 | + } | ||
34 | + | ||
35 | + $null.css({ | ||
36 | + top: winH / 2 - nullH / 2 + navH | ||
37 | + }); | ||
38 | +} | ||
39 | + | ||
40 | +ellipsis.init(); | ||
41 | + | ||
42 | +function goToBack() { | ||
43 | + if (linkUrl) { | ||
44 | + window.location.href = linkUrl; | ||
45 | + } else { | ||
46 | + history.go(-1); | ||
47 | + } | ||
48 | +} | ||
49 | + | ||
50 | +$newCoupon.on('submit', function() { | ||
51 | + let $this = $(this); | ||
52 | + | ||
53 | + if (!$this.find('[name="couponCode"]').val()) { | ||
54 | + tip.show('请输入优惠券码'); | ||
55 | + return false; | ||
56 | + } | ||
57 | + $.ajax({ | ||
58 | + method: 'POST', | ||
59 | + url: '/cart/index/new/couponSearch', | ||
60 | + data: $this.serialize() | ||
61 | + }).then(function(res) { | ||
62 | + if (res.message) { | ||
63 | + tip.show(res.message); | ||
64 | + } | ||
65 | + if (res.code === 200) { | ||
66 | + tip.show('优惠券可用'); | ||
67 | + | ||
68 | + // 实付金额发生变化,使用有货币为0 | ||
69 | + orderInfo('yohoCoin', 0); | ||
70 | + orderInfo('coupon_code', res.data.coupon_code); | ||
71 | + orderInfo('couponName', res.data.coupon_title); | ||
72 | + goToBack(); | ||
73 | + } | ||
74 | + }).fail(function() { | ||
75 | + tip.show('网络错误'); | ||
76 | + }); | ||
77 | + return false; | ||
78 | +}); | ||
79 | + | ||
80 | +$couponList.on('touchstart', '.employ-main', function() { | ||
81 | + let $this = $(this); | ||
82 | + | ||
83 | + $this.siblings().removeClass('focus'); | ||
84 | + $this.addClass('focus'); | ||
85 | +}).on('touchend touchcancel', '.employ-main', function() { | ||
86 | + let $this = $(this); | ||
87 | + | ||
88 | + $this.siblings().removeClass('focus'); | ||
89 | + $this.removeClass('focus'); | ||
90 | +}); | ||
91 | + | ||
92 | +$('body').on('touchend', '.not-use', function() { | ||
93 | + orderInfo('coupon_code', null); | ||
94 | + orderInfo('couponName', null); | ||
95 | + | ||
96 | + // 实付金额发生变化,使用有货币为0 | ||
97 | + orderInfo('yohoCoin', 0); | ||
98 | + goToBack(); | ||
99 | +}); | ||
100 | + | ||
101 | + | ||
102 | +$newCoupon.find('input').on('input', function() { | ||
103 | + if ($(this).val() !== '') { | ||
104 | + $newCoupon.find('.submit').css('background', '#444'); | ||
105 | + } else { | ||
106 | + $newCoupon.find('.submit').css('background', '#b0b0b0'); | ||
107 | + } | ||
108 | +}); | ||
109 | + | ||
110 | +function getCouponHandle(allCoupons) { | ||
111 | + let notAvailableCoupons, | ||
112 | + coupons; | ||
113 | + | ||
114 | + // 把可用和不可用的优惠券分离出来 | ||
115 | + notAvailableCoupons = allCoupons.notAvailableCoupons; | ||
116 | + coupons = allCoupons.coupons; | ||
117 | + | ||
118 | + // 没有优惠券 | ||
119 | + if (!(notAvailableCoupons.length || coupons.length)) { | ||
120 | + $('.coupon-wrap').html($('#tmpl-no-coupon').html()); | ||
121 | + fixedLayOut(); | ||
122 | + return; | ||
123 | + } | ||
124 | + | ||
125 | + | ||
126 | + $.each(coupons, function(i, coupon) { | ||
127 | + coupon.couponValue = Math.floor(coupon.couponValue); | ||
128 | + }); | ||
129 | + | ||
130 | + $.each(notAvailableCoupons, function(i, coupon) { | ||
131 | + coupon.couponValue = Math.floor(coupon.couponValue); | ||
132 | + }); | ||
133 | + | ||
134 | + // 渲染可用的优惠券 | ||
135 | + $couponList.append(conponTmpl({ | ||
136 | + coupons: coupons | ||
137 | + })).find('.employ-main').on('touchstart', function() { | ||
138 | + let couponCode = $(this).data('coupon-code'); | ||
139 | + | ||
140 | + $.ajax({ | ||
141 | + method: 'POST', | ||
142 | + url: '/cart/index/new/couponSearch', | ||
143 | + data: { | ||
144 | + couponCode: couponCode | ||
145 | + } | ||
146 | + }).then(function(res) { | ||
147 | + if (res.code === 200) { | ||
148 | + orderInfo('coupon_code', res.data.coupon_code); | ||
149 | + orderInfo('couponName', res.data.coupon_title); | ||
150 | + | ||
151 | + // 实付金额发生变化,使用有货币为0 | ||
152 | + orderInfo('yohoCoin', 0); | ||
153 | + goToBack(); | ||
154 | + } else if (res.message) { | ||
155 | + tip.show(res.message); | ||
156 | + } | ||
157 | + }).fail(function() { | ||
158 | + tip.show('网络错误'); | ||
159 | + }); | ||
160 | + }); | ||
161 | + | ||
162 | + if (notAvailableCoupons.length) { | ||
163 | + $('.not-avaliable-coupon-line').show(); | ||
164 | + } | ||
165 | + $('#coupon-list-not').append(conponNotAvaliableTmpl({ | ||
166 | + notAvailableCoupons: notAvailableCoupons | ||
167 | + })); | ||
168 | + window.rePosFooter(); | ||
169 | + | ||
170 | +} | ||
171 | + | ||
172 | +function getCouponDate() { | ||
173 | + | ||
174 | + if (isGetData) { | ||
175 | + return; | ||
176 | + } | ||
177 | + | ||
178 | + loading.showLoadingMask(); | ||
179 | + isGetData = true; | ||
180 | + | ||
181 | + $.ajax({ | ||
182 | + type: 'GET', | ||
183 | + url: '/cart/index/new/couponList', | ||
184 | + dataType: 'json' | ||
185 | + }).then(getCouponHandle).always(function() { | ||
186 | + isGetData = false; | ||
187 | + loading.hideLoadingMask(); | ||
188 | + }); | ||
189 | +} | ||
190 | + | ||
191 | +getCouponDate(); |
public/js/buynow/select-invoice.page.js
0 → 100644
1 | +/* | ||
2 | + * @Author: Targaryen | ||
3 | + * @Date: 2017-06-23 11:43:34 | ||
4 | + * @Last Modified by: Targaryen | ||
5 | + * @Last Modified time: 2017-06-23 11:43:34 | ||
6 | + */ | ||
7 | +require('cart/select-invoice.page.css'); | ||
8 | + | ||
9 | +let $ = require('yoho-jquery'), | ||
10 | + tip = require('plugin/tip'), | ||
11 | + dialog = require('plugin/dialog'), | ||
12 | + order = require('./order-info'); | ||
13 | + | ||
14 | +let $invoiceNotice = $('.invoice-notice'), | ||
15 | + $taxNumber = $('.tax-number'), | ||
16 | + $editFlag = $('.edit-flag'), | ||
17 | + $tel = $('.tel'), | ||
18 | + $company = $('.company'), | ||
19 | + $copyTel = $('.copy-tel'); | ||
20 | +let $confirmBtn = $('.confirm-btn'); | ||
21 | +let $buyerTaxNumber = $('#buyerTaxNumber'); | ||
22 | + | ||
23 | +let eInvoiceType = $('#eInvoices').data('id'); | ||
24 | +let orderInfo = order.orderInfo; | ||
25 | +let linkUrl = document.referrer; | ||
26 | +let isModifyTel = false; | ||
27 | +let C_ID = window._ChannelVary[window.cookie('_Channel')] || 1; | ||
28 | + | ||
29 | +require('common'); | ||
30 | + | ||
31 | +if (window.getUid() !== orderInfo('uid')) { | ||
32 | + order.init(); | ||
33 | + window.location.reload(); | ||
34 | +} | ||
35 | + | ||
36 | +function goToBack() { | ||
37 | + if (linkUrl) { | ||
38 | + window.location.href = linkUrl; | ||
39 | + } else { | ||
40 | + history.go(-1); | ||
41 | + } | ||
42 | +} | ||
43 | + | ||
44 | +/** | ||
45 | + * 切换确认按钮激活状态 | ||
46 | + */ | ||
47 | +function switchBtnStatus() { | ||
48 | + if ($('.invoice-top').find('.on').text() === '单位') { | ||
49 | + if ($buyerTaxNumber.val() && $company.val() && $tel.val()) { | ||
50 | + $confirmBtn.addClass('active'); | ||
51 | + } else { | ||
52 | + $confirmBtn.removeClass('active'); | ||
53 | + } | ||
54 | + } else { | ||
55 | + if ($tel.attr('data-tel')) { | ||
56 | + $confirmBtn.addClass('active'); | ||
57 | + } else { | ||
58 | + $confirmBtn.removeClass('active'); | ||
59 | + } | ||
60 | + } | ||
61 | +} | ||
62 | + | ||
63 | +/** | ||
64 | + * 发票抬头输入监听 | ||
65 | + */ | ||
66 | +$company.bind('input', function() { | ||
67 | + switchBtnStatus(); | ||
68 | +}); | ||
69 | + | ||
70 | +/** | ||
71 | + * 手机号输入监听 | ||
72 | + */ | ||
73 | +$tel.bind('input', function() { | ||
74 | + switchBtnStatus(); | ||
75 | +}); | ||
76 | + | ||
77 | +/** | ||
78 | + * 税号输入监听 | ||
79 | + */ | ||
80 | +$buyerTaxNumber.bind('input', function() { | ||
81 | + switchBtnStatus(); | ||
82 | +}); | ||
83 | + | ||
84 | +// 单选效果 | ||
85 | +function chooseAction(pDom, dom) { | ||
86 | + if (dom.hasClass('icon-cb-radio')) { | ||
87 | + return; | ||
88 | + } else { | ||
89 | + pDom.find('.choose').removeClass('icon-cb-radio icon-radio').addClass('icon-radio'); | ||
90 | + dom.removeClass('icon-radio').addClass('icon-cb-radio'); | ||
91 | + dom.parent().addClass('on'); | ||
92 | + dom.parent().siblings().removeClass('on'); | ||
93 | + $editFlag.val('true'); | ||
94 | + } | ||
95 | +} | ||
96 | + | ||
97 | +// 确认表单事件 | ||
98 | +function confirmAction() { | ||
99 | + let title = $('.invoice-top').find('.on').text(), | ||
100 | + buyerTaxNumber = $buyerTaxNumber.val(), | ||
101 | + tel = $tel.attr('data-tel'), | ||
102 | + company = $company.val(); | ||
103 | + | ||
104 | + if ($editFlag.val() === 'true') { | ||
105 | + if (title === '单位' && company.length === 0) { | ||
106 | + tip.show('请填写发票抬头'); | ||
107 | + $company.focus(); | ||
108 | + return false; | ||
109 | + } else if (title === '单位' && company.length > 30) { | ||
110 | + tip.show('发票抬头不得超过30个汉字'); | ||
111 | + $company.focus(); | ||
112 | + return false; | ||
113 | + } else if (title === '单位' && !buyerTaxNumber) { | ||
114 | + tip.show('请输入正确的15位或18位纳税人识别号'); | ||
115 | + $company.focus(); | ||
116 | + return false; | ||
117 | + } else { | ||
118 | + dialog.showDialog({ | ||
119 | + dialogText: '确认保存修改内容?', | ||
120 | + hasFooter: { | ||
121 | + leftBtnText: '取消', | ||
122 | + rightBtnText: '确定' | ||
123 | + } | ||
124 | + }, function() { | ||
125 | + orderInfo('invoices_type', eInvoiceType); // 发票类型,目前只有电子发票 | ||
126 | + orderInfo('invoice_title', (title === '单位' ? company : '')); // 发票抬头,个人不传 | ||
127 | + orderInfo('receiverMobile', tel); | ||
128 | + orderInfo('buyerTaxNumber', buyerTaxNumber); | ||
129 | + | ||
130 | + if (isModifyTel && $copyTel !== tel) { | ||
131 | + orderInfo('isModifyTel', true); | ||
132 | + } else { | ||
133 | + orderInfo('isModifyTel', false); | ||
134 | + } | ||
135 | + | ||
136 | + dialog.showDialog({ | ||
137 | + dialogText: '保存成功', | ||
138 | + autoHide: true, | ||
139 | + fast: true | ||
140 | + }); | ||
141 | + goToBack(); | ||
142 | + }, function() { | ||
143 | + goToBack(); | ||
144 | + }); | ||
145 | + } | ||
146 | + } else { | ||
147 | + goToBack(); | ||
148 | + } | ||
149 | +} | ||
150 | + | ||
151 | +// 发票抬头、发票内容选择 | ||
152 | +$('.invoice-top span, .invoice-cont li').not('.invoice-cont .cont-title').on('touchstart', function() { | ||
153 | + chooseAction($(this).parent(), $(this).find('.choose')); | ||
154 | + | ||
155 | + if ($(this).text() === '单位') { | ||
156 | + $company.val(''); | ||
157 | + $company.removeAttr('disabled'); | ||
158 | + $taxNumber.slideDown(); | ||
159 | + } | ||
160 | + | ||
161 | + if ($(this).text() === '个人') { | ||
162 | + $company.val('个人(不可修改)'); | ||
163 | + $company.attr('disabled', 'true'); | ||
164 | + $taxNumber.slideUp(); | ||
165 | + } | ||
166 | + switchBtnStatus(); | ||
167 | +}); | ||
168 | + | ||
169 | +// 发票须知 | ||
170 | +$('.invoice-btn').on('touchstart', function() { | ||
171 | + $invoiceNotice.fadeIn(); | ||
172 | + return false; | ||
173 | +}); | ||
174 | + | ||
175 | +// 关闭发票须知弹框 | ||
176 | +$('.think-ok, .mask-bg').on('touchstart', function() { | ||
177 | + $invoiceNotice.fadeOut(); | ||
178 | +}); | ||
179 | + | ||
180 | +// 电话清空 | ||
181 | +$('.istel').one('input', function() { | ||
182 | + $(this).val('').removeClass('istel'); | ||
183 | +}); | ||
184 | + | ||
185 | +$tel.on('input', function() { | ||
186 | + $(this).attr('data-tel', $(this).val()); | ||
187 | + $editFlag.val('true'); | ||
188 | + isModifyTel = true; | ||
189 | +}); | ||
190 | + | ||
191 | +$company.on('input', function() { | ||
192 | + $editFlag.val('true'); | ||
193 | +}); | ||
194 | + | ||
195 | +// 确认及返回事件 | ||
196 | +$('.confirm-btn, .nav-back').on('touchstart', function(e) { | ||
197 | + | ||
198 | + setTimeout(function() { | ||
199 | + if (window._yas && window._yas.sendCustomInfo) { | ||
200 | + window._yas.sendCustomInfo({ | ||
201 | + op: 'YB_SC_INVOICE_INFO_SAVE', | ||
202 | + param: JSON.stringify({ | ||
203 | + C_ID: C_ID, | ||
204 | + INVOICE_TYPE: eInvoiceType, | ||
205 | + INVOICE_TITLE: $('.invoice-top').find('.on').text(), | ||
206 | + INVOICE_CONTENT: 12 | ||
207 | + }) | ||
208 | + }, true); | ||
209 | + } | ||
210 | + }, 200); | ||
211 | + | ||
212 | + e.preventDefault(); | ||
213 | + confirmAction(); | ||
214 | +}); |
-
Please register or login to post a comment