diff --git a/app.js b/app.js index 930c922..18ad10f 100644 --- a/app.js +++ b/app.js @@ -7,6 +7,7 @@ App({ version: 152, xAppId: '470236309865238528', nowLocation: null, + nowCity: null, globalData: { userInfo: null, openId: null, diff --git a/pages/article/fragment/index.js b/pages/article/fragment/index.js index f25cba1..5f84c14 100644 --- a/pages/article/fragment/index.js +++ b/pages/article/fragment/index.js @@ -87,7 +87,7 @@ Component({ this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false }) this.fetchAgentList() } else if(message.what == 444){ - this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false, cityName: app.nowLocation.cityName }) + this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false, cityName: app.nowCity.cityName }) this.fetchAgentList() } }, diff --git a/pages/home/city-select/index.js b/pages/home/city-select/index.js index bd8b120..872f842 100644 --- a/pages/home/city-select/index.js +++ b/pages/home/city-select/index.js @@ -1,19 +1,20 @@ // pages/home/about/index.js const util = require('../../../utils/util') const event = require('../../../utils/event') +const storage = require('../../../utils/storage') const city = require("../../../utils/city.js") const app = getApp() +var hotList = [] Page({ - /** * 页面的初始数据 */ data: { value: '', height: app.globalData.fragmentHeight - 100, - localCity:'',//当前定位城市 - hotCity: ['北京', '上海', '广州', '深圳', '杭州', '长沙', '武汉', '厦门', '西安', '昆明', '成都', '重庆'], // 热门城市 + localCity: null,//当前定位城市 + hotCity: [], // 热门城市 lists:[],//城市列表 searchResult:[],//查找列表 titleHeight: 240, @@ -30,8 +31,16 @@ Page({ var height = app.globalData.fragmentHeight - 100 this.data.indexHeight = height - 48 var titleHeight = this.px2rpx(app.globalData.CustomBar) + 116 - var itemHeight = parseInt(this.data.indexHeight / 25) - this.setData({ height, itemHeight, indexHeight: this.data.indexHeight, titleHeight,lists: city.list }) + var itemHeight = parseInt(this.data.indexHeight / 24) + var localCity = null + if(app.nowLocation && !util.isEmpty(app.nowLocation.cityName)){ + localCity = app.nowLocation.cityName + } + var hotstring = storage.get('ztb-hot-list') + if(!util.isEmpty(hotstring)){ + hotList = JSON.parse(hotstring) + } + this.setData({ height, itemHeight, indexHeight: this.data.indexHeight, titleHeight, localCity, lists: city.list, hotCity: hotList }) }, getInputValue(e){ this.setData({ value:e.detail.value },()=>{ @@ -89,11 +98,22 @@ Page({ } else { item = this.data.searchResult[e.currentTarget.dataset.index] } - if(app.nowLocation) { - app.nowLocation.cityName = item.cityName.replace('市', '') - app.nowLocation.cityCode = item.code + if(app.nowCity) { + app.nowCity.cityName = item.cityName.replace('市', '') + app.nowCity.cityCode = item.code } else { - app.nowLocation = { cityName: item.cityName.replace('市', ''), cityCode: item.code } + app.nowCity = { cityName: item.cityName.replace('市', ''), cityCode: item.code } + } + var flag = false + for (let index = 0; index < hotList.length; index++) { + if(hotList[index].code == item.code){ + flag = true + break + } + } + if(!flag){ + hotList.push(item) + storage.put('ztb-hot-list', JSON.stringify(hotList)) } event.emit('EventMessage', { what: 444, desc: 'nowLocation' }) wx.navigateBack() diff --git a/pages/home/city-select/index.json b/pages/home/city-select/index.json index 7ce2263..378808f 100644 --- a/pages/home/city-select/index.json +++ b/pages/home/city-select/index.json @@ -1,5 +1,7 @@ { "usingComponents": { + "wux-grids": "/components/grids/index", + "wux-grid": "/components/grid/index", "free-input":"/components/free-input/index", "wux-cell": "/components/cell/index" } diff --git a/pages/home/city-select/index.wxml b/pages/home/city-select/index.wxml index 810b95a..70e0152 100644 --- a/pages/home/city-select/index.wxml +++ b/pages/home/city-select/index.wxml @@ -14,18 +14,18 @@ - - 定位城市 - - - {{localCity}} - + + 定位城市:{{localCity}} - - 热门城市 - - {{item}} + + 热门城市 + + + + {{item.cityName}} + + diff --git a/pages/home/city-select/index.wxss b/pages/home/city-select/index.wxss index 1a15d23..5d99ec0 100644 --- a/pages/home/city-select/index.wxss +++ b/pages/home/city-select/index.wxss @@ -30,40 +30,16 @@ } -.city-names { - display: flex; - flex-wrap: wrap; - justify-content: space-between; - align-content: space-between; - /* width: 630rpx; */ - padding: 12rpx 90rpx 26rpx 30rpx; -} .city-name-item { display: flex; justify-content: center; align-items: center; - width: 140rpx; + width: 150rpx; height: 56rpx; margin-top: 16rpx; /* border: solid 1rpx #ccc; */ - border-radius: 28rpx; - font-size: 28rpx; - color: #333; - position: relative; -} -.city-name-item::before { - content: ""; - position: absolute; - width: 200%; - height: 200%; - -webkit-transform-origin: 0 0; - transform-origin: 0 0; - -webkit-transform: scale(0.5, 0.5); - transform: scale(0.5, 0.5); - -webkit-box-sizing: border-box; - box-sizing: border-box; - left: 0; - top: 0; border-radius: 56rpx; border: 1px solid #ccc; + font-size: 28rpx; + color: #333; } \ No newline at end of file diff --git a/pages/index/index.js b/pages/index/index.js index 2e61d4b..70ccb11 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -91,6 +91,7 @@ Page({ success: function (res) { app.nowLocation.cityName = res.result.address_component.city.replace('市', '') app.nowLocation.cityCode = res.result.ad_info.city_code + app.nowCity = { cityName: app.nowLocation.cityName, cityCode: app.nowLocation.cityCode } that.setData({ cityName: app.nowLocation.cityName }) that.locate = true }, diff --git a/pages/moment/fragment/index.js b/pages/moment/fragment/index.js index aefa480..87c815a 100644 --- a/pages/moment/fragment/index.js +++ b/pages/moment/fragment/index.js @@ -63,7 +63,7 @@ Component({ this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false }) this.fetchAgentList() } else if(message.what == 444){ - this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false, cityName: app.nowLocation.cityName }) + this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false, cityName: app.nowCity.cityName }) this.fetchAgentList() } },