...
|
...
|
@@ -122,7 +122,9 @@ function addressDialogFactory(opt, $the) { |
|
|
consignee,
|
|
|
detail,
|
|
|
mobile,
|
|
|
phone;
|
|
|
phone,
|
|
|
areaCode,
|
|
|
isDefault;
|
|
|
|
|
|
// 验证输入
|
|
|
if (validateAddress(address.$el)) {
|
...
|
...
|
@@ -132,6 +134,8 @@ function addressDialogFactory(opt, $the) { |
|
|
detail = $el.find('.address-detail').val();
|
|
|
mobile = $el.find('.address-mobile').val();
|
|
|
phone = $el.find('.address-phone').val();
|
|
|
areaCode = $el.address.getAreaIds().split(',')[2];
|
|
|
isDefault = $el.default ? 'Y' : 'N';
|
|
|
|
|
|
if (opt && opt.id) {
|
|
|
|
...
|
...
|
@@ -146,22 +150,22 @@ function addressDialogFactory(opt, $the) { |
|
|
address: detail,
|
|
|
mobile: mobile,
|
|
|
phone: phone,
|
|
|
'area_code': '320107'// eslint-disable-line
|
|
|
'is_default': isDefault, // eslint-disable-line
|
|
|
'area_code': areaCode // eslint-disable-line
|
|
|
}
|
|
|
}).then(function(data) {
|
|
|
if (data.code === 200) {
|
|
|
$the.before(addressTpl({
|
|
|
address: [
|
|
|
{
|
|
|
consignee: consignee,
|
|
|
address: detail,
|
|
|
mobile: mobile,
|
|
|
phone: phone,
|
|
|
area_code: data.data.area_code, // eslint-disable-line
|
|
|
id: opt.id,
|
|
|
focus: $the.hasClass('focus')
|
|
|
}
|
|
|
]
|
|
|
address: [{
|
|
|
consignee: consignee,
|
|
|
address: detail,
|
|
|
mobile: mobile,
|
|
|
phone: phone,
|
|
|
area_code: data.data.area_code, // eslint-disable-line
|
|
|
id: opt.id,
|
|
|
focus: $the.hasClass('focus'),
|
|
|
area: $el.address.getAreaLabels().replace(/,/g, ' ')
|
|
|
}]
|
|
|
}));
|
|
|
|
|
|
$the.remove();
|
...
|
...
|
@@ -180,7 +184,8 @@ function addressDialogFactory(opt, $the) { |
|
|
address: detail,
|
|
|
mobile: mobile,
|
|
|
phone: phone,
|
|
|
'area_code': '320107'// eslint-disable-line
|
|
|
'is_default': isDefault, // eslint-disable-line
|
|
|
'area_code': areaCode// eslint-disable-line
|
|
|
}
|
|
|
}).then(function(data) {
|
|
|
var the;
|
...
|
...
|
@@ -215,20 +220,34 @@ function addressDialogFactory(opt, $the) { |
|
|
return address;
|
|
|
}
|
|
|
|
|
|
// 初始化弹窗内容
|
|
|
function initAddressContent($el) {
|
|
|
/**
|
|
|
* 初始化弹窗内容
|
|
|
* @param $el dialog的jquery对象
|
|
|
* @param areaCode 区码,初始化选择区域的组件
|
|
|
*/
|
|
|
function initAddressContent($el, areaCode) {
|
|
|
|
|
|
// 初始化地址组件
|
|
|
cascadingAddress({
|
|
|
// 初始化地址组件/将组件attr到$el方便操作
|
|
|
$el.address = cascadingAddress({
|
|
|
el: '#address',
|
|
|
url: 'http://localhost:3000/areas/0',
|
|
|
resource: 'areas'
|
|
|
});
|
|
|
|
|
|
if (areaCode) {
|
|
|
$el.address.setAddress({
|
|
|
province: '32',
|
|
|
city: '3201',
|
|
|
dist: areaCode
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// init default
|
|
|
$el.default = $el.find('.default-address-radio .iconfont').hasClass('checked');
|
|
|
$el.find('.default-address-radio').check({
|
|
|
type: 'radio',
|
|
|
onChange: function(el, checked) {
|
|
|
console.log(checked);
|
|
|
$el.default = checked;
|
|
|
}
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -243,7 +262,7 @@ function newAddress() { |
|
|
|
|
|
// 显示全部地址
|
|
|
$('.address-all').click(function() {
|
|
|
$(this).siblings('.address-list').removeClass('shrink').end().remove();
|
|
|
$(this).siblings('.address-list').removeClass('shrink').end().addClass('vhide');
|
|
|
});
|
|
|
|
|
|
// 新增地址
|
...
|
...
|
@@ -265,6 +284,7 @@ $('.address-list').on('click', '.address', function() { |
|
|
|
|
|
// 修改地址
|
|
|
var $this = $(this).closest('.address');
|
|
|
var areaCode = $this.data('areacode');
|
|
|
var address = addressDialogFactory({
|
|
|
updateAddress: true,
|
|
|
id: $this.data('id'),
|
...
|
...
|
@@ -272,11 +292,11 @@ $('.address-list').on('click', '.address', function() { |
|
|
name: $this.data('name'),
|
|
|
mobile: $this.data('mobile'),
|
|
|
phone: $this.data('phone'),
|
|
|
areacode: $this.data('areacode'),
|
|
|
areacode: areaCode,
|
|
|
detail: $this.data('address')
|
|
|
}, $this);
|
|
|
|
|
|
initAddressContent(address.$el);
|
|
|
initAddressContent(address.$el, areaCode);
|
|
|
|
|
|
address.show();
|
|
|
|
...
|
...
|
@@ -348,7 +368,7 @@ $.ajax({ |
|
|
list = data.data;
|
|
|
if (list.length === 0) {
|
|
|
|
|
|
//new address
|
|
|
// new address
|
|
|
newAddress();
|
|
|
} else {
|
|
|
$('#address-list').append(addressTpl({
|
...
|
...
|
|