// pages/home/location/location.js var city = require('../../../libs/city.js'); const app = getApp(); Page({ /** * 页面的初始数据 */ data: { city: app.globalData.city, cityData: {},//所有城市 hotCityData: [],//热门城市 _py: ["hot", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z"],//字母索引 hidden: true, showPy: '★', }, //选择城市 selectCity: function (e) { app.globalData.city = e.currentTarget.dataset.name; wx.reLaunch({ url: '/pages/home/index?city=' + e.currentTarget.dataset.name, }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { var that = this; that.setData({ cityData: city.all, hotCityData: city.hot }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.setData({ city: app.globalData.city }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, //获取文字信息 getPy: function (e) { this.setData({ hidden: false, showPy: e.target.id, }) }, setPy: function (e) { this.setData({ hidden: true, scrollTopId:e.target.id // scrollTopId: this.data.showPy }) }, //触发全部开始选择 tStart: function () { this.setData({ hidden: false }) }, //滑动选择城市 tMove: function (e) { var y = e.touches[0].clientY;//触摸点Y坐标 var offsettop = e.currentTarget.offsetTop;//节点Y坐标 //判断选择区域,只有在选择区才会生效 if (y > offsettop && y < offsettop+276) { var num = parseInt((y - offsettop) / 12); this.setData({ showPy: this.data._py[num] }) }; }, //触发结束选择 tEnd: function () { this.setData({ hidden: true, scrollTopId: this.data.showPy }) }, })