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. active: 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. active: 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. //改变民宿或物品
  51. change(e) {
  52. console.log(this.data.value);
  53. this.setData({
  54. active: 0
  55. })
  56. if (this.data.value == '民宿') {
  57. this.getRoomOrder()
  58. } else {
  59. }
  60. },
  61. //改变订单状态
  62. onChange(event) {
  63. let active = event.detail.name;
  64. this.setData({
  65. active: active
  66. });
  67. if (this.data.value == '民宿') {
  68. this.getRoomOrder()
  69. } else {
  70. }
  71. console.log(this.data.active, this.data.value);
  72. },
  73. formatDate2(date1, date2) {
  74. date1 = new Date(date1);
  75. date2 = new Date(date2);
  76. // 获取年份、月份和日期
  77. const year1 = date1.getFullYear();
  78. const month1 = date1.getMonth() + 1; // 月份从0开始,所以要加1
  79. const day1 = date1.getDate();
  80. const year2 = date2.getFullYear();
  81. const month2 = date2.getMonth() + 1; // 月份从0开始,所以要加1
  82. const day2 = date2.getDate();
  83. // 返回格式化的字符串
  84. return `${year1}年${month1}月${day1}日入住 - ${year2}年${month2}月${day2}日离店`;
  85. },
  86. async getRoomOrder() {
  87. let Order = new Parse.Query('RoomOrder');
  88. Order.equalTo('company', company);
  89. Order.include('room');
  90. Order.equalTo('user', Parse.User.current().id);
  91. Order.include('shopStore');
  92. if (this.data.active == 0) {
  93. Order.equalTo('status', 100);
  94. }
  95. if (this.data.active == 1) {
  96. Order.equalTo('status', 200);
  97. }
  98. if (this.data.active == 2) {
  99. console.log(this.data.active);
  100. Order.equalTo('status', 800);
  101. }
  102. // 添加排序条件
  103. Order.descending('updatedAt');
  104. let room = await Order.find();
  105. let roomList = room.map(async item => {
  106. let roomItme = item.toJSON();
  107. roomItme.tiem = await this.formatDate2(roomItme.startTime.iso, roomItme.endTime.iso)
  108. return roomItme
  109. });
  110. let roomList2 = await Promise.all(roomList);
  111. this.setData({
  112. roomList: roomList2
  113. })
  114. console.log(this.data.roomList);
  115. },
  116. gourl(e) {
  117. const url = e.currentTarget.dataset.url;
  118. const id = e.currentTarget.dataset.id;
  119. // 构造要传递的信息
  120. const info = {
  121. objectId: id,
  122. value:this.data.value
  123. };
  124. // 将信息转为查询字符串
  125. const queryString = Object.keys(info)
  126. .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(info[key])}`)
  127. .join('&');
  128. // 使用查询字符串跳转
  129. wx.navigateTo({
  130. url: `${url}?${queryString}`,
  131. });
  132. },
  133. /**
  134. * 生命周期函数--监听页面初次渲染完成
  135. */
  136. onReady: function () {
  137. },
  138. /**
  139. * 生命周期函数--监听页面显示
  140. */
  141. onShow: function () {
  142. },
  143. /**
  144. * 生命周期函数--监听页面隐藏
  145. */
  146. onHide: function () {
  147. },
  148. /**
  149. * 生命周期函数--监听页面卸载
  150. */
  151. onUnload: function () {
  152. },
  153. /**
  154. * 页面相关事件处理函数--监听用户下拉动作
  155. */
  156. onPullDownRefresh: function () {
  157. },
  158. /**
  159. * 页面上拉触底事件的处理函数
  160. */
  161. onReachBottom: function () {
  162. },
  163. /**
  164. * 用户点击右上角分享
  165. */
  166. onShareAppMessage: function () {
  167. }
  168. })