index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. let Parse = getApp().Parse
  2. const company = getApp().globalData.company
  3. const compute = require('../../../utils/compute.js')
  4. let navigationBarHeight = getApp().globalData.statusBarHeight + 44;
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {},
  10. /**
  11. * 组件的初始数据
  12. */
  13. data: {
  14. imgUrls: [
  15. 'https://s1.ax1x.com/2023/04/10/ppqifvF.png',
  16. 'https://s1.ax1x.com/2023/04/10/ppqiWgU.png',
  17. 'https://s1.ax1x.com/2023/04/10/ppqiR3T.png'
  18. ],
  19. list: [],
  20. hotels: [],
  21. rooms: [],
  22. active: 0,
  23. type: 'recommend',
  24. loadIndex: 1,
  25. searchVal: '',
  26. showTab: false,
  27. stickytop: navigationBarHeight,
  28. tabs: [{
  29. title: '推荐',
  30. icon: 'https://s1.ax1x.com/2023/04/10/ppqEqdH.png',
  31. type: 'recommend'
  32. },
  33. {
  34. title: '价格',
  35. icon: 'https://s1.ax1x.com/2023/04/10/ppqkh79.png',
  36. type: 'price'
  37. },
  38. ],
  39. tabIndex: 0,
  40. banners:[]
  41. },
  42. ready: function () {
  43. // 在组件布局完成后执行,确保options参数中有data信息
  44. // this.selectComponent('#tabs').resize()
  45. // this.getRooms()
  46. },
  47. lifetimes: {
  48. created() {
  49. this.getBanner()
  50. },
  51. attached() {
  52. }
  53. },
  54. /**
  55. * 组件的方法列表
  56. */
  57. methods: {
  58. details(e) {
  59. let id = e.detail.id
  60. console.log(id)
  61. wx.navigateTo({
  62. url: `/nova-tourism/pages/homestay/room-detail/index?id=${id}`
  63. })
  64. },
  65. async getHotels(type) {
  66. let Hotel = new Parse.Query('ShopStore')
  67. Hotel.notEqualTo('isDeleted', "true")
  68. Hotel.equalTo('company', company)
  69. Hotel.equalTo('type', 'stay')
  70. Hotel.select(
  71. 'cover',
  72. 'storeName',
  73. 'perCapita',
  74. 'address',
  75. 'type',
  76. 'isShow'
  77. )
  78. Hotel.equalTo('isShow', true)
  79. Hotel.skip((this.data.loadIndex - 1) * 10)
  80. if (type == 'price') {
  81. Hotel.ascending('perCapita')
  82. }
  83. Hotel.limit(10)
  84. let hotels = await Hotel.find()
  85. hotels = hotels.map((hotel) => hotel.toJSON())
  86. hotels = this.data.loadIndex == 1 ? hotels : this.data.hotels.concat(hotels)
  87. this.setData({
  88. hotels
  89. })
  90. },
  91. toSearch() {
  92. wx.navigateTo({
  93. url: '/nova-tourism/pages/search/search'
  94. })
  95. },
  96. search(event) {
  97. console.log(event);
  98. this.getRooms()
  99. },
  100. searchClear() {
  101. this.data.searchVal = '';
  102. this.getRooms()
  103. },
  104. showSearchBtn() {
  105. this.setData({
  106. searchBtn: true
  107. })
  108. },
  109. hiddenSearchBtn() {
  110. this.setData({
  111. searchBtn: false
  112. })
  113. },
  114. onTabClick(e) {
  115. let {
  116. id,
  117. type
  118. } = e.currentTarget.dataset;
  119. this.data.active = id
  120. this.data.loadIndex = 1
  121. this.data.type = type
  122. this.setData({
  123. tabIndex: id,
  124. })
  125. this.getRooms()
  126. },
  127. tabChange(event) {
  128. this.data.active = event.detail.name
  129. this.data.loadIndex = 1
  130. this.data.type = event.detail.name
  131. this.getRooms()
  132. },
  133. loadMore() {
  134. this.data.loadIndex++
  135. this.getRooms()
  136. },
  137. async getRooms() {
  138. let type = this.data.type;
  139. console.log('getRooms');
  140. let Room = new Parse.Query('ShopRoom')
  141. Room.equalTo('company', company)
  142. Room.equalTo('isEnabled', true)
  143. if (this.data.searchVal != '') {
  144. Room.contains('name', this.data.searchVal)
  145. }
  146. if (type == 'price') {
  147. Room.ascending('price')
  148. }
  149. if (type == 'recommend') {
  150. Room.equalTo('isRecom', true)
  151. }
  152. Room.skip((this.data.loadIndex - 1) * 10)
  153. Room.select(
  154. 'name',
  155. 'images',
  156. 'price',
  157. 'total',
  158. 'remaining',
  159. 'merber',
  160. 'type',
  161. 'area',
  162. 'tags',
  163. 'address'
  164. )
  165. Room.limit(10)
  166. let rooms = await Room.find()
  167. rooms = rooms.map((room) => room.toJSON())
  168. // hotels = hotels.concat(hotels).concat(hotels).concat(hotels).concat(hotels)
  169. rooms = this.data.loadIndex == 1 ? rooms : this.data.rooms.concat(rooms)
  170. this.setData({
  171. rooms
  172. })
  173. },
  174. async getBanner() {
  175. let Banner = new Parse.Query('Banner')
  176. Banner.notEqualTo('isDeleted', "true")
  177. Banner.equalTo('company', company)
  178. Banner.equalTo('isEnabled', "true")
  179. Banner.equalTo('type', 'homestay')
  180. let banner = await Banner.find()
  181. if (banner && banner.length > 0) {
  182. let listJSON = []
  183. banner.forEach(c => {
  184. listJSON.push(c.toJSON())
  185. })
  186. this.setData({
  187. banners: listJSON
  188. })
  189. }
  190. },
  191. }
  192. })