index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. let Parse = getApp().Parse
  2. const company = getApp().globalData.company
  3. let navigationBarHeight = getApp().globalData.statusBarHeight + 44;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. hotels: [],
  10. active: 0,
  11. loadIndex: 1,
  12. searchVal: '',
  13. stickytop: navigationBarHeight
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. this.setData({
  20. activeColor: getApp().globalData.activeColor || '#229293'
  21. })
  22. this.getHotels()
  23. },
  24. details(e) {
  25. let id = e.detail.id
  26. console.log(id)
  27. wx.navigateTo({
  28. url: `/nova-tourism/pages/homestay/hotel-details/index?id=${id}`
  29. })
  30. },
  31. getHotels: async function (type) {
  32. let Hotel = new Parse.Query('ShopStore')
  33. Hotel.notEqualTo('isDeleted', "true")
  34. Hotel.equalTo('company', company)
  35. Hotel.equalTo('type', 'stay')
  36. if (this.data.searchVal != '') {
  37. Hotel.contains('storeName', this.data.searchVal)
  38. }
  39. Hotel.select(
  40. 'cover',
  41. 'storeName',
  42. 'perCapita',
  43. 'address',
  44. 'type',
  45. 'isShow'
  46. )
  47. // Hotel.equalTo('isShow', true)
  48. Hotel.skip((this.data.loadIndex - 1) * 10)
  49. if (type == 'price') {
  50. Hotel.ascending('perCapita')
  51. }
  52. Hotel.limit(10)
  53. let hotels = await Hotel.find()
  54. hotels = hotels.map((hotel) => hotel.toJSON())
  55. console.log(hotels)
  56. // hotels = hotels.concat(hotels).concat(hotels).concat(hotels).concat(hotels)
  57. hotels = this.data.loadIndex == 1 ? hotels : this.data.hotels.concat(hotels)
  58. console.log('hotels', hotels)
  59. this.setData({
  60. hotels
  61. })
  62. },
  63. search(event) {
  64. console.log(event, this.data.searchVal);
  65. this.getHotels()
  66. },
  67. searchClear() {
  68. this.data.searchVal = '';
  69. this.getHotels()
  70. },
  71. tabChange(event) {
  72. this.data.active = event.detail.name
  73. this.data.loadIndex = 1
  74. console.log(this.data.active)
  75. this.getHotels(event.detail.name)
  76. },
  77. loadMore() {
  78. this.data.loadIndex++
  79. console.log('ddddddddddddd', this.data.loadIndex)
  80. this.getHotels()
  81. },
  82. /**
  83. * 生命周期函数--监听页面初次渲染完成
  84. */
  85. onReady: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面显示
  89. */
  90. onShow: function () {
  91. },
  92. /**
  93. * 生命周期函数--监听页面隐藏
  94. */
  95. onHide: function () {
  96. },
  97. /**
  98. * 生命周期函数--监听页面卸载
  99. */
  100. onUnload: function () {
  101. },
  102. /**
  103. * 页面相关事件处理函数--监听用户下拉动作
  104. */
  105. onPullDownRefresh: function () {
  106. },
  107. /**
  108. * 页面上拉触底事件的处理函数
  109. */
  110. onReachBottom: function () {
  111. },
  112. /**
  113. * 用户点击右上角分享
  114. */
  115. onShareAppMessage: function () {
  116. }
  117. })