...
|
...
|
@@ -28,7 +28,7 @@ var html = $tpl.html(); |
|
|
var active;
|
|
|
var dialogMessage = '<p class="message-title"><i class="order-icon {{messageIcon}}"></i>{{messageTitle}}</p><p class="message-summary">{{messageSummary}}</p>';
|
|
|
var $dialogEdit = $('#edit-dialog-tpl');
|
|
|
var $addressManage, $province, $city, $county, $selectList, $name, $phone, $address, $telCode, $tel, isProvinceChecked = false;
|
|
|
var $addressManage, $province, $city, $county, $street, $selectList, $name, $phone, $address, $telCode, $tel, isProvinceChecked = false;
|
|
|
|
|
|
function cancelFactory(id) {
|
|
|
var options = {
|
...
|
...
|
@@ -260,6 +260,7 @@ function newAddress(id) { |
|
|
$province = $addressManage.find('select[name="province"]');
|
|
|
$city = $addressManage.find('select[name="city"]');
|
|
|
$county = $addressManage.find('select[name="county"]');
|
|
|
$street = $addressManage.find('select[name="street"]');
|
|
|
$selectList = $addressManage.find('select[name="province"],select[name="city"]');
|
|
|
$name = $addressManage.find('.inp[name="name"]');
|
|
|
$phone = $addressManage.find('.inp[name="phone"]');
|
...
|
...
|
@@ -298,26 +299,35 @@ function newAddress(id) { |
|
|
getAddress({
|
|
|
id: cityId,
|
|
|
type: 'getCounty',
|
|
|
selectId: code
|
|
|
selectId: '' + codeId[0] + codeId[1] + codeId[2]
|
|
|
}, function() {
|
|
|
var countyId = $county.val();
|
|
|
|
|
|
//如果获取的县有默认选中项则获取乡镇/街道
|
|
|
if (countyId !== '0') {
|
|
|
getAddress({
|
|
|
id: countyId,
|
|
|
type: 'getStreet',
|
|
|
selectId: code
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
$addressManage.find('select[name="city"]').html('<option value="0">请选择城市</option>');
|
|
|
$addressManage.find('select[name="county"]').html('<option value="0">请选择区县</option>');
|
|
|
$street.html('<option value="0">请选择乡镇/街道</option>');
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 发生change事件时获取下一级地址
|
|
|
$selectList.change(function() {
|
|
|
|
|
|
var $this = $(this);
|
|
|
|
|
|
if ($this.attr('name') === 'province') {
|
|
|
|
|
|
if ($this.val() === '0') {
|
|
|
$addressManage.find('select[name="city"]').html('<option value="0">请选择城市</option>');
|
|
|
$addressManage.find('select[name="county"]').html('<option value="0">请选择区县</option>');
|
|
|
} else {
|
|
|
getAddress({
|
|
|
id: $this.val(),
|
...
|
...
|
@@ -325,12 +335,12 @@ function newAddress(id) { |
|
|
}, function() {
|
|
|
isProvinceChecked = true;
|
|
|
});
|
|
|
$addressManage.find('select[name="county"]').html('<option value="0">请选择区县</option>');
|
|
|
}
|
|
|
$addressManage.find('select[name="county"]').html('<option value="0">请选择区县</option>');
|
|
|
$street.html('<option value="0">请选择乡镇/街道</option>');
|
|
|
}
|
|
|
|
|
|
if ($this.attr('name') === 'city' && isProvinceChecked) {
|
|
|
|
|
|
if ($this.val() === '0') {
|
|
|
$addressManage.find('select[name="county"]').html('<option value="0">请选择区县</option>');
|
|
|
} else {
|
...
|
...
|
@@ -339,8 +349,21 @@ function newAddress(id) { |
|
|
type: 'getCounty'
|
|
|
});
|
|
|
}
|
|
|
$street.html('<option value="0">请选择乡镇/街道</option>');
|
|
|
}
|
|
|
|
|
|
if ($this.attr('name') === 'county' && isProvinceChecked) {
|
|
|
if ($this.val() === '0') {
|
|
|
$street.html('<option value="0">请选择乡镇/街道</option>');
|
|
|
} else {
|
|
|
getAddress({
|
|
|
id: $this.val(),
|
|
|
type: 'getStreet'
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
$name.on('blur', function() {
|
|
|
validate.name($.trim($name.val()));
|
|
|
});
|
...
|
...
|
@@ -352,9 +375,9 @@ function newAddress(id) { |
|
|
});
|
|
|
$tel.on('blur', function() {
|
|
|
validate.tel($.trim($telCode.val()), $.trim($tel.val()));
|
|
|
})
|
|
|
$county.on('change', function() {
|
|
|
validate.city($province.val(), $city.val(),$county.val());
|
|
|
});
|
|
|
$street.on('change', function() {
|
|
|
validate.city($province.val(), $city.val(), $county.val(), $(this).val());
|
|
|
})
|
|
|
}
|
|
|
/**
|
...
|
...
|
@@ -380,6 +403,8 @@ function getAddress(d, callback) { |
|
|
|
|
|
//url = 'getCounty';
|
|
|
$obj = $county;
|
|
|
} else if (d.type === 'getStreet') {
|
|
|
$obj = $street;
|
|
|
}
|
|
|
|
|
|
$.ajax({
|
...
|
...
|
@@ -402,11 +427,11 @@ function getAddress(d, callback) { |
|
|
|
|
|
// 构建select下拉选项
|
|
|
function structureOption($obj, data, selectId) {
|
|
|
|
|
|
var i,
|
|
|
optionHtml = '',
|
|
|
defaultOption,
|
|
|
isStar = '';
|
|
|
var countyId;
|
|
|
|
|
|
for (i = 0; i < data.length; i++) {
|
|
|
|
...
|
...
|
@@ -431,6 +456,15 @@ function structureOption($obj, data, selectId) { |
|
|
|
|
|
} else if ($obj.attr('name') === 'county') {
|
|
|
defaultOption = '<option value="0">请选择区县</option>';
|
|
|
} else if ($obj.attr('name') === 'street') {
|
|
|
selectId += '';
|
|
|
countyId = selectId.substr(0, 6);
|
|
|
|
|
|
defaultOption = '<option value="0">请选择乡镇/街道</option>';
|
|
|
|
|
|
if (countyId) {
|
|
|
defaultOption += '<option value="' + countyId + '">全部</option>';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
$obj.html(defaultOption + optionHtml);
|
...
|
...
|
@@ -442,6 +476,7 @@ function saveAddress(id) { |
|
|
province = $province.val(),
|
|
|
city = $city.val(),
|
|
|
county = $county.val(),
|
|
|
street = $street.val(),
|
|
|
address = $address.val(),
|
|
|
phone = $phone.val(),
|
|
|
telCode = $telCode.val(),
|
...
|
...
|
@@ -456,14 +491,14 @@ function saveAddress(id) { |
|
|
var postData = {
|
|
|
orderCode: id,
|
|
|
userName: name,
|
|
|
areaCode: county,
|
|
|
areaCode: street,
|
|
|
address: address,
|
|
|
mobile: phone,
|
|
|
phoneCode: telCode,
|
|
|
phoneNum: tel
|
|
|
};
|
|
|
var validate = validateForm();
|
|
|
if (!validate.name(name) || !validate.city(province, city, county) || !validate.address(address) || !validate.mobile(phone) || !validate.tel(telCode, tel)) {
|
|
|
if (!validate.name(name) || !validate.city(province, city, county, street) || !validate.address(address) || !validate.mobile(phone) || !validate.tel(telCode, tel)) {
|
|
|
return;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -510,8 +545,8 @@ function validateForm() { |
|
|
return true;
|
|
|
}
|
|
|
},
|
|
|
city: function(province, city, county) {
|
|
|
if (province === '0' || city === '0' || county === '0') {
|
|
|
city: function(province, city, county, street) {
|
|
|
if (province === '0' || city === '0' || county === '0' || street === '0') {
|
|
|
$err_province.html(_error_html);
|
|
|
$err_province.find('b').html('请填写完整的省市区信息');
|
|
|
$err_province.show();
|
...
|
...
|
|