index.js 5.2 KB

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