index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // nova-tourism/pages/my/my-order/index.js
  2. let Parse = getApp().Parse;
  3. const company = getApp().globalData.company
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. statusBarHeight: 0,
  10. screenHeight: 0,
  11. customHeight: 0,
  12. bottomNavHeight: 0,
  13. contentHeight: 0,
  14. currentTab:0,
  15. option: [{
  16. text: '民宿订单',
  17. value: '民宿'
  18. },
  19. {
  20. text: '物品订单',
  21. value: '物品'
  22. },
  23. ],
  24. value: '民宿',
  25. roomList: [],
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. this.setData({
  32. currentTab: Number(options.active)
  33. })
  34. const systemInfo = wx.getSystemInfoSync();
  35. const statusBarHeight = systemInfo.statusBarHeight || 0;
  36. const screenHeight = systemInfo.screenHeight || 0;
  37. const custom = wx.getMenuButtonBoundingClientRect();
  38. const customHeight = custom.height + 10 + 2 || 0;
  39. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  40. const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  41. this.setData({
  42. statusBarHeight,
  43. screenHeight,
  44. customHeight,
  45. bottomNavHeight,
  46. contentHeight
  47. });
  48. this.getRoomOrder()
  49. },
  50. switchTab (e) {
  51. const index = e.currentTarget.dataset.index;
  52. this.setData({
  53. currentTab: index,
  54. });
  55. if (this.data.value == '民宿') {
  56. this.getRoomOrder()
  57. } else {
  58. }
  59. console.log(this.data.currentTab, this.data.value);
  60. },
  61. //改变民宿或物品
  62. change(e) {
  63. console.log(this.data.value);
  64. this.setData({
  65. currentTab: 0
  66. })
  67. if (this.data.value == '民宿') {
  68. this.getRoomOrder()
  69. } else {
  70. }
  71. },
  72. formatDate2(date1, date2) {
  73. date1 = new Date(date1);
  74. date2 = new Date(date2);
  75. // 获取年份、月份和日期
  76. const year1 = date1.getFullYear();
  77. const month1 = date1.getMonth() + 1; // 月份从0开始,所以要加1
  78. const day1 = date1.getDate();
  79. const year2 = date2.getFullYear();
  80. const month2 = date2.getMonth() + 1; // 月份从0开始,所以要加1
  81. const day2 = date2.getDate();
  82. // 返回格式化的字符串
  83. return `${year1}年${month1}月${day1}日入住 - ${year2}年${month2}月${day2}日离店`;
  84. },
  85. async getRoomOrder() {
  86. let Order = new Parse.Query('RoomOrder');
  87. Order.equalTo('company', company);
  88. Order.include('room');
  89. Order.equalTo('user', Parse.User.current().id);
  90. Order.include('shopStore');
  91. if (this.data.currentTab == 0) {
  92. Order.equalTo('status', 100);
  93. }
  94. if (this.data.currentTab == 1) {
  95. Order.equalTo('status', 200);
  96. }
  97. if (this.data.currentTab == 2) {
  98. Order.equalTo('status', 800);
  99. }
  100. // 添加排序条件
  101. Order.descending('updatedAt');
  102. let room = await Order.find();
  103. let roomList = room.map(async item => {
  104. let roomItme = item.toJSON();
  105. roomItme.tiem = await this.formatDate2(roomItme.startTime.iso, roomItme.endTime.iso)
  106. return roomItme
  107. });
  108. let roomList2 = await Promise.all(roomList);
  109. this.setData({
  110. roomList: roomList2
  111. })
  112. console.log(this.data.roomList);
  113. },
  114. gourl(e) {
  115. const url = e.currentTarget.dataset.url;
  116. const id = e.currentTarget.dataset.id;
  117. // 构造要传递的信息
  118. const info = {
  119. objectId: id,
  120. value:this.data.value
  121. };
  122. // 将信息转为查询字符串
  123. const queryString = Object.keys(info)
  124. .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(info[key])}`)
  125. .join('&');
  126. // 使用查询字符串跳转
  127. wx.navigateTo({
  128. url: `${url}?${queryString}`,
  129. });
  130. },
  131. /**
  132. * 生命周期函数--监听页面初次渲染完成
  133. */
  134. onReady: function () {
  135. },
  136. /**
  137. * 生命周期函数--监听页面显示
  138. */
  139. onShow: function () {
  140. },
  141. /**
  142. * 生命周期函数--监听页面隐藏
  143. */
  144. onHide: function () {
  145. },
  146. /**
  147. * 生命周期函数--监听页面卸载
  148. */
  149. onUnload: function () {
  150. },
  151. /**
  152. * 页面相关事件处理函数--监听用户下拉动作
  153. */
  154. onPullDownRefresh: function () {
  155. },
  156. /**
  157. * 页面上拉触底事件的处理函数
  158. */
  159. onReachBottom: function () {
  160. },
  161. /**
  162. * 用户点击右上角分享
  163. */
  164. onShareAppMessage: function () {
  165. }
  166. })