...
|
...
|
@@ -6,7 +6,12 @@ |
|
|
|
|
|
var $ = require('yoho-jquery'),
|
|
|
lazyLoad = require('yoho-jquery-lazyload'),
|
|
|
Dialog = require('../plugins/dialog').Dialog;
|
|
|
Hbs = require('yoho-handlebars'),
|
|
|
cascadingAddress = require('../plugins/cascading-address'),
|
|
|
popup = require('../plugins/dialog');
|
|
|
|
|
|
var Dialog = popup.Dialog,
|
|
|
Confirm = popup.Confirm;
|
|
|
|
|
|
var minusPlus = {
|
|
|
minus: '',
|
...
|
...
|
@@ -33,12 +38,160 @@ var $invoiceTitleInput, |
|
|
$invoiceEntity,
|
|
|
invoiceDialog;
|
|
|
|
|
|
var addressTpl = Hbs.compile($('#address-dialog-tpl').html());
|
|
|
|
|
|
require('../plugins/check');
|
|
|
|
|
|
lazyLoad($('img.lazy'));
|
|
|
|
|
|
// 地址切换
|
|
|
// 显示全部地址
|
|
|
$('.address-all').click(function() {
|
|
|
$(this).siblings('.address-list').removeClass('shrink').end().remove();
|
|
|
});
|
|
|
|
|
|
// address dialog 数据验证
|
|
|
function validateAddress($el) {
|
|
|
var field = {
|
|
|
name: [
|
|
|
{
|
|
|
noEmpty: true,
|
|
|
err: '收货人不能为空'
|
|
|
},
|
|
|
{
|
|
|
regx: /[\u4e00-\u9fa5a-zA-Z\d]{2,12}/,
|
|
|
err: '请输入2-12个汉字、英文或数字'
|
|
|
}
|
|
|
],
|
|
|
detail: [
|
|
|
{
|
|
|
noEmpty: true,
|
|
|
err: '详细地址不能为空'
|
|
|
},
|
|
|
{
|
|
|
regx: /[\u4e00-\u9fa5a-zA-Z\d#-()]+/,
|
|
|
err: '只能包含数字、字母、汉字、#、-、()及其组合'
|
|
|
}
|
|
|
],
|
|
|
mobile: [
|
|
|
{
|
|
|
noEmpty: true,
|
|
|
err: '手机号码不能为空'
|
|
|
},
|
|
|
{
|
|
|
regx: /\d+/,
|
|
|
err: '手机号码格式不正确'
|
|
|
}
|
|
|
],
|
|
|
phone: [
|
|
|
{
|
|
|
regx: /[\d-]+/,
|
|
|
err: '只能包含数字、-组合',
|
|
|
skipWhenEmpty: true
|
|
|
}
|
|
|
]
|
|
|
};
|
|
|
|
|
|
var key,
|
|
|
$cur,
|
|
|
cur,
|
|
|
vaKey,
|
|
|
vaRegx;
|
|
|
|
|
|
var pass = true;
|
|
|
|
|
|
for (key in field) {
|
|
|
if (field.hasOwnProperty(key)) {
|
|
|
$cur = $el.find('.address-' + key);
|
|
|
cur = $cur.val();
|
|
|
|
|
|
// 按顺序去验证对应filed的值
|
|
|
for (vaKey = 0; vaKey < field[key].length; vaKey++) {
|
|
|
vaRegx = field[key][vaKey];
|
|
|
|
|
|
// 非空验证、非空下正则验证、其他正则验证
|
|
|
if ((vaRegx.noEmpty && cur === '') || (vaRegx.regx &&
|
|
|
(vaRegx.skipWhenEmpty ? !(cur === '' || vaRegx.regx.test(cur)) : !vaRegx.regx.test(cur))
|
|
|
)) {
|
|
|
pass = false;
|
|
|
$cur.siblings('.error-tips').find('em').text(vaRegx.err).end().removeClass('hide');
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return pass;
|
|
|
}
|
|
|
|
|
|
// 地址弹窗Factory
|
|
|
function addressDialogFactory(opt) {
|
|
|
var tplData = $.extend({
|
|
|
dialogAddress: true,
|
|
|
checked: true
|
|
|
}, opt);
|
|
|
|
|
|
var address = new Dialog({
|
|
|
closeIcon: false,
|
|
|
className: 'address',
|
|
|
content: addressTpl(tplData),
|
|
|
btns: [
|
|
|
{
|
|
|
id: 'save-address',
|
|
|
btnClass: ['save-address'],
|
|
|
name: '保存',
|
|
|
cb: function() {
|
|
|
|
|
|
// 验证输入
|
|
|
if (validateAddress(address.$el)) {
|
|
|
address.close();
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
id: 'cancel-address',
|
|
|
btnClass: ['cancel-address', 'white'],
|
|
|
name: '取消',
|
|
|
cb: function() {
|
|
|
address.close();
|
|
|
}
|
|
|
}
|
|
|
]
|
|
|
});
|
|
|
|
|
|
return address;
|
|
|
}
|
|
|
|
|
|
// 初始化弹窗内容
|
|
|
function initAddressContent($el) {
|
|
|
|
|
|
// 初始化地址组件
|
|
|
cascadingAddress({
|
|
|
el: '#address',
|
|
|
url: 'http://localhost:3000/areas/0',
|
|
|
resource: 'areas'
|
|
|
});
|
|
|
|
|
|
$el.find('.default-address-radio').check({
|
|
|
type: 'radio',
|
|
|
onChange: function(el, checked) {
|
|
|
console.log(checked);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 新增地址
|
|
|
$('.new-address').click(function() {
|
|
|
var address = addressDialogFactory();
|
|
|
|
|
|
initAddressContent(address.$el);
|
|
|
|
|
|
address.show();
|
|
|
});
|
|
|
|
|
|
|
|
|
$('.address-list').on('click', '.address', function() {
|
|
|
|
|
|
// 地址切换
|
|
|
var $this = $(this);
|
|
|
|
|
|
if ($this.hasClass('focus')) {
|
...
|
...
|
@@ -47,16 +200,48 @@ $('.address-list').on('click', '.address', function() { |
|
|
|
|
|
$this.addClass('focus');
|
|
|
$this.siblings('.focus').removeClass('focus');
|
|
|
});
|
|
|
}).on('click', '.modify', function(e) {
|
|
|
|
|
|
// 显示全部地址
|
|
|
$('.address-all').click(function() {
|
|
|
$(this).siblings('.address-list').removeClass('shrink').end().remove();
|
|
|
|
|
|
// 修改地址
|
|
|
var $this = $(this).closest('.address');
|
|
|
var address = addressDialogFactory({
|
|
|
updateAddress: true,
|
|
|
name: '徐祁',
|
|
|
detail: '嘉陵江东街18号',
|
|
|
mobile: '15895869035',
|
|
|
id: $this.data('id')
|
|
|
});
|
|
|
|
|
|
initAddressContent(address.$el);
|
|
|
|
|
|
address.show();
|
|
|
|
|
|
e.stopPropagation();
|
|
|
}).on('click', '.delete', function(e) {
|
|
|
|
|
|
// 删除地址
|
|
|
// var $this = $(this).closest('.address');
|
|
|
// var id = $this.data('id');
|
|
|
|
|
|
new Confirm({
|
|
|
className: 'address-confirm-dialog',
|
|
|
content: '<p class="main">删除地址</p><p class="sub">您确定要删除该收货地址吗?</p>',
|
|
|
cb: function() {
|
|
|
|
|
|
// 确认删除,do something
|
|
|
}
|
|
|
}).show();
|
|
|
|
|
|
e.stopPropagation();
|
|
|
}).on('click', '.set-default', function(e) {
|
|
|
|
|
|
// 设置为默认地址
|
|
|
|
|
|
e.stopPropagation();
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 发票弹窗Factory
|
|
|
*/
|
|
|
// 发票弹窗Factory
|
|
|
function invoiceDialogFactory() {
|
|
|
var invoice = new Dialog({
|
|
|
className: 'invoice',
|
...
|
...
|
|