アプレット省市区三級連動
3775 ワード
プロジェクトは省市地区の三級連動が必要で、最終的に区県に戻る必要があるコードデータはバックグラウンド要求である.
wxml
wxml
:
{{proviceName}}
{{cityName}}
{{districtName}}
js[
{
CityName:" ",
CodeId:110101,
ParentId:1101,
Sort:0
},
{
CityName:" ",
CodeId:110101,
ParentId:1101,
Sort:0
},
]
const httpHelper = require('../../libs/httpRequertHelper.js')// ajax
Page({
/**
*
*/
data: {
provice: [],//
city: [],
district:[],
proviceName: ' ',
cityName: ' ',
districtName:' ',
proviceList :[],// code
cityList :[],
districtList:[],
index:0,//
Pcode:0,// code code
},
checkboxChange:function(){
},
onLoad: function (options) {
//
var that = this;
var arr = [];
var http = new httpHelper.HttpRequert({
data: {
parentCode: 0
},
success: returnData => {
if (returnData.data.status == 200) {
var datas = JSON.parse(returnData.data.list);
for (var i = 0; i < datas.length; i++) {
arr.push(datas[i].CityName)
}
that.setData({
provice: arr,
proviceList:datas
})
}
}
});
http.send('/Common/FindCityList');
},
bindPickerChange: function (e) { //
console.log('picker , ', e.detail.value)
this.setData({
index: e.detail.value,
proviceName: this.data.provice[e.detail.value],
Pcode: this.data.proviceList[e.detail.value].CodeId
})
this.getCity(1);
},
bindCityChange: function (e) {//
console.log('picker , ', e.detail.value)
this.setData({
index: e.detail.value,
cityName: this.data.city[e.detail.value],
Pcode: this.data.cityList[e.detail.value].CodeId
})
this.getCity(2);
},
bindDistrictChange: function (e) {//
console.log('picker , ', e.detail.value)
this.setData({
index: e.detail.value,
districtName: this.data.district[e.detail.value],
Pcode: this.data.districtList[e.detail.value].CodeId,
})
},
getCity:function(types){
var that=this;
var arr=[];
var http = new httpHelper.HttpRequert({
data: {
parentCode:this.data.Pcode
},
success: returnData => {
if (returnData.data.status == 200) {
var datas=JSON.parse(returnData.data.list)
console.log(datas)
for (var i = 0; i < datas.length;i++){
arr.push(datas[i].CityName)
}
if(types==1){
that.setData({
city: arr,
cityList:datas
})
} else if (types == 2) {
that.setData({
district: arr,
districtList:datas
})
}
}
}
});
http.send('/Common/FindCityList');
},
onShow:function(){
},
})