location.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // pages/home/location/location.js
  2. var city = require('../../../libs/city.js');
  3. const app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. city: app.globalData.city,
  10. cityData: {},//所有城市
  11. hotCityData: [],//热门城市
  12. _py: ["hot", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z"],//字母索引
  13. hidden: true,
  14. showPy: '★',
  15. },
  16. //选择城市
  17. selectCity: function (e) {
  18. app.globalData.city = e.currentTarget.dataset.name;
  19. wx.reLaunch({
  20. url: '/pages/home/index?city=' + e.currentTarget.dataset.name,
  21. })
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. var that = this;
  28. that.setData({
  29. cityData: city.all,
  30. hotCityData: city.hot
  31. });
  32. },
  33. /**
  34. * 生命周期函数--监听页面初次渲染完成
  35. */
  36. onReady: function () {
  37. },
  38. /**
  39. * 生命周期函数--监听页面显示
  40. */
  41. onShow: function () {
  42. this.setData({
  43. city: app.globalData.city
  44. })
  45. },
  46. /**
  47. * 生命周期函数--监听页面隐藏
  48. */
  49. onHide: function () {
  50. },
  51. /**
  52. * 生命周期函数--监听页面卸载
  53. */
  54. onUnload: function () {
  55. },
  56. /**
  57. * 页面相关事件处理函数--监听用户下拉动作
  58. */
  59. onPullDownRefresh: function () {
  60. },
  61. /**
  62. * 页面上拉触底事件的处理函数
  63. */
  64. onReachBottom: function () {
  65. },
  66. /**
  67. * 用户点击右上角分享
  68. */
  69. onShareAppMessage: function () {
  70. },
  71. //获取文字信息
  72. getPy: function (e) {
  73. this.setData({
  74. hidden: false,
  75. showPy: e.target.id,
  76. })
  77. },
  78. setPy: function (e) {
  79. this.setData({
  80. hidden: true,
  81. scrollTopId:e.target.id
  82. // scrollTopId: this.data.showPy
  83. })
  84. },
  85. //触发全部开始选择
  86. tStart: function () {
  87. this.setData({
  88. hidden: false
  89. })
  90. },
  91. //滑动选择城市
  92. tMove: function (e) {
  93. var y = e.touches[0].clientY;//触摸点Y坐标
  94. var offsettop = e.currentTarget.offsetTop;//节点Y坐标
  95. //判断选择区域,只有在选择区才会生效
  96. if (y > offsettop && y < offsettop+276) {
  97. var num = parseInt((y - offsettop) / 12);
  98. this.setData({
  99. showPy: this.data._py[num]
  100. })
  101. };
  102. },
  103. //触发结束选择
  104. tEnd: function () {
  105. this.setData({
  106. hidden: true,
  107. scrollTopId: this.data.showPy
  108. })
  109. },
  110. })