|
|
/**
|
|
|
* 订单结算页
|
|
|
* @author: yyq<yanqing.yang@yoho.cn>
|
|
|
* @date: 2016/11/30
|
|
|
* @date: 2016/12/20
|
|
|
*/
|
|
|
|
|
|
// var $ = require('yoho-jquery');
|
|
|
var $ = require('yoho-jquery');
|
|
|
var hbs = require('yoho-handlebars');
|
|
|
var dialog = require('../../common/dialog');
|
|
|
var Dialog = dialog.Dialog;
|
|
|
|
|
|
// var Confirm = dialog.Confirm;
|
|
|
// var Alert = dialog.Alert;
|
|
|
|
|
|
var addressTpl = hbs.compile($('#address-tpl').html());
|
|
|
|
|
|
Dialog.prototype.packageInfo = function() {
|
|
|
var data = {};
|
|
|
var province = this.$el.find('.province').val(),
|
|
|
city = this.$el.find('.city').val(),
|
|
|
country = this.$el.find('.country').val();
|
|
|
|
|
|
this.$el.find('input').each(function() {
|
|
|
var $this = $(this),
|
|
|
key = $this.attr('name');
|
|
|
|
|
|
if (key) {
|
|
|
data[key] = $.trim($this.val());
|
|
|
}
|
|
|
});
|
|
|
|
|
|
data.areacode = (province || '00') + '' + (city || '00') + (country || '00');
|
|
|
|
|
|
if (this.$el.find('.radio-btn.on').length) {
|
|
|
data.setDefault = true;
|
|
|
}
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
|
|
|
function validateAddress(data) {
|
|
|
var regx = {
|
|
|
consignee: /^[\u4e00-\u9fa5]{2,5}$/,
|
|
|
areacode: /^[0-9]{6}$/,
|
|
|
mobile: /^\d{3}(\d{4}|\*{4})\d{4}$/,
|
|
|
tel: /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/
|
|
|
},
|
|
|
pass = true,
|
|
|
i;
|
|
|
|
|
|
data = data || {};
|
|
|
for (i in data) {
|
|
|
if (data.hasOwnProperty(i) &&
|
|
|
regx[i] &&
|
|
|
!regx[i].test(data[i])) {
|
|
|
pass = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return pass;
|
|
|
}
|
|
|
|
|
|
function bindOperateEvent($el) {
|
|
|
var $province = $el.find('.province'),
|
|
|
$city = $el.find('.city'),
|
|
|
$country = $el.find('.country');
|
|
|
|
|
|
$el.on('change', 'input[name="consignee"]', function() {
|
|
|
var $this = $(this);
|
|
|
var val = $.trim($this.val());
|
|
|
|
|
|
if (!val) {
|
|
|
$this.siblings('.caveat-tip').text('收货人不能为空').show();
|
|
|
} else if (!validateAddress({consignee: val})) {
|
|
|
$this.siblings('.caveat-tip').text('收货人姓名至少2个中文,最多5个中文').show();
|
|
|
} else {
|
|
|
$this.siblings('.caveat-tip').empty().hide();
|
|
|
}
|
|
|
}).on('change', '.country', function() {
|
|
|
var code = '' + $province.val() + $city.val() + $country.val();
|
|
|
|
|
|
if (!validateAddress({areacode: code})) {
|
|
|
$province.parent().siblings('.caveat-tip').show().text('请选择省市县').prev().hide();
|
|
|
} else {
|
|
|
$province.parent().siblings('.caveat-tip').empty().hide().prev().show();
|
|
|
}
|
|
|
}).on('change', 'input[name="address"]', function() {
|
|
|
var $this = $(this);
|
|
|
var val = $.trim($this.val());
|
|
|
|
|
|
if (!val) {
|
|
|
$this.siblings('.caveat-tip').text('收货地址不能为空').show();
|
|
|
} else {
|
|
|
$this.siblings('.caveat-tip').empty().hide();
|
|
|
}
|
|
|
$country.trigger('change');
|
|
|
}).on('change', 'input[name="mobile"]', function() {
|
|
|
var $this = $(this);
|
|
|
var val = $.trim($this.val());
|
|
|
|
|
|
if (!val) {
|
|
|
$this.siblings('.caveat-tip').text('手机号码不能为空').show();
|
|
|
} else if (!validateAddress({mobile: val})) {
|
|
|
$this.siblings('.caveat-tip').text('您输入的手机号码格式不正确').show();
|
|
|
} else {
|
|
|
$this.siblings('.caveat-tip').empty().hide();
|
|
|
}
|
|
|
}).on('change', 'input[name="tel"]', function() {
|
|
|
var $this = $(this);
|
|
|
var val = $.trim($this.val());
|
|
|
|
|
|
if (val && !validateAddress({tel: val})) {
|
|
|
$this.siblings('.caveat-tip').text('您输入的电话格式不正确').show();
|
|
|
} else {
|
|
|
$this.siblings('.caveat-tip').empty().hide();
|
|
|
}
|
|
|
}).on('click', '.radio-btn', function() {
|
|
|
$(this).toggleClass('on');
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function newEditAddress(info) {
|
|
|
var addDia = new Dialog({
|
|
|
content: addressTpl({
|
|
|
title: '新增地址'
|
|
|
}),
|
|
|
className: 'ope-address-dialog',
|
|
|
btns: [{
|
|
|
id: 1,
|
|
|
name: '保存',
|
|
|
btnClass: ['black'],
|
|
|
cb: function() {
|
|
|
console.log(addDia.packageInfo());
|
|
|
|
|
|
console.log(info);
|
|
|
// window.open(myCouponUrl);
|
|
|
}
|
|
|
}, {
|
|
|
id: 2,
|
|
|
name: '取消',
|
|
|
btnClass: ['btn-close']
|
|
|
}]
|
|
|
}).show();
|
|
|
|
|
|
bindOperateEvent(addDia.$el);
|
|
|
}
|
|
|
|
|
|
$('#new-address-btn').click(function() {
|
|
|
newEditAddress();
|
|
|
});
|
|
|
|
...
|
...
|
|