|
|
@@ -16,11 +16,7 @@ Page({ |
|
|
|
cityCurrent: -1, |
|
|
|
districtCurrent: -1, |
|
|
|
params: {}, // 筛选条件 |
|
|
|
obj: { |
|
|
|
provinceName: '湖南省', |
|
|
|
cityName: '株洲市', |
|
|
|
districtName: '芦淞区' |
|
|
|
} |
|
|
|
obj: {} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
@@ -28,7 +24,7 @@ Page({ |
|
|
|
* 生命周期函数--监听页面加载 |
|
|
|
*/ |
|
|
|
onLoad: function (options) { |
|
|
|
this.getCityTreeList() |
|
|
|
// this.getCityTreeList() |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
@@ -38,22 +34,47 @@ Page({ |
|
|
|
// 隐藏返回图标 |
|
|
|
wx.hideHomeButton(); |
|
|
|
let positionParams = wx.getStorageSync('positionParams') |
|
|
|
if(Object.keys(positionParams).length) { |
|
|
|
let params = this.data.params |
|
|
|
params.provinceCode = positionParams.provinceCode |
|
|
|
params.cityCode = positionParams.cityCode |
|
|
|
params.districtCode = positionParams.districtCode |
|
|
|
this.setData({ |
|
|
|
params, |
|
|
|
provinceCurrent: positionParams.provinceCurrent, |
|
|
|
provinceOptions: positionParams.provinceOptions, |
|
|
|
cityCurrent: positionParams.cityCurrent, |
|
|
|
cityOptions: positionParams.cityOptions, |
|
|
|
districtCurrent: positionParams.districtCurrent, |
|
|
|
districtOptions: positionParams.districtOptions |
|
|
|
}) |
|
|
|
} else { |
|
|
|
this.getUserLocation() |
|
|
|
let options = this.data.provinceOptions |
|
|
|
if(options.length === 0) { |
|
|
|
let provinceOptions = wx.getStorageSync('provinceOptions') |
|
|
|
if(provinceOptions.length) { |
|
|
|
this.setData({provinceOptions}) |
|
|
|
if(Object.keys(positionParams).length) { |
|
|
|
let params = this.data.params |
|
|
|
params.provinceCode = positionParams.provinceCode |
|
|
|
params.cityCode = positionParams.cityCode |
|
|
|
params.districtCode = positionParams.districtCode |
|
|
|
this.setData({ |
|
|
|
params, |
|
|
|
provinceCurrent: positionParams.provinceCurrent, |
|
|
|
cityCurrent: positionParams.cityCurrent, |
|
|
|
cityOptions: positionParams.cityOptions, |
|
|
|
districtCurrent: positionParams.districtCurrent, |
|
|
|
districtOptions: positionParams.districtOptions |
|
|
|
}) |
|
|
|
} else { |
|
|
|
this.getUserLocation() |
|
|
|
} |
|
|
|
} else { |
|
|
|
this.getCityTreeList().then(res=> { |
|
|
|
if(Object.keys(positionParams).length) { |
|
|
|
let params = this.data.params |
|
|
|
params.provinceCode = positionParams.provinceCode |
|
|
|
params.cityCode = positionParams.cityCode |
|
|
|
params.districtCode = positionParams.districtCode |
|
|
|
this.setData({ |
|
|
|
params, |
|
|
|
provinceCurrent: positionParams.provinceCurrent, |
|
|
|
cityCurrent: positionParams.cityCurrent, |
|
|
|
cityOptions: positionParams.cityOptions, |
|
|
|
districtCurrent: positionParams.districtCurrent, |
|
|
|
districtOptions: positionParams.districtOptions |
|
|
|
}) |
|
|
|
} else { |
|
|
|
this.getUserLocation() |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
/** |
|
|
@@ -63,6 +84,9 @@ Page({ |
|
|
|
let provinceOptions = this.data.provinceOptions |
|
|
|
let provinceCurrent, cityCurrent, districtCurrent, cityOptions, districtOptions |
|
|
|
let params = this.data.params |
|
|
|
params.provinceCode = obj.provinceCode |
|
|
|
params.cityCode = obj.cityCode |
|
|
|
params.districtCode = obj.districtCode |
|
|
|
if(provinceOptions.length) { |
|
|
|
provinceOptions.forEach((item,index)=> { |
|
|
|
if(item.citycode === obj.provinceCode) { |
|
|
@@ -91,9 +115,16 @@ Page({ |
|
|
|
|
|
|
|
/* 获取省市区 */ |
|
|
|
getCityTreeList() { |
|
|
|
getCityTree().then(res=> { |
|
|
|
this.setData({ |
|
|
|
provinceOptions: res.data |
|
|
|
return new Promise((resolve)=> { |
|
|
|
getCityTree().then(res=> { |
|
|
|
wx.setStorage({ |
|
|
|
key: 'provinceOptions', |
|
|
|
data: res.data |
|
|
|
}) |
|
|
|
this.setData({ |
|
|
|
provinceOptions: res.data |
|
|
|
}) |
|
|
|
resolve(res) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}, |
|
|
@@ -143,10 +174,10 @@ Page({ |
|
|
|
key: 'location', |
|
|
|
data: res |
|
|
|
}) |
|
|
|
let latLog = {} |
|
|
|
latLog.lat = res.latitude |
|
|
|
latLog.lng = res.longitude |
|
|
|
getCityNameCode(latLog).then(res=> { |
|
|
|
let latlng = {} |
|
|
|
latlng.lat = res.latitude |
|
|
|
latlng.lng = res.longitude |
|
|
|
getCityNameCode(latlng).then(res=> { |
|
|
|
let cityObj = res.data |
|
|
|
this.setData({cityObj}) |
|
|
|
this.getListByName(cityObj) |
|
|
@@ -163,7 +194,6 @@ Page({ |
|
|
|
positionParams.provinceCurrent = this.data.provinceCurrent |
|
|
|
positionParams.cityCurrent = this.data.cityCurrent |
|
|
|
positionParams.districtCurrent = this.data.districtCurrent |
|
|
|
positionParams.provinceOptions = this.data.provinceOptions |
|
|
|
positionParams.cityOptions = this.data.cityOptions |
|
|
|
positionParams.districtOptions = this.data.districtOptions |
|
|
|
wx.setStorage({ |