index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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: [],
  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. this.getpic()
  77. },
  78. /**
  79. * 生命周期函数--监听页面初次渲染完成
  80. */
  81. onReady: function () {
  82. },
  83. /**
  84. * 生命周期函数--监听页面显示
  85. */
  86. onShow: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面隐藏
  90. */
  91. onHide: function () {
  92. },
  93. /**
  94. * 生命周期函数--监听页面卸载
  95. */
  96. onUnload: function () {
  97. },
  98. /**
  99. * 页面相关事件处理函数--监听用户下拉动作
  100. */
  101. onPullDownRefresh: function () {
  102. },
  103. /**
  104. * 页面上拉触底事件的处理函数
  105. */
  106. onReachBottom: function () {
  107. },
  108. /**
  109. * 用户点击右上角分享
  110. */
  111. onShareAppMessage: function () {
  112. },
  113. //随轮播图变化而变化
  114. onSwiperChange: function (event) {
  115. const currentIndex = event.detail.current; // 获取当前索引
  116. this.setData({
  117. index: currentIndex + 1
  118. })
  119. },
  120. //获取名宿信息
  121. async gethomestay() {
  122. let ShopStore = new Parse.Query('ShopStore');
  123. ShopStore.equalTo('company', company);
  124. ShopStore.equalTo('type', "stay");
  125. ShopStore.equalTo('objectId', this.data.objectId);
  126. ShopStore.notEqualTo('isDeleted', "true");
  127. let store = await ShopStore.find();
  128. let storeList = store.map(item => item.toJSON());
  129. this.setData({
  130. storeList
  131. });
  132. console.log(this.data.storeList);
  133. },
  134. //获取房间信息
  135. async getroom() {
  136. let room = new Parse.Query('ShopRoom');
  137. room.equalTo('company', company);
  138. room.equalTo('shop', this.data.objectId);
  139. room.equalTo('isEnabled', 'true');
  140. room.notEqualTo('isDeleted', 'true');
  141. let room2 = await room.find();
  142. let roomList = room2.map(item => item.toJSON());
  143. // 对 roomList 进行排序
  144. roomList.sort((a, b) => {
  145. // 先比较 remaining,remaining 为 0 的排后面
  146. if (a.remaining === 0 && b.remaining !== 0) {
  147. return 1; // a 排后面
  148. }
  149. if (a.remaining !== 0 && b.remaining === 0) {
  150. return -1; // a 排前面
  151. }
  152. // 如果两个房间的 remaining 都不为 0,按数量升序排列
  153. return a.remaining - b.remaining;
  154. });
  155. this.setData({
  156. roomList
  157. })
  158. console.log('房间', this.data.roomList);
  159. },
  160. //获取轮播图
  161. async getpic() {
  162. let Banner = new Parse.Query('Banner');
  163. Banner.equalTo('company', company);
  164. Banner.equalTo('store', this.data.objectId);
  165. Banner.equalTo('isEnabled', 'true');
  166. Banner.notEqualTo('isDeleted', 'true');
  167. Banner.select('image');
  168. let Banner2 = await Banner.find();
  169. // 提取 image 属性并存储到 imageUrls 中
  170. let imageUrls = Banner2.map(item => item.get('image')); // 使用 get() 方法获取 image 属性
  171. this.setData({
  172. imageUrls // 将提取的 imageUrls 存储到组件状态中
  173. });
  174. console.log(this.data.imageUrls); // 输出 imageUrls
  175. },
  176. })