From aaf2087a984fb05ce2211727cad246296f0c581a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E5=AD=A6=E6=96=87?= Date: Sun, 24 Nov 2019 23:26:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E5=B0=8F=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 2 +- app.json | 2 +- config/config.js | 2 +- pages/enterCommunity/enterCommunity.js | 159 ++++++++++++++++++++--- pages/enterCommunity/enterCommunity.wxml | 46 ++++--- 5 files changed, 173 insertions(+), 38 deletions(-) diff --git a/app.js b/app.js index 93bc197..ef3eb53 100644 --- a/app.js +++ b/app.js @@ -41,7 +41,7 @@ App({ success: function (res, data){ console.log(data); wx.setStorageSync('location', data.pois[0].title); - wx.setStorageSync('currentLocation', data.reverseGeocoderResult.address_component); + wx.setStorageSync('currentLocation', data.reverseGeocoderSimplify); } }); diff --git a/app.json b/app.json index 9f3cfba..c098536 100644 --- a/app.json +++ b/app.json @@ -42,7 +42,7 @@ ] }, "networkTimeout": { - "request": 3000 + "request": 10000 }, "permission": { "scope.userLocation": { diff --git a/config/config.js b/config/config.js index c82bda7..6dc97fa 100644 --- a/config/config.js +++ b/config/config.js @@ -18,7 +18,7 @@ const appInfo = { }; const urlInfo = { - areaUrl: baseUrl +"appApi/app.listAreas" + areaUrl: baseUrl +"appApi/area.listAreas" } diff --git a/pages/enterCommunity/enterCommunity.js b/pages/enterCommunity/enterCommunity.js index 0692cb0..049ac00 100644 --- a/pages/enterCommunity/enterCommunity.js +++ b/pages/enterCommunity/enterCommunity.js @@ -10,8 +10,18 @@ Page({ data: { province:'', city:'', + multiArray: [], + multiIndex: [0, 0, 0], provinces:[], - citys:[] + areas:[], + currentArea:{}, + + communityName:'', + ownerName:'', + idCard:'', + tel:'', + validateCode:'' + }, /** @@ -19,10 +29,10 @@ Page({ */ onLoad: function (options) { //查询省级地区 - let pros = this._loadArea('101','0'); - this.setData({ - provinces: pros.areas, - }) + let pros = this._loadArea('',''); + + + }, /** @@ -40,10 +50,13 @@ Page({ this.setData({ province: curLocation.province, city: curLocation.city, - communityName:'', - idCard:'', - tel:'', - validateCode:'', + + communityName: '', + ownerName: '', + idCard: '', + tel: '', + validateCode: '' + }) }, @@ -80,8 +93,17 @@ Page({ */ onShareAppMessage: function () { + }, + + bindRegionChange: function (e) { + console.log('picker发送选择改变,携带值为', e.detail.value) + // this.setData({ + // region: e.detail.value + // }) + }, _loadArea:function(_level,_parentAreaCode){ + let that = this; wx.request({ url: urlInfo.areaUrl, header: util.getHeaders(), @@ -89,26 +111,125 @@ Page({ areaLevel: _level, // 临时登录凭证 parentAreaCode: _parentAreaCode }, - success: function (res) { console.log('login success'); res = res.data; + var province = [], city = [], area = []; + var _currentArea = []; + province = res.areas.filter(item => { + return item.parentAreaCode == 0; + }) + city = res.areas.filter(item => { + return item.parentAreaCode == province[0].areaCode; + }) + area = res.areas.filter(item => { + return item.parentAreaCode == city[0].areaCode; + }) + var provinceList = province.map(item => { + return item.areaName; + }) + var cityList = city.map(item => { + return item.areaName; + }) + var quyuList = area.map(item => { + return item.areaName; + }); + let curLocation = wx.getStorageSync("currentLocation"); + _currentArea = res.areas.filter(item => { + return item.areaCode == curLocation.adcode; + }) + that.setData({ + multiArray: [provinceList, cityList, quyuList], + areas: res.areas, + currentArea: _currentArea[0], + province + }); + - if (res.result == 0) { - that.globalData.userInfo = res.userInfo; - wx.setStorageSync('userInfo', JSON.stringify(res.userInfo)); - wx.setStorageSync('loginFlag', res.sessionKey); - callback(); - } else { - that.showInfo(res.errmsg); - } }, fail: function (error) { // 调用服务端登录接口失败 - that.showInfo('调用接口失败'); + wx.showToast({ + title: '调用接口失败', + }); console.log(error); } }) + }, + bindMultiPickerChange: function (e) { + console.log('picker发送选择改变,携带值为', e.detail.value) + this.setData({ + multiIndex: e.detail.value + }) + }, + bindMultiPickerColumnChange: function (e) { + console.log('修改的列为', e.detail.column, ',值为', e.detail.value,this.data); + var data = { + multiArray: this.data.multiArray, + multiIndex: this.data.multiIndex + }; + data.multiIndex[e.detail.column] = e.detail.value; + const provinceName = data.multiArray[0][data.multiIndex[0]]; + let provinceId = ""; + let province = this.data.province; + let quyuList = [], cityList = [], provinceList = [], city = [], area = []; + try { + province.forEach(item => { + if (item.areaName === provinceName) { + provinceId = item.areaCode; + throw (new Error('find item')) + } + }) + } catch (err) { + } + city = this.data.areas.filter(item => { + return item.parentAreaCode == provinceId; + }) + if (e.detail.column == 0) { + data.multiIndex = [e.detail.value, 0, 0]; + try { + area = this.data.areas.filter(item => { + return item.parentAreaCode == city[data.multiIndex[1]].areaCode; + }) + } catch (err) { } + } else if (e.detail.column == 1) { + data.multiIndex[2] = 0; + area = this.data.areas.filter(item => { + return item.parentAreaCode == city[e.detail.value].areaCode; + }) + } else { + const cityName = data.multiArray[1][data.multiIndex[1]]; + let cityId = ''; + try { + this.data.areas.forEach(item => { + if (item.areaName === cityName) { + cityId = item.areaCode; + throw (new Error('find item')); + } + }) + } catch (err) { } + area = this.data.areas.filter(item => { + return item.parentAreaCode == cityId; + //return item.parentAreaCode == city[e.detail.value].areaCode; + + }) + } + provinceList = province.map(item => { + return item.areaName + }) + cityList = city.map(item => { + return item.areaName; + }) + quyuList = area.map(item => { + return item.areaName; + }); + data.currentArea = area[data.multiIndex[2]]; + data.multiArray = [provinceList, cityList, quyuList], + this.setData(data); + }, + enterCommunity:function(e){ + this.data.areaCode = this.data.currentArea.areaCode; + console.log("提交数据",this.data); } }) \ No newline at end of file diff --git a/pages/enterCommunity/enterCommunity.wxml b/pages/enterCommunity/enterCommunity.wxml index a312ff9..4844839 100644 --- a/pages/enterCommunity/enterCommunity.wxml +++ b/pages/enterCommunity/enterCommunity.wxml @@ -2,48 +2,62 @@ - - - - - + + + + - - - - - + + + + {{currentArea.parentAreaName}}{{currentArea.areaName}} + + - + - + + + + + + + + + - + - + - + - + \ No newline at end of file