Authored by 郭成尧

invoice-page

... ... @@ -6,6 +6,7 @@ const cartModel = require('../models/cart');
const headerModel = require('../../../doraemon/models/header');
const userModel = require('../../serverAPI/user');
const addressModel = require('../../serverAPI/user/address');
const orderModel = require('../models/order');
exports.orderEnsure = (req, res, next) => {
... ... @@ -45,51 +46,46 @@ exports.orderEnsure = (req, res, next) => {
let userProfile = userModel.queryProfile(uid);
let address = addressModel.addressData(uid);
return Promise.all([order, userProfile, address])
.then(
result => {
order = result[0];
userProfile = result[1];
address = result[2];
if (order.cartUrl) { // TODO? 普通或者预售商品为空时, BUT WHEN AJAX?
return res.redirect(order.cartUrl);
}
if (req.xhr) {
return res.json(order);
}
// 获取用户完整手机号
let mobile = _.get(userProfile, 'data.mobile', '');
let orderAddress = _.get(order, 'address', []);
let addressList = _.get(address, 'data', []);
orderAddress.length && addressList.forEach(address => { //eslint-disable-line
if (address.address_id === orderAddress.address_id) {
mobile = address.mobile;
}
});
let viewData = {
orderEnsurePage: true,
isOrdinaryCart: cartType !== 'advance',
orderEnsure: order,
userMobile: mobile
};
viewData.pageHeader = headerData;
viewData.pageFooter = true;
viewData.module = 'cart';
viewData.page = 'order-ensure';
viewData.width750 = true;
viewData.title = '确认订单';
res.render('order-ensure', viewData);
return Promise.all([order, userProfile, address]).then(result => {
order = result[0];
userProfile = result[1];
address = result[2];
if (order.cartUrl) { // TODO? 普通或者预售商品为空时, BUT WHEN AJAX?
return res.redirect(order.cartUrl);
}
if (req.xhr) {
return res.json(order);
}
// 获取用户完整手机号
let mobile = _.get(userProfile, 'data.mobile', '');
let orderAddress = _.get(order, 'address', []);
let addressList = _.get(address, 'data', []);
orderAddress.length && addressList.forEach(address => { //eslint-disable-line
if (address.address_id === orderAddress.address_id) {
mobile = address.mobile;
}
)
.catch(next);
});
let viewData = {
orderEnsurePage: true,
isOrdinaryCart: cartType !== 'advance',
orderEnsure: order,
userMobile: mobile
};
viewData.pageHeader = headerData;
viewData.pageFooter = true;
viewData.module = 'cart';
viewData.page = 'order-ensure';
viewData.width750 = true;
viewData.title = '确认订单';
res.render('order-ensure', viewData);
}).catch(next);
};
/**
... ... @@ -149,40 +145,42 @@ exports.couponSearch = (req, res, next) => {
})();
};
/**
* 选择地址
*/
exports.selectAddress = (req, res, next) => {
let uid = req.user.uid;
return addressModel.addressData(uid)
.then(address => {
let moreUrl = req.get('Referer') || '/cart/index/new/orderEnsure'; // 取跳过来的url
return addressModel.addressData(uid).then(address => {
let moreUrl = req.get('Referer') || '/cart/index/new/orderEnsure'; // 取跳过来的url
address = address.data;
address = address.data;
// 购物车订单进来,秒杀进来
if (
moreUrl.indexOf('/cart/index/new/orderEnsure') !== -1 ||
moreUrl.indexOf('/cart/index/seckill') !== -1
) {
req.session.addressMore = moreUrl; // TODO: 注意cookie-session
}
// 购物车订单进来,秒杀进来
if (
moreUrl.indexOf('/cart/index/new/orderEnsure') !== -1 ||
moreUrl.indexOf('/cart/index/seckill') !== -1
) {
req.session.addressMore = moreUrl; // TODO: 注意cookie-session
}
moreUrl = req.session.addressMore;
moreUrl = req.session.addressMore;
let headerData = headerModel.setNav({
navTitle: '选择地址',
navBtn: false,
backUrl: moreUrl
});
let headerData = headerModel.setNav({
navTitle: '选择地址',
navBtn: false,
backUrl: moreUrl
});
res.render('select-address', {
module: 'cart',
page: 'select-address',
pageHeader: headerData,
pageFooter: true,
moreUrl,
address
});
res.render('select-address', {
module: 'cart',
page: 'select-address',
pageHeader: headerData,
pageFooter: true,
moreUrl,
address
});
}).catch(next);
};
/**
... ... @@ -190,14 +188,23 @@ exports.selectAddress = (req, res, next) => {
*/
exports.invoiceInfo = (req, res, next) => {
let uid = req.user.uid;
let cookieData = req.cookies['order-info'];
let orderInfo = JSON.parse(cookieData);
let orderInfo = req.cookies.orderInfo;
try {
orderInfo = JSON.parse(orderInfo);
} catch (e) {
orderInfo = {};
}
co(function* () {
let userData = yield userModel.queryProfile(uid);
let mobile = _.get(userData, 'data.mobile', '');
let addresslist = yield userModel.addressTextData(uid);
let returnData = orderModel.processInvoiceData(orderInfo, mobile, addresslist);
let headerData = headerModel.setNav({
navTitle: '发票信息',
navBtn: false
});
res.render('select-invoice', _.assign(returnData, {
pageHeader: headerData,
module: 'cart',
page: 'select-invoice'
})).catch(next);
})();
};
... ...
'use strict';
const _ = require('lodash');
const crypto = global.yoho.crypto;
const processInvoiceData = (orderInfo, mobile, addresslist) => {
let invoices_title = '';
let invoiceType = '7';
let invoices_type = '2';
let invoice_Top = '个人';
// 用户手机号处理
if (orderInfo.receiverMobile && orderInfo.isModifyTel) {
mobile = orderInfo.receiverMobile;
} else {
_.forEach(addresslist, addressValue => {
if (addressValue.address_id === crypto.encryption('', orderInfo.addressId)) {
mobile = addressValue.mobile;
}
});
}
// 发票信息处理
if (orderInfo.invoiceType && orderInfo.invoiceTitle) {
invoices_title = orderInfo.invoiceText;
invoiceType = orderInfo.invoiceType;
invoices_type = orderInfo.invoicesType * 1;
invoice_Top = orderInfo.invoiceTitle;
}
return {
invoiceNotice: '发票须知',
phone: mobile ? mobile : '', // TODO 字符串替换 ****
completeTel: mobile,
isCompany: invoice_Top !== '单位',
companyName: invoices_title,
isPaper: invoices_type === 1,
invoicesType: [
{
id: '2',
type: '电子发票',
choosed: !invoices_type || invoices_type === 2,
},
{
id: '1',
type: '纸质发票',
choosed: invoices_type === 1
}
],
invoiceTitle: [
{
type: '个人',
choosed: invoice_Top === '个人'
},
{
type: '单位',
choosed: invoice_Top === '单位'
}
],
content: [
{
choosed: !invoiceType || invoiceType === 7,
id: 7,
text: '服装'
},
{
choosed: invoiceType === 9,
id: 9,
text: '配件'
},
{
choosed: invoiceType === 11,
id: 11,
text: '日用品'
},
{
choosed: invoiceType === 3,
id: 3,
text: '办公用品'
},
{
choosed: invoiceType === 6,
id: 6,
text: '体育用品'
},
{
choosed: invoiceType === 10,
id: 10,
text: '数码产品'
},
]
};
};
module.exports = {
processInvoiceData
};
... ...
... ... @@ -132,7 +132,7 @@
<input type="hidden" class="user-mobile" value="{{userMobile}}" />
<span class="title">发票</span>
<span class="iconfont checkbox {{#if needInvoice}}icon-cb-radio{{else}}icon-radio{{/if}}"></span>
<a id="invoice" class="invoice-info" href="/cart/index/invoiceInfo">
<a id="invoice" class="invoice-info" href="/cart/index/new/invoiceInfo">
<span class="title">发票信息</span>
<span class="invoice-type"><i class="iconfont">&#xe614;</i></span>
</a>
... ...
<div class="invoice-info-page yoho-page">
<ul class="invoice-form">
<li>
<span class="title">发票类型:</span>
<div class="invoice-type">
{{#invoicesType}}
<span {{#if choosed}}class="on"{{/if}} data-id="{{id}}">{{type}}</span>
{{/invoicesType}}
</div>
</li>
<li>
<span class="title">发票抬头:</span>
<div class="invoice-top">
{{#invoiceTitle}}
<span {{#if choosed}}class="on"{{/if}}><i class="iconfont choose {{#if choosed}}icon-cb-radio{{else}}icon-radio{{/if}}"></i>{{type}}</span>
{{/invoiceTitle}}
</div>
</li>
<li {{#isPaper}}style="display: none;"{{/isPaper}} class="tel-area">
<span class="title"><i class="txt-point">*</i>发票人手机:</span>
<span class="phone">
<input type="hidden" class="copy-tel" value="{{completeTel}}">
<input type="text" name="tel" data-tel="{{completeTel}}" class="tel {{#phone}}istel{{/phone}}" value="{{phone}}" placeholder="可通过手机号在发票服务平台查询">
</span>
</li>
<li class="company-area" {{#isCompany}}style="display: none;"{{/isCompany}}><input type="text" name="company" class="company" value="{{companyName}}" placeholder="填写单位名称" maxlength="30"></li>
</ul>
<ul class="invoice-cont">
<li class="cont-title">
<span>发票内容:</span>
<span class="choose-cont" data-id=""></span>
</li>
{{#each content}}
<li><span class="iconfont choose {{#if choosed}}icon-cb-radio{{else}}icon-radio{{/if}}" data-id="{{id}}"></span>{{text}}</li>
{{/each}}
</ul>
<div class="btn-area"><span class="confirm-btn">确认</span></div>
<div class="invoice-notice">
<div class="mask-bg"></div>
<div class="notice-area">
<div class="notice-cont">
<h2>发票须知</h2>
<p>1、发票金额不含优惠券/有货币/红包/优惠码/运费,只包含商品实付金额</p>
<p>2、电子发票:是税局认可的有效收付款凭证,其法律效力、基本用途及使用规定同纸质发票,如需纸质发票可自行下载打印</p>
</div>
<div class="think-ok">我知道了</div>
</div>
</div>
<input type="hidden" class="edit-flag" value="false" />
<input type="hidden" class="address-more" value="{{addressMore}}" />
</div>
... ...
... ... @@ -21,3 +21,10 @@ exports.queryProfile = (uid) => {
return api.get('', params, options);
};
exports.addressTextData = (uid) => {
return api.get('', {
method: 'app.address.get',
uid: uid
});
};
... ...
/**
* 发票信息
* @author: wsl<shuiling.wang@yoho.cn>
* @date: 2016/6/14
*/
var $ = require('yoho-jquery'),
tip = require('../plugin/tip'),
dialog = require('../plugin/dialog'),
order = require('./order-info');
var $invoiceNotice = $('.invoice-notice'),
$companyArea = $('.company-area'),
$editFlag = $('.edit-flag'),
$chooseCont = $('.choose-cont'),
$invoiceType = $('.invoice-type'),
$tel = $('.tel'),
$company = $('.company'),
$telArea = $('.tel-area'),
orderInfo = order.orderInfo,
$chooseContLi = $('.invoice-cont').find('.icon-cb-radio').parent(),
$copyTel = $('.copy-tel'),
isModifyTel = false;
var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$/,
linkUrl = $('.address-more').val() || '/cart/index/orderEnsure?cartType=ordinary';
var C_ID = window._ChannelVary[window.cookie('_Channel')] || 1;
require('../common');
if (window.getUid() !== orderInfo('uid')) {
order.init();
window.location.reload();
}
// 单选效果
function chooseAction(pDom, dom) {
if (dom.hasClass('icon-cb-radio')) {
return;
} else {
pDom.find('.choose').removeClass('icon-cb-radio icon-radio').addClass('icon-radio');
dom.removeClass('icon-radio').addClass('icon-cb-radio');
dom.parent().addClass('on');
dom.parent().siblings().removeClass('on');
$editFlag.val('true');
}
}
// 确认表单事件
function confirmAction() {
var type = $invoiceType.find('.on').data('id'),
title = $('.invoice-top').find('.on').text(),
tel = $tel.attr('data-tel'),
company = $company.val(),
cont = $chooseCont.data('id');
if ($editFlag.val() === 'true') {
if (type === 2 && !myreg.test($tel.attr('data-tel'))) {
tip.show('请输入正确手机号');
$tel.focus();
return false;
} else if (title === '单位' && company.length === 0) {
tip.show('请填写发票抬头');
$company.focus();
return false;
} else if (title === '单位' && company.length > 30) {
tip.show('发票抬头不得超过30个汉字');
$company.focus();
return false;
} else {
dialog.showDialog({
dialogText: '确认保存修改内容?',
hasFooter: {
leftBtnText: '取消',
rightBtnText: '确定'
}
}, function() {
orderInfo('invoiceText', (title === '单位' ? company : ''));
orderInfo('invoiceType', cont);
orderInfo('receiverMobile', tel);
orderInfo('invoicesType', type);
orderInfo('invoiceTitle', title);
if (isModifyTel && $copyTel !== tel) {
orderInfo('isModifyTel', true);
} else {
orderInfo('isModifyTel', false);
}
dialog.showDialog({
dialogText: '保存成功',
autoHide: true,
fast: true
});
window.location.href = linkUrl;
}, function() {
window.location.href = linkUrl;
});
}
} else {
window.location.href = linkUrl;
}
}
$chooseCont.html($chooseContLi.text()).attr('data-id', $chooseContLi.find('span').data('id'));
// 发票抬头、发票内容选择
$('.invoice-top span, .invoice-cont li').not('.invoice-cont .cont-title').on('touchstart', function() {
chooseAction($(this).parent(), $(this).find('.choose'));
if ($(this).parent().hasClass('invoice-cont')) {
$chooseCont.html($(this).text()).attr('data-id', $(this).find('span').data('id'));
}
if ($(this).text() === '单位') {
$companyArea.slideDown();
}
if ($(this).text() === '个人') {
$companyArea.slideUp();
}
});
// 发票类型选择
$('.invoice-type span').on('touchstart', function() {
if ($(this).hasClass('on')) {
return;
} else {
$(this).addClass('on').siblings().removeClass('on');
$editFlag.val('true');
// 纸质发票不显示手机号
if ($(this).index() === 1) {
$telArea.slideUp();
} else {
$telArea.slideDown();
}
}
});
// 发票须知
$('.invoice-btn').on('touchstart', function() {
$invoiceNotice.fadeIn();
return false;
});
// 关闭发票须知弹框
$('.think-ok, .mask-bg').on('touchstart', function() {
$invoiceNotice.fadeOut();
});
// 电话清空
$('.istel').one('input', function() {
$(this).val('').removeClass('istel');
});
$tel.on('input', function() {
$(this).attr('data-tel', $(this).val());
$editFlag.val('true');
isModifyTel = true;
});
$company.on('input', function() {
$editFlag.val('true');
});
// 确认及返回事件
$('.confirm-btn, .nav-back').on('touchstart', function(e) {
setTimeout(function() {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_SC_INVOICE_INFO_SAVE',
param: JSON.stringify({
C_ID: C_ID,
INVOICE_TYPE: $invoiceType.find('.on').data('id'),
INVOICE_TITLE: $('.invoice-top').find('.on').text(),
INVOICE_CONTENT: $chooseCont.data('id')
})
}, true);
}
}, 200);
e.preventDefault();
confirmAction();
});
// initData();
... ...
... ... @@ -590,7 +590,7 @@
span {
display: inline-block;
width: 130px;
width: 160px;
}
}
... ...