index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. show: false,
  27. showid:null,
  28. },
  29. onClose() {
  30. this.setData({
  31. show: false,
  32. }); // 关闭弹窗并重置标志位
  33. },
  34. ONShow(e) {
  35. const id =e.currentTarget.dataset.item.objectId
  36. this.setData({
  37. showid:id,
  38. show: true,
  39. }); // 设置弹窗显示
  40. console.log(this.data.showid);
  41. },
  42. //订单完成
  43. async ordercom(e){
  44. console.log(e.currentTarget.dataset.item.objectId);
  45. let objectId = e.currentTarget.dataset.item.objectId
  46. let newOrder = new Parse.Query('RoomOrder');
  47. newOrder.equalTo('company', company);
  48. newOrder.equalTo('objectId', objectId);
  49. newOrder.notEqualTo('isDeleted', true);
  50. let order = await newOrder.first();
  51. console.log(order);
  52. order.set('status',102)
  53. try{
  54. let saveDate = await order.save();
  55. console.log('保存成功');
  56. this.setData({
  57. showid:null
  58. })
  59. this.getRoomOrder()
  60. }catch (error) {
  61. console.error("保存数据时出现错误:", error);
  62. }
  63. },
  64. /**
  65. * 生命周期函数--监听页面加载
  66. */
  67. onLoad: function (options) {
  68. this.setData({
  69. currentTab: Number(options.active)
  70. })
  71. const systemInfo = wx.getSystemInfoSync();
  72. const statusBarHeight = systemInfo.statusBarHeight || 0;
  73. const screenHeight = systemInfo.screenHeight || 0;
  74. const custom = wx.getMenuButtonBoundingClientRect();
  75. const customHeight = custom.height + 10 + 2 || 0;
  76. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  77. const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  78. this.setData({
  79. statusBarHeight,
  80. screenHeight,
  81. customHeight,
  82. bottomNavHeight,
  83. contentHeight
  84. });
  85. this.getRoomOrder()
  86. },
  87. switchTab (e) {
  88. const index = e.currentTarget.dataset.index;
  89. this.setData({
  90. currentTab: index,
  91. });
  92. if (this.data.value == '民宿') {
  93. this.getRoomOrder()
  94. } else {
  95. }
  96. console.log(this.data.currentTab, this.data.value);
  97. },
  98. //改变民宿或物品
  99. change(e) {
  100. console.log(this.data.value);
  101. this.setData({
  102. currentTab: 0
  103. })
  104. if (this.data.value == '民宿') {
  105. this.getRoomOrder()
  106. } else {
  107. }
  108. },
  109. formatDate2(date1, date2) {
  110. date1 = new Date(date1);
  111. date2 = new Date(date2);
  112. // 获取年份、月份和日期
  113. const year1 = date1.getFullYear();
  114. const month1 = date1.getMonth() + 1; // 月份从0开始,所以要加1
  115. const day1 = date1.getDate();
  116. const year2 = date2.getFullYear();
  117. const month2 = date2.getMonth() + 1; // 月份从0开始,所以要加1
  118. const day2 = date2.getDate();
  119. // 返回格式化的字符串
  120. return `${year1}年${month1}月${day1}日入住 - ${year2}年${month2}月${day2}日离店`;
  121. },
  122. async getRoomOrder() {
  123. let Order = new Parse.Query('RoomOrder');
  124. Order.equalTo('company', company);
  125. Order.include('room');
  126. Order.equalTo('user', Parse.User.current().id);
  127. Order.include('shopStore');
  128. if (this.data.currentTab == 0) {
  129. Order.equalTo('status', 100)
  130. }
  131. if (this.data.currentTab == 1) {
  132. Order.equalTo('status', 200);
  133. }
  134. if (this.data.currentTab == 2) {
  135. Order.equalTo('status', 800);
  136. }
  137. // 添加排序条件
  138. Order.descending('updatedAt');
  139. let room = await Order.find();
  140. let roomList = room.map(async item => {
  141. let roomItme = item.toJSON();
  142. roomItme.tiem = await this.formatDate2(roomItme.startTime.iso, roomItme.endTime.iso)
  143. return roomItme
  144. });
  145. let roomList2 = await Promise.all(roomList);
  146. this.setData({
  147. roomList: roomList2
  148. })
  149. console.log(this.data.roomList);
  150. },
  151. gourl(e) {
  152. const url = e.currentTarget.dataset.url;
  153. const id = e.currentTarget.dataset.id;
  154. // 构造要传递的信息
  155. const info = {
  156. objectId: id,
  157. value:this.data.value
  158. };
  159. // 将信息转为查询字符串
  160. const queryString = Object.keys(info)
  161. .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(info[key])}`)
  162. .join('&');
  163. // 使用查询字符串跳转
  164. wx.navigateTo({
  165. url: `${url}?${queryString}`,
  166. });
  167. },
  168. /**
  169. * 生命周期函数--监听页面初次渲染完成
  170. */
  171. onReady: function () {
  172. },
  173. /**
  174. * 生命周期函数--监听页面显示
  175. */
  176. onShow: function () {
  177. },
  178. /**
  179. * 生命周期函数--监听页面隐藏
  180. */
  181. onHide: function () {
  182. },
  183. /**
  184. * 生命周期函数--监听页面卸载
  185. */
  186. onUnload: function () {
  187. },
  188. /**
  189. * 页面相关事件处理函数--监听用户下拉动作
  190. */
  191. onPullDownRefresh: function () {
  192. },
  193. /**
  194. * 页面上拉触底事件的处理函数
  195. */
  196. onReachBottom: function () {
  197. },
  198. /**
  199. * 用户点击右上角分享
  200. */
  201. onShareAppMessage: function () {
  202. }
  203. })