city.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. const app = getApp();
  2. const CHINA = require('../../utils/china_city');
  3. Page({
  4. data: {
  5. StatusBar: app.globalData.StatusBar,
  6. CustomBar: app.globalData.CustomBar,
  7. Custom: app.globalData.Custom,
  8. TabCur: 0,
  9. MainCur: 0,
  10. VerticalNavTop: 0,
  11. list: [],
  12. house_count:0,
  13. base:CHINA.cites,
  14. load: true
  15. },
  16. NavigetClick(res){
  17. var navigate = res.currentTarget.dataset.navigate;
  18. if(!navigate){
  19. return
  20. }
  21. wx.navigateTo({
  22. url: '/pages/web/web?navigate='+navigate
  23. })
  24. },
  25. GetAdvertiseDone(res){
  26. this.setData({
  27. advertises: res.data.data
  28. })
  29. },
  30. onLoad() {
  31. app.wxshowloading('加载中...');
  32. var params = {};
  33. var city = app.globalData.city;
  34. if(city){
  35. params['city'] = city
  36. }
  37. app.WxHttpRequestGet('house/advertises',params, this.GetAdvertiseDone, app.InterError)
  38. let list = [];
  39. var index = 0;
  40. const cities = CHINA.cites["0"];
  41. for(const i in cities){
  42. list.push({
  43. 'code':i,
  44. 'id':index++,
  45. 'name':cities[i]
  46. })
  47. }
  48. this.setData({
  49. list: list,
  50. listCur: list[0]
  51. })
  52. wx.hideLoading()
  53. },
  54. onReady() {
  55. },
  56. CityClick(e){
  57. var cityName = e.currentTarget.dataset.cityName;
  58. app.globalData.province = e.currentTarget.dataset.province;
  59. app.globalData.city = cityName;
  60. app.globalData.district = "";
  61. app.globalData.index_new_city = true;
  62. app.globalData.discuss_new_city = true;
  63. app.ShowToast('城市修改成功');
  64. var pre = app.getPrepage();
  65. pre.setData({
  66. new_city:true,
  67. houses:[],
  68. page:0,
  69. activekey: 'all',
  70. city:cityName,
  71. placeholder:cityName
  72. });
  73. setTimeout(function () {
  74. wx.navigateBack();
  75. },1500)
  76. },
  77. tabSelect(e) {
  78. this.setData({
  79. TabCur: e.currentTarget.dataset.id,
  80. MainCur: e.currentTarget.dataset.id,
  81. VerticalNavTop: (e.currentTarget.dataset.id - 1) * 50
  82. })
  83. },
  84. /**
  85. * @return {boolean}
  86. */
  87. VerticalMain(e) {
  88. let that = this;
  89. let list = this.data.list;
  90. let tabHeight = 0;
  91. if (this.data.load) {
  92. for (let i = 0; i < list.length; i++) {
  93. let view = wx.createSelectorQuery().select("#main-" + list[i].id);
  94. view.fields({
  95. size: true
  96. }, data => {
  97. list[i].top = tabHeight;
  98. tabHeight = tabHeight + data.height;
  99. list[i].bottom = tabHeight;
  100. }).exec();
  101. }
  102. that.setData({
  103. load: false,
  104. list: list
  105. })
  106. }
  107. let scrollTop = e.detail.scrollTop + 20;
  108. for (let i = 0; i < list.length; i++) {
  109. if (scrollTop > list[i].top && scrollTop < list[i].bottom) {
  110. that.setData({
  111. VerticalNavTop: (list[i].id - 1) * 50,
  112. TabCur: list[i].id
  113. })
  114. return false
  115. }
  116. }
  117. }
  118. })