|
@@ -9,7 +9,11 @@
|
|
|
countryNode : ele.find(".init_country"),
|
|
|
provinceId : 0,
|
|
|
cityId : 0,
|
|
|
- countryId :0
|
|
|
+ countryId :0,
|
|
|
+ provinceName : "",
|
|
|
+ cityName : "",
|
|
|
+ countryName : "",
|
|
|
+ initLock : false
|
|
|
},
|
|
|
this.options = $.extend({}, this.addressInfo, opt) //opt并入addressInfo集合组成新的集合,然后赋值给 options ,所以一切调用options
|
|
|
}
|
|
@@ -28,13 +32,14 @@
|
|
|
$(result.returnMsg.provinceList).each(function (){
|
|
|
$provinceNode.append("<option value='"+ this.provinceId +"'>"+ this.province +"</option>");
|
|
|
})
|
|
|
-
|
|
|
- if(isEmpty($provinceNode.attr("defValue"))){
|
|
|
- address.options.provinceId = $provinceNode.attr("defValue");
|
|
|
- }else if(!isEmpty(address.options.provinceId)){
|
|
|
- address.options.provinceId = result.returnMsg.provinceList[0].provinceId;
|
|
|
+ if(isEmpty($provinceNode.attr("provinceId"))){
|
|
|
+ address.options.provinceId = $provinceNode.attr("provinceId");
|
|
|
+ }else if(isEmpty(address.options.provinceName)){
|
|
|
+ address.options.provinceId = address.getAttrIdByName($provinceNode,address.options.provinceName);
|
|
|
+ }else if(isEmpty($provinceNode.attr("provinceName"))) {
|
|
|
+ address.options.provinceId = address.getAttrIdByName($provinceNode,$provinceNode.attr("provinceName"));
|
|
|
}else{
|
|
|
- address.options.provinceId = $provinceNode.val();
|
|
|
+ address.options.provinceId = result.returnMsg.provinceList[0].provinceId;
|
|
|
}
|
|
|
address.setProvince();
|
|
|
}else{
|
|
@@ -53,12 +58,14 @@
|
|
|
$cityNode.append("<option value='"+ this.cityId +"'>"+ this.city +"</option>");
|
|
|
})
|
|
|
|
|
|
- if(isEmpty($cityNode.attr("defValue"))){
|
|
|
- address.options.cityId = $cityNode.attr("defValue");
|
|
|
- }else if(!isEmpty(address.options.cityId)){
|
|
|
- address.options.cityId = result.returnMsg.cityList[0].cityId;
|
|
|
+ if(isEmpty($cityNode.attr("cityId"))){
|
|
|
+ address.options.cityId = $cityNode.attr("cityId");
|
|
|
+ }else if(isEmpty(address.options.cityName)){
|
|
|
+ address.options.cityId = address.getAttrIdByName($cityNode,address.options.cityName);
|
|
|
+ }else if(isEmpty($cityNode.attr("cityName"))){
|
|
|
+ address.options.cityId = address.getAttrIdByName($cityNode,$cityNode.attr("cityName"));
|
|
|
}else{
|
|
|
- address.options.cityId = $cityNode.val();
|
|
|
+ address.options.cityId = result.returnMsg.cityList[0].cityId;
|
|
|
}
|
|
|
address.setCity();
|
|
|
}else{
|
|
@@ -77,14 +84,17 @@
|
|
|
$countryNode.append("<option value='"+ this.districtId +"'>"+ this.district +"</option>");
|
|
|
})
|
|
|
|
|
|
- if(isEmpty($countryNode.attr("defValue"))){
|
|
|
- address.options.countryId = $countryNode.attr("defValue");
|
|
|
- }else if(!isEmpty(address.options.countryId)){
|
|
|
- address.options.countryId = result.returnMsg.districtList[0].districtId;
|
|
|
+ if(isEmpty($countryNode.attr("$countryId"))){
|
|
|
+ address.options.countryId = $countryNode.attr("$countryId");
|
|
|
+ }else if(isEmpty(address.options.countryName)){
|
|
|
+ address.options.countryId = address.getAttrIdByName($countryNode,address.options.countryName);
|
|
|
+ }else if(isEmpty($countryNode.attr("$countryName"))){
|
|
|
+ address.options.countryId = address.getAttrIdByName($countryNode,$countryNode.attr("$countryName"));
|
|
|
}else{
|
|
|
- address.options.countryId = $countryNode.val();
|
|
|
+ address.options.countryId = result.returnMsg.districtList[0].districtId;
|
|
|
}
|
|
|
address.setCountry();
|
|
|
+ address.options.initLock = true;
|
|
|
}else{
|
|
|
console.log("区县查询失败");
|
|
|
}
|
|
@@ -128,6 +138,45 @@
|
|
|
this.setCountry();
|
|
|
return this;
|
|
|
},
|
|
|
+ setProvinceName:function(provinceName){
|
|
|
+ this.options.provinceName = provinceName;
|
|
|
+ this.initProvince(); //直接重新加载
|
|
|
+ return this;
|
|
|
+ },
|
|
|
+ setCityName:function(cityName){
|
|
|
+ this.options.cityName = cityName;
|
|
|
+ this.setProvince();
|
|
|
+ return this;
|
|
|
+ },
|
|
|
+ setCountryName:function(countryName){
|
|
|
+ this.options.countryName = countryName;
|
|
|
+ this.setCity();
|
|
|
+ return this;
|
|
|
+ },
|
|
|
+ getAttrIdByName:function($node,name){
|
|
|
+ name = $.trim(name);
|
|
|
+ var reArray = "省,市,县,乡,镇,市,自治区";
|
|
|
+ var array = reArray.split(",");
|
|
|
+ for (var i=0;i<array.length;i++){
|
|
|
+ name = name.replace(array[i],"");
|
|
|
+ }
|
|
|
+ var max = 0,maxValue="";
|
|
|
+ $node.find("option").each(function(){
|
|
|
+ var number=0,attrName = "";
|
|
|
+ if($(this).text().indexOf(name) > -1){
|
|
|
+ number ++
|
|
|
+ if($(this).text() == name){
|
|
|
+ number ++
|
|
|
+ }
|
|
|
+ attrName = $(this).val();
|
|
|
+ }
|
|
|
+ if(max < number){
|
|
|
+ max = number;
|
|
|
+ maxValue = attrName;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return maxValue;
|
|
|
+ },
|
|
|
cufte:function(val) {
|
|
|
if (undefined == val || null == val||typeof val == undefined || typeof val == 'undefined'|| 'undefined' == val) {
|
|
|
val = "";
|