index.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. // nova-tourism/pages/homestay/homestay-detail/index.js
  2. let Parse = getApp().Parse;
  3. const company = getApp().globalData.company
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. //屏幕高度
  10. statusBarHeight: 0, // 状态栏高度
  11. screenHeight: 0, // 屏幕高度
  12. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  13. bottomNavHeight: 0, // 底部导航栏高度
  14. contentHeight: 0, // 可用内容高度
  15. // 轮播图数组
  16. imageUrls: ['https://tse4-mm.cn.bing.net/th/id/OIP-C.3r1vguZyWFUJ80A2Nf2k3AHaEK?rs=1&pid=ImgDetMain', 'https://ts1.cn.mm.bing.net/th/id/R-C.9881613a29f26488b40938427aa585e4?rik=fim4XvDejjHE%2fQ&riu=http%3a%2f%2fn.sinaimg.cn%2fsinakd20220516ac%2f797%2fw2048h1149%2f20220516%2fb0aa-5aca29fe2dfa69c385118bbc74d039de.jpg&ehk=tzq%2bJP6uMipI0aIHY3bMSVO7lS7ZQM6TKMlwZ5CFP4s%3d&risl=&pid=ImgRaw&r=0', 'https://pic3.zhimg.com/v2-5fb13110e1de13d4c11e6e7f5b8026da_r.jpg', 'https://desk-fd.zol-img.com.cn/t_s960x600c5/g5/M00/02/04/ChMkJ1bKyEyIMaKUAAhskHwWGqUAALIAAM2KsIACGyo249.jpg'],
  17. index: 1,
  18. //
  19. decodedDateStart: '',
  20. decodedDateEnd: '',
  21. objectId: "",
  22. daysBetween: 0,
  23. istoday:null,
  24. storeList: [],
  25. roomList: []
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. // 计算
  32. const systemInfo = wx.getSystemInfoSync();
  33. const statusBarHeight = systemInfo.statusBarHeight || 0;
  34. const screenHeight = systemInfo.screenHeight || 0;
  35. const custom = wx.getMenuButtonBoundingClientRect();
  36. const customHeight = custom.height + 10 + 2 || 0;
  37. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  38. const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  39. if (bottomNavHeight) {
  40. const padding_bottom = bottomNavHeight * 750 / systemInfo.windowWidth
  41. this.setData({
  42. bottomNavHeight: padding_bottom
  43. })
  44. console.log(this.data.bottomNavHeight);
  45. } else {
  46. this.setData({
  47. bottomNavHeight: 40
  48. })
  49. }
  50. this.setData({
  51. statusBarHeight,
  52. screenHeight,
  53. customHeight,
  54. contentHeight
  55. });
  56. const {
  57. objectId,
  58. date_start,
  59. date_end,
  60. daysBetween,
  61. istoday
  62. } = options;
  63. // 解码接收到的参数
  64. const decodedDateStart = decodeURIComponent(date_start);
  65. const decodedDateEnd = decodeURIComponent(date_end);
  66. this.setData({
  67. decodedDateStart,
  68. decodedDateEnd,
  69. objectId,
  70. daysBetween,
  71. istoday
  72. })
  73. console.log('istoday',this.data.istoday);
  74. this.gethomestay()
  75. this.getroom()
  76. },
  77. /**
  78. * 生命周期函数--监听页面初次渲染完成
  79. */
  80. onReady: function () {
  81. },
  82. /**
  83. * 生命周期函数--监听页面显示
  84. */
  85. onShow: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面隐藏
  89. */
  90. onHide: function () {
  91. },
  92. /**
  93. * 生命周期函数--监听页面卸载
  94. */
  95. onUnload: function () {
  96. },
  97. /**
  98. * 页面相关事件处理函数--监听用户下拉动作
  99. */
  100. onPullDownRefresh: function () {
  101. },
  102. /**
  103. * 页面上拉触底事件的处理函数
  104. */
  105. onReachBottom: function () {
  106. },
  107. /**
  108. * 用户点击右上角分享
  109. */
  110. onShareAppMessage: function () {
  111. },
  112. //随轮播图变化而变化
  113. onSwiperChange: function (event) {
  114. const currentIndex = event.detail.current; // 获取当前索引
  115. this.setData({
  116. index: currentIndex + 1
  117. })
  118. },
  119. //获取名宿信息
  120. async gethomestay() {
  121. let ShopStore = new Parse.Query('ShopStore');
  122. ShopStore.equalTo('company', company);
  123. ShopStore.equalTo('type', "stay");
  124. ShopStore.equalTo('objectId', this.data.objectId);
  125. ShopStore.notEqualTo('isDeleted', "true");
  126. let store = await ShopStore.find();
  127. let storeList = store.map(item => item.toJSON());
  128. this.setData({
  129. storeList
  130. });
  131. console.log(this.data.storeList);
  132. },
  133. //获取房间信息
  134. async getroom() {
  135. let room = new Parse.Query('ShopRoom');
  136. room.equalTo('company', company);
  137. room.equalTo('shop', this.data.objectId);
  138. room.equalTo('isEnabled', 'true');
  139. room.notEqualTo('isDeleted', 'true');
  140. let room2 = await room.find();
  141. let roomList = room2.map(item => item.toJSON());
  142. // 对 roomList 进行排序
  143. roomList.sort((a, b) => {
  144. // 先比较 remaining,remaining 为 0 的排后面
  145. if (a.remaining === 0 && b.remaining !== 0) {
  146. return 1; // a 排后面
  147. }
  148. if (a.remaining !== 0 && b.remaining === 0) {
  149. return -1; // a 排前面
  150. }
  151. // 如果两个房间的 remaining 都不为 0,按数量升序排列
  152. return a.remaining - b.remaining;
  153. });
  154. this.setData({
  155. roomList
  156. })
  157. console.log('房间', this.data.roomList);
  158. }
  159. })