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) }) } } })
|