|
|
|
@ -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() |
|
|
|
|