行政区划代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

<div class="input-group f-mt10">
<select class="form-control v-cloak" v-model="provinceSelect" @change="provinceChange()">
<option class="v-cloak" v-for="option in provinceOptions" v-bind:value="option.value">
{{ option.text }}
</option>
</select>
<select class="form-control v-cloak f-mt5" v-model="citySelect" @change="cityChange()">
<option class="v-cloak" v-for="option in cityOptions" v-bind:value="option.value">
{{ option.text }}
</option>
</select>
<select class="form-control v-cloak f-mt5" v-model="countySelect">
<option class="v-cloak" v-for="option in countyOptions" v-bind:value="option.value">
{{ option.text }}
</option>
</select>
</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109

new Vue({
el: '#update',
data: {
provinceSelect: '',
provinceOptions: [
{
text: '选择省',
value: ''
}
],
citySelect: '',
cityOptions: [
{
text: '选择市',
value: ''
}
],
countySelect: '',
countyOptions: [
{
text: '选择区',
value: ''
}
]
},
methods:{
provinceChange(){
detailSchool.xzqhdm(detailSchool.provinceSelect).then(function(data){
detailSchool.provinceSelect = data.provinceSelect;
detailSchool.provinceOptions = data.provinceOptions;
detailSchool.citySelect = data.citySelect;
detailSchool.cityOptions = data.cityOptions;
detailSchool.countySelect = data.countySelect;
detailSchool.countyOptions = data.countyOptions;
})
},
cityChange(){
detailSchool.xzqhdm(detailSchool.provinceSelect,detailSchool.citySelect).then(function(data){
detailSchool.provinceSelect = data.provinceSelect;
detailSchool.provinceOptions = data.provinceOptions;
detailSchool.citySelect = data.citySelect;
detailSchool.cityOptions = data.cityOptions;
detailSchool.countySelect = data.countySelect;
detailSchool.countyOptions = data.countyOptions;
})
}
xzqhdm(province,city,county){
return new Promise(function(resolve,reject){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
var data = JSON.parse(xmlhttp.responseText);
console.log(data)
var countySelect = '86';
var provinceCodeArr = Object.keys(data[countySelect]);
var provinceNameArr = Object.values(data[countySelect]);
var provinceOptions = provinceCodeArr.map(function(item,index){
return {
text:provinceNameArr[index],
value:item
}
})
var provinceSelect = province provinceCodeArr[0];
var provinceName = data[countySelect][provinceSelect];
var cityCodeArr = Object.keys(data[provinceSelect]);
var cityNameArr = Object.values(data[provinceSelect]);
var cityOptions = cityCodeArr.map(function(item,index){
return {
text:cityNameArr[index],
value:item
}
})
var citySelect = (province && city)?city:cityCodeArr[0];
var cityName = data[provinceSelect][citySelect];
var countyCodeArr = Object.keys(data[citySelect]);
var countyNameArr = Object.values(data[citySelect]);
var countyOptions = countyCodeArr.map(function(item,index){
return {
text:countyNameArr[index],
value:item
}
})
var countySelect = (province && city && county)?county:countyCodeArr[0];
var countyName = data[citySelect][countySelect];
resolve({
provinceSelect:provinceSelect,
provinceName:provinceName,
provinceOptions:provinceOptions,
citySelect:citySelect,
cityName:cityName,
cityOptions:cityOptions,
countySelect:countySelect,
countyName:countyName,
countyOptions:countyOptions
})
}
}
xmlhttp.onerror = function(){
reject();
}
xmlhttp.open('GET','//public.yitong.com/javascripts/xzqhdm.json',true);
xmlhttp.send();
}).catch(function(err){
console.log(err)
});
}
}
})
1
2
3
4
5
6
7

this.xzqhdm().then(function(data){
console.log(data)
})
this.xzqhdm("420000","420100","420112").then(function(data){
console.log(data)
})

行政区划代码
http://example.com/2018-06-08 行政区划代码-2/
作者
csorz
发布于
2018年6月8日
许可协议