|
@@ -26,6 +26,9 @@ Page({
|
|
|
data: {
|
|
|
checked: true,
|
|
|
areas: [],
|
|
|
+ tree: [],
|
|
|
+ cityIndex: 0,
|
|
|
+ districtIndex: 0,
|
|
|
region: [],
|
|
|
years: years,
|
|
|
year: date.getFullYear(),
|
|
@@ -33,14 +36,17 @@ Page({
|
|
|
month: 2,
|
|
|
days: days,
|
|
|
day: 2,
|
|
|
- value: [9999, 1, 1]
|
|
|
+ value: [0, 0, 0],
|
|
|
+ oldval: [0, 0, 0],
|
|
|
+ citys: [],
|
|
|
+ districts: []
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
-
|
|
|
+ this.getDatas()
|
|
|
},
|
|
|
toggleChecked() {
|
|
|
this.setData({
|
|
@@ -54,14 +60,84 @@ Page({
|
|
|
})
|
|
|
},
|
|
|
bindChange: function (e) {
|
|
|
+ console.log(e)
|
|
|
const val = e.detail.value
|
|
|
+
|
|
|
+
|
|
|
+ // if (districtIndex != this.data.oldval[1] && cityIndex != 0) {
|
|
|
+ // districtIndex = 0
|
|
|
+ // }
|
|
|
+ if (this.data.oldval[0] != val[0]) {
|
|
|
+ val[1] = 0
|
|
|
+ val[2] = 0
|
|
|
+ } else { //若省份column未做滑动,地级市做了滑动则定位区县第一位
|
|
|
+ if (this.data.oldval[1] != val[1]) {
|
|
|
+ val[2] = 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let cityIndex = val[0]
|
|
|
+ let districtIndex = val[1]
|
|
|
this.setData({
|
|
|
- year: this.data.years[val[0]],
|
|
|
- month: this.data.months[val[1]],
|
|
|
- day: this.data.days[val[2]]
|
|
|
+ oldval: val,
|
|
|
+ citys: this.data.tree[val[0]].children,
|
|
|
+ districts: this.data.tree[val[0]].children[val[1]].children
|
|
|
+ })
|
|
|
+ // this.setData({
|
|
|
+ // oldval: val,
|
|
|
+ // citys: this.data.tree[val[0]],
|
|
|
+ // districts: this.data.tree[val[0].children[val[1]]
|
|
|
+ // })
|
|
|
+ },
|
|
|
+ getDatas() {
|
|
|
+ wx.showLoading({
|
|
|
+ title: '加载中',
|
|
|
+ })
|
|
|
+ var self = this
|
|
|
+ getReq({
|
|
|
+ act: 'app_update',
|
|
|
+ op: 'area',
|
|
|
+ curpage: 1
|
|
|
+ }, function (res) {
|
|
|
+ wx.hideLoading()
|
|
|
+ if (res.code == 200) {
|
|
|
+ console.log(res.datas.areas)
|
|
|
+ let tree = self.arrayToTree(res.datas.areas)
|
|
|
+ console.log(tree)
|
|
|
+ self.setData({
|
|
|
+ areas: res.datas.areas,
|
|
|
+ tree
|
|
|
+ })
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ wx.showToast({
|
|
|
+ icon: 'none',
|
|
|
+ title: res.message,
|
|
|
+ duration: 2000
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ arrayToTree(array) {
|
|
|
+ let result = [], hash = {}, children = 'children'
|
|
|
+ array.forEach((item, index) => {
|
|
|
+ hash[item.aid] = item
|
|
|
+ })
|
|
|
+
|
|
|
+ array.forEach((item, index) => {
|
|
|
+ let pid = item.pid
|
|
|
+ if (pid == 0) {
|
|
|
+ result.push(item)
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ let hashvp = hash[item.pid]
|
|
|
+ if (!hashvp[children]) {
|
|
|
+ hashvp[children] = []
|
|
|
+ }
|
|
|
+ hashvp[children].push(item)
|
|
|
+ }
|
|
|
})
|
|
|
+ return result
|
|
|
},
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面初次渲染完成
|