Authored by 刘传洋

Merge branch 'feature/shoppingCart' of http://git.yoho.cn/fe/yohobuy-node into feature/shoppingCart

... ... @@ -8,7 +8,6 @@
<div class="block-title">收货信息<span id="new-address-btn" class="right">新增收货地址 +</span></div>
<div id="addr-list" class="addr-list clearfix">
{{# deliveryAddress}}
{{log this}}
<div class="addr-item{{#isY is_default}} addr-default addr-select{{/isY}}" data-id="{{id}}" data-consignee="{{consignee}}" data-mobile="{{mobile}}" data-phone="{{phone}}" data-area="{{area}}" data-code="{{area_code}}" data-address="{{address}}"{{#isY is_default}} data-default="1"{{/isY}}{{#isY is_delivery}} data-delivery="1"{{/isY}}>
<p class="name">
{{consignee}}
... ... @@ -115,9 +114,11 @@
</div>
<div class="invoice-wrap">
<div class="block-title">发票信息</div>
<p>
<label class="radio-btn">发票开具</label>
</p>
<label id="invoice-radio" class="invoice-radio radio-btn">发票开具</label>
<div class="invoice-info-view hide">
<span></span>
<label id="modify-invoice">修改</label>
</div>
</div>
<div class="extra-wrap">
<dl>
... ... @@ -144,10 +145,7 @@
</li>
{{/each}}
</ul>
<p id="delivery-detail" class="delivery-detail">
寄送至:<br>
收货人:
</p>
<p id="delivery-detail" class="delivery-detail"></p>
</div>
<div class="sum-wrap">
... ...
... ... @@ -73,3 +73,68 @@
</p>
</div>
</script>
<script id="invoice-chose-tpl" type="text/html">
<p class="invoice-header">发票信息</p>
<ul class="invoice-type">
<li class="el-invoice focus">电子发票</li>
<li class="pa-invoice">纸质发票</li>
</ul>
<div class="invoice-content el-content">
<p class="el-tip">
※ 电子发票是税务局认可的有效凭证,其法律效力、基本用途及使用规定同纸质发票,如需纸质发票可自行下载打印。<br>
<a href="//www.yohobuy.com/help?category_id=99">什么是电子发票?</a>
</p>
<ul>
<li class="invoice-title invoice-row">
<span class="row-title">
<em>*</em>
发票抬头
</span>
<div class="row-content">
<span class="radio-wrap">
<label class="rbt-1 radio-btn on" data-id="1"></label> 个人
</span>
<span class="radio-wrap">
<label class="rbt-2 radio-btn" data-id="2"></label> 单位
</span>
<div class="company-row hide">
<input id="company-name" class="company-name" type="text" placeholder="请填写单位名称">
<span class="input-tip invoice-title-tip red hide">
<span class="iconfont">&#xe629;</span>
请填写发票抬头
</span>
</div>
</div>
</li>
<li class="invoice-goods-type invoice-row">
<span class="row-title">
<em>*</em>
发票内容:
</span>
<div class="row-content">
{{#each invoices.invoiceContentList}}
<span class="radio-wrap">
<label class="radio-btn rbc-{{invoices_type_id}}{{#if @first}} on{{/if}}" data-id="{{invoices_type_id}}" data-name="{{invoices_type_name}}"></label> {{invoices_type_name}}
</span>
{{/each}}
</div>
</li>
<li class="receiver invoice-row">
<span class="row-title">
<em>*</em>
手机号码:
</span>
<div class="row-content">
<input id="receiver-phone" class="receiver-phone" type="text">
<span class="input-tip receiver-tip red hide">
<span class="iconfont">&#xe629;</span>
<em></em>
</span>
</div>
</li>
</ul>
</div>
</script>
... ...
... ... @@ -12,6 +12,7 @@ var payWay,
deliveryWay;
require('./order-new/address');
require('./order-new/invoice');
// 支付方式
payWay = {
... ... @@ -129,17 +130,6 @@ deliveryWay = {
// 更新订单送货时间数据
that.updateOrder({time: $this.data('id')});
});
// 仅前端展示,该数据无作用,接口不接受此参数
$('.delivery-time-wrap .radio-btn').click(function() {
var $this = $(this);
if ($this.hasClass('on')) {
return;
}
$this.siblings('.on').removeClass('on');
$this.addClass('on');
});
},
updateOrder: function(info) {
if (!info) {
... ...
... ... @@ -145,11 +145,11 @@ function setDefaultAddr(id, cb) {
$.ajax({
url: '/cart/address/setdefault',
type: 'POST',
data: {id: id},
data: {id: id}
}).done(function(data) {
if (data.code === 200 && cb && typeof cb === 'function') {
cb();
addrDefault = id;
return cb();
}
});
}
... ... @@ -252,7 +252,7 @@ function newEditAddress(title, info, $el) {
$.ajax({
url: '/cart/address/save',
type: 'POST',
data: data,
data: data
}).done(function(resData) {
if (resData.code === 200) {
$.extend(data, area.text());
... ... @@ -359,11 +359,10 @@ $addrWrap.on('click', '.addr-item', function() {
}).show();
});
$('.addr-opt').on('click', 'span', function(event) {
$('.addr-opt').on('click', 'span', function() {
var $this = $(this).parent(),
$sel;
var height = 650,
index;
var height = 650;
if ($this.hasClass('open')) {
height = 212;
... ...
/**
* 订单结算页
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/12/29
*/
var $ = require('yoho-jquery');
var Dialog = require('../../common/dialog').Dialog;
var $invoiceRadio = $('#invoice-radio');
var invoiceTpl = $('#invoice-chose-tpl').html();
var invoiceInfo = {};
function validateInvoice($el, info) {
var pass = true;
var $receiverTip;
// 发票抬头
if (!info.titleName) {
pass = false;
$('.invoice-title-tip', $el).removeClass('hide');
} else {
$('.invoice-title-tip', $el).addClass('hide');
}
// 收票人手机号
if (info.invocesType * 1 === 2) {
$receiverTip = $('.receiver-tip', $el);
if (!info.receiver) {
$receiverTip.removeClass('hide').find('em').html('请填写手机号码');
pass = false;
} else if (!/^[0-9]{11}$/.test(info.receiver)) {
$receiverTip.removeClass('hide').find('em').html('手机号码不正确');
pass = false;
} else {
$receiverTip.addClass('hide');
}
}
return pass;
}
function bindInvoiceEvent($el) {
var $invoiceTypeWrap = $('.invoice-type', $el),
$titleWrap = $('.invoice-title', $el),
$goodsTypeWrap = $('.invoice-goods-type', $el),
$receiver = $('.receiver', $el),
$companyRow = $('.company-row', $el);
$invoiceTypeWrap.on('click', 'li', function() {
var $this = $(this);
if ($this.hasClass('focus')) {
return;
}
if ($this.hasClass('el-invoice')) {
$receiver.removeClass('hide');
} else {
$receiver.addClass('hide');
}
$this.siblings('.focus').removeClass('focus');
$this.addClass('focus');
});
$titleWrap.on('click', '.radio-btn', function() {
var $this = $(this),
id = $this.data('id');
if ($this.hasClass('on')) {
return;
}
if (id * 1 === 2) {
$companyRow.removeClass('hide');
} else {
$companyRow.addClass('hide');
}
$titleWrap.find('.on').removeClass('on');
$this.addClass('on');
});
$goodsTypeWrap.on('click', '.radio-btn', function() {
var $this = $(this);
if ($this.hasClass('on')) {
return;
}
$goodsTypeWrap.find('.on').removeClass('on');
$this.addClass('on');
});
}
function bindInvoiceInfo($el, info) {
info = info || {};
// 发票类型
if (info.invocesType === 1) {
$('.pa-invoice', $el).trigger('click');
}
if (info.titleId) {
$('.rbt-' + info.titleId).trigger('click');
if (info.titleId === 2 && info.titleName) {
$('#company-name', $el).val(info.titleName);
}
}
if (info.contentId) {
$('.rbc-' + info.contentId, $el).trigger('click');
}
$('#receiver-phone', $el).val(info.receiver || '');
}
function packInvoiceInfo($el) {
var $goodsType = $('.invoice-goods-type .on', $el);
var resData = {},
receiver = $('#receiver-phone', $el).val();
if ($('.pa-invoice', $el).hasClass('focus')) {
resData.invocesType = 1;
} else {
resData.invocesType = 2;
}
resData.titleId = $('.invoice-title .on', $el).data('id') || 1;
if (resData.titleId * 1 === 1) {
resData.titleName = '个人';
} else {
resData.titleName = $('#company-name', $el).val();
}
resData.contentId = $goodsType.data('id');
resData.contentName = $goodsType.data('name');
if (receiver) {
resData.receiver = receiver;
}
return resData;
}
function setShowInvoiceInfo() {
var $dom = $invoiceRadio.next();
var _h = '';
if (!invoiceInfo.invocesType) {
$dom.addClass('hide');
return;
}
if (invoiceInfo.invocesType * 1 === 1) {
_h += '纸质发票';
} else {
_h += '电子发票';
}
_h += '&nbsp;&nbsp;&nbsp;&nbsp;' + invoiceInfo.titleName +
'&nbsp;&nbsp;&nbsp;&nbsp;' + invoiceInfo.contentName;
$dom.removeClass('hide').find('span').html(_h);
}
function invoiceEditDialog(baseInfo) {
var invoice = new Dialog({
content: invoiceTpl,
className: 'ensure-invoice-dialog',
btns: [
{
id: 'save-invoice',
name: '保存发票信息',
btnClass: ['save-invoice'],
cb: function() {
var info = packInvoiceInfo(invoice.$el);
if (validateInvoice(invoice.$el, info)) {
$.extend(invoiceInfo, packInvoiceInfo(invoice.$el));
setShowInvoiceInfo();
invoice.close();
}
}
},
{
id: 'cancel-invoice',
name: '取消',
btnClass: ['btn-close'],
cb: function() {
invoice.close();
if (!invoiceInfo.invocesType) {
$invoiceRadio.removeClass('on');
}
}
}
]
});
bindInvoiceEvent(invoice.$el);
bindInvoiceInfo(invoice.$el, baseInfo);
return invoice;
}
$invoiceRadio.click(function() {
$invoiceRadio.toggleClass('on');
if ($invoiceRadio.hasClass('on')) {
invoiceEditDialog(invoiceInfo).show();
} else {
invoiceInfo = {};
setShowInvoiceInfo();
}
});
$('#modify-invoice').click(function() {
invoiceEditDialog(invoiceInfo).show();
});
// 获取发票信息
exports.getInvoice = function() {
if (!$invoiceRadio.hasClass('on') || !invoiceInfo.invocesType) {
return;
}
return {
invoicesType: invoiceInfo.invocesType,
invoicesTitle: invoiceInfo.titleName,
invoicesContent: invoiceInfo.contentId,
receiver: invoiceInfo.receiver
};
};
... ...
... ... @@ -451,9 +451,29 @@
border-left: 1px solid $borderColor;
border-right: 1px solid $borderColor;
> p {
.invoice-radio {
line-height: 70px;
padding-left: 20px;
margin-left: 20px;
font-size: 14px;
}
.invoice-info-view {
display: inline-block;
float: right;
line-height: 70px;
padding-right: 20px;
font-size: 14px;
> label {
width: 80px;
height: 24px;
line-height: 24px;
border: 1px solid #444;
margin-left: 20px;
display: inline-block;
text-align: center;
cursor: pointer;
}
}
}
... ... @@ -765,3 +785,138 @@
}
}
}
.ensure-invoice-dialog {
$red: #d0021b;
width: 440px;
font-size: 14px;
color: #444;
background-color: #fff;
.radio-btn {
&:before {
content: '';
width: 15px;
height: 15px;
margin-right: 4px;
background-image: url(/cart/radio-off.png);
display: inline-block;
vertical-align: middle;
position: relative;
top: -2px;
cursor: pointer;
}
&.on:before {
background-image: url(/cart/radio-on.png);
}
}
> .close {
top: 10px;
right: 12px;
.iconfont {
font-size: 32px;
}
}
> .content {
text-align: left;
}
.invoice-header {
font-size: 18px;
padding-bottom: 10px;
border-bottom: 1px solid #e8e8e8;
}
.invoice-type {
padding: 20px 0;
> li {
width: 98px;
height: 28px;
line-height: 28px;
text-align: center;
font-size: 14px;
margin-right: 17px;
border: 1px solid #505050;
color: #505050;
display: inline-block;
cursor: pointer;
}
.focus {
border-color: #d0021b;
color: #d0021b;
}
}
.el-tip {
background-color: #f5f5f5;
padding: 14px;
line-height: 1.5;
> a {
color: $red;
display: inline-block;
padding-top: 12px;
}
}
.invoice-row {
padding-top: 16px;
padding-left: 84px;
overflow: hidden;
.row-content {
width: 110%;
}
.row-title {
line-height: 30px;
position: absolute;
margin-left: -84px;
> em {
color: $red;
margin-right: 3px;
position: relative;
top: 2px;
}
}
.radio-wrap {
width: 92px;
display: inline-block;
padding: 8px 0;
}
input {
width: 194px;
height: 26px;
padding: 0 10px;
}
.red {
color: $red;
}
}
.btns {
padding-top: 28px;
padding-bottom: 10px;
.btn {
width: 130px;
height: 28px;
line-height: 28px;
}
.save-invoice {
background-color: #000;
color: #fff;
}
}
}
... ...