index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. let Parse = getApp().Parse
  2. const company = getApp().globalData.company
  3. const rechText = require('../../../../utils/rech-text')
  4. import date from '../../../../utils/date';
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. // list: {},
  11. // show: false,
  12. hotelId: null,
  13. SwiperInfo: {
  14. duration: 500,
  15. autoplay: false,
  16. interval: 2000
  17. },
  18. rooms: [],
  19. loadIndex: 1,
  20. time: '', // 入住时间
  21. condition: '', // 入住条件
  22. orders: [],
  23. commentCount: 0 // 评论总数
  24. },
  25. showPopup() {
  26. this.setData({
  27. show: true
  28. })
  29. },
  30. //关闭 弹窗
  31. onClose: function () {
  32. console.log(123)
  33. this.setData({
  34. show: false
  35. })
  36. console.log(this.data.show)
  37. },
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. onLoad: function (options) {
  42. this.setData({
  43. activeColor: getApp().globalData.activeColor || '#229293'
  44. })
  45. let hotelId = options.id
  46. if (!hotelId) {
  47. wx.navigateTo({
  48. url: `/nova-tourism/pages/index/index`
  49. })
  50. }
  51. this.setData({
  52. hotelId
  53. })
  54. this.getData()
  55. },
  56. /**
  57. * 生命周期函数--监听页面初次渲染完成
  58. */
  59. onReady: function () {},
  60. /**
  61. * 生命周期函数--监听页面显示
  62. */
  63. onShow: function () {},
  64. /**
  65. * 生命周期函数--监听页面隐藏
  66. */
  67. onHide: function () {},
  68. /**
  69. * 生命周期函数--监听页面卸载
  70. */
  71. onUnload: function () {},
  72. /**
  73. * 页面相关事件处理函数--监听用户下拉动作
  74. */
  75. onPullDownRefresh: function () {},
  76. /**
  77. * 页面上拉触底事件的处理函数
  78. */
  79. onReachBottom: function () {},
  80. /**
  81. * 用户点击右上角分享
  82. */
  83. onShareAppMessage: function () {
  84. return {
  85. title: '民宿详情',
  86. }
  87. },
  88. async getData() {
  89. await this.getHotel()
  90. this.getRooms()
  91. this.getRoomComments()
  92. },
  93. async getRoomComments() {
  94. let Order = new Parse.Query('RoomOrder')
  95. Order.equalTo("shopStore", this.data.hotelId);
  96. Order.include("user");
  97. Order.greaterThanOrEqualTo("status", 800);
  98. Order.limit(2)
  99. let orders = await Order.find()
  100. if (orders && orders.length) {
  101. orders = orders.map(order => {
  102. order['time'] = date.formatTime('YY-mm-dd HH:MM', order.updatedAt)
  103. order.toJSON()
  104. })
  105. console.log(orders)
  106. this.setData({
  107. orders
  108. })
  109. }
  110. let commentCount = await Order.count()
  111. console.log(commentCount);
  112. this.setData({
  113. commentCount
  114. })
  115. console.log(this.data.orders);
  116. },
  117. async getHotel() {
  118. let Hotel = new Parse.Query('ShopStore')
  119. let hotel = await Hotel.get(this.data.hotelId)
  120. hotel = hotel.toJSON()
  121. if (hotel.content) {
  122. hotel.content = rechText.formatRichText(hotel.content)
  123. }
  124. console.log(hotel)
  125. this.setData({
  126. hotel
  127. })
  128. },
  129. async getRooms() {
  130. let Room = new Parse.Query('ShopRoom')
  131. Room.equalTo('company', company)
  132. Room.equalTo('isEnabled', true)
  133. Room.equalTo("shop", this.data.hotelId)
  134. Room.select(
  135. 'name',
  136. 'images',
  137. 'price',
  138. 'total',
  139. 'remaining',
  140. 'merber',
  141. 'type',
  142. 'area',
  143. 'tags'
  144. )
  145. Room.skip((this.data.loadIndex - 1) * 10)
  146. Room.limit(10)
  147. let rooms = await Room.find()
  148. rooms = rooms.map((room) => {
  149. room = room.toJSON()
  150. room.tags.slice(0, 5)
  151. return room
  152. })
  153. console.log(rooms)
  154. if (this.data.loadIndex != 1) {
  155. rooms = this.data.rooms.concat(rooms)
  156. }
  157. this.setData({
  158. rooms
  159. })
  160. },
  161. navigateComments() {
  162. wx.navigateTo({
  163. url: `/nova-tourism/pages/homestay/comments/index?id=${this.data.roomId}`
  164. })
  165. },
  166. details(event) {
  167. let id = event.detail.id
  168. console.log(id)
  169. wx.navigateTo({
  170. url: `/nova-tourism/pages/homestay/room-detail/index?id=${id}`
  171. })
  172. },
  173. loadMore() {
  174. this.data.loadIndex++;
  175. console.log('ddddddddddddd', this.data.loadIndex)
  176. this.getRooms()
  177. },
  178. /* 选择入住条件 */
  179. selectCheck() {},
  180. /* 选择入住时间 */
  181. selectTime() {}
  182. })