city.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // pages/Components/city/city.js
  2. const city = require('../../../utils/city')
  3. const app = getApp()
  4. Component({
  5. attached: function() {
  6. // 在组件实例进入页面节点树时执行
  7. this.setData({
  8. hot: city.hotCity.hot,
  9. cityList:city.citys,
  10. city:wx.getStorageSync('wxLocalName').city
  11. })
  12. },
  13. /**
  14. * 组件的属性列表
  15. */
  16. properties: {
  17. },
  18. /**
  19. * 组件的初始数据
  20. */
  21. data: {
  22. src:"https://app.schoolwisdoms.com/static/wx/images/",
  23. hot:[],
  24. cityList:[],
  25. cityArr:["TOP","A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","W","X","Y","Z"],
  26. tipHide: 1,
  27. showTimeOut:null,
  28. tipText:"",
  29. city:''
  30. },
  31. /**
  32. * 组件的方法列表
  33. */
  34. methods: {
  35. changeTitle:function(e){
  36. var idName = e.target.dataset.id
  37. clearTimeout(this.data.showTimeOut)
  38. this.setData({
  39. tipHide: 0,
  40. tipText: idName
  41. })
  42. this.data.showTimeOut = setTimeout(() => {
  43. this.setData({
  44. tipHide: 1,
  45. })
  46. }, 800);
  47. if(idName != "TOP"){
  48. var me = this;
  49. var query = wx.createSelectorQuery().in(me);
  50. query.selectViewport().scrollOffset()
  51. query.select("#"+idName).boundingClientRect();
  52. query.exec(function (res) {
  53. var miss = res[0].scrollTop + res[1].top - 93;
  54. wx.pageScrollTo({
  55. scrollTop: miss,
  56. duration: 0
  57. });
  58. });
  59. } else{
  60. wx.pageScrollTo({
  61. scrollTop: 0,
  62. duration: 0
  63. });
  64. }
  65. },
  66. getCity:function(e){
  67. var json = wx.getStorageSync('wxLocalName')
  68. json.city = e.currentTarget.dataset.name + "市"
  69. wx.setStorageSync('wxLocalName', json)
  70. wx.navigateBack({
  71. delta: 0,
  72. })
  73. }
  74. },
  75. })