index.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 storeListPromises = store.map(async item => {
  129. let storeItem = item.toJSON();
  130. storeItem.iscollect = await this.iscollect(storeItem.objectId); // 等待iscollect的结果
  131. return storeItem;
  132. });
  133. let storeList = await Promise.all(storeListPromises); // 等待所有的Promise完成
  134. this.setData({
  135. storeList
  136. });
  137. console.log(this.data.storeList);
  138. },
  139. //获取房间信息
  140. async getroom() {
  141. let room = new Parse.Query('ShopRoom');
  142. room.equalTo('company', company);
  143. room.equalTo('shop', this.data.objectId);
  144. room.equalTo('isEnabled', 'true');
  145. room.include('benefitMap')
  146. room.notEqualTo('isDeleted', 'true');
  147. let room2 = await room.find();
  148. let roomList = room2.map(item => item.toJSON());
  149. // 对 roomList 进行排序
  150. roomList.sort((a, b) => {
  151. // 先比较 remaining,remaining 为 0 的排后面
  152. if (a.remaining === 0 && b.remaining !== 0) {
  153. return 1; // a 排后面
  154. }
  155. if (a.remaining !== 0 && b.remaining === 0) {
  156. return -1; // a 排前面
  157. }
  158. // 如果两个房间的 remaining 都不为 0,按数量升序排列
  159. return a.remaining - b.remaining;
  160. });
  161. this.setData({
  162. roomList
  163. })
  164. console.log('房间', this.data.roomList);
  165. },
  166. //收藏功能
  167. async iscollect(object) {
  168. const currentUser = Parse.User.current();
  169. let Collect = new Parse.Query('DramaShopCollect');
  170. Collect.equalTo('company', company);
  171. Collect.equalTo('user', currentUser.id);
  172. Collect.equalTo('homestayStore', object);
  173. Collect.equalTo('isCollect', 'true');
  174. Collect.notEqualTo('isDeleted', "true");
  175. let collect = await Collect.first();
  176. if (collect) {
  177. return true
  178. } else {
  179. return false
  180. }
  181. },
  182. //获取轮播图
  183. async getpic() {
  184. let Banner = new Parse.Query('Banner');
  185. Banner.equalTo('company', company);
  186. Banner.equalTo('store', this.data.objectId);
  187. Banner.equalTo('isEnabled', 'true');
  188. Banner.notEqualTo('isDeleted', 'true');
  189. Banner.select('image');
  190. let Banner2 = await Banner.find();
  191. // 提取 image 属性并存储到 imageUrls 中
  192. let imageUrls = Banner2.map(item => item.get('image')); // 使用 get() 方法获取 image 属性
  193. this.setData({
  194. imageUrls // 将提取的 imageUrls 存储到组件状态中
  195. });
  196. console.log(this.data.imageUrls); // 输出 imageUrls
  197. },
  198. })