index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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: '民宿订单', value: '民宿' },
  17. { text: '物品订单', value: '物品' },
  18. ],
  19. value:'民宿',
  20. roomList:[],
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. this.setData({
  27. active:Number(options.active)
  28. })
  29. const systemInfo = wx.getSystemInfoSync();
  30. const statusBarHeight = systemInfo.statusBarHeight || 0;
  31. const screenHeight = systemInfo.screenHeight || 0;
  32. const custom = wx.getMenuButtonBoundingClientRect();
  33. const customHeight = custom.height + 10 + 2 || 0;
  34. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  35. const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  36. this.setData({
  37. statusBarHeight,
  38. screenHeight,
  39. customHeight,
  40. bottomNavHeight,
  41. contentHeight
  42. });
  43. this.getRoomOrder()
  44. },
  45. //改变民宿或物品
  46. change(e){
  47. console.log(this.data.value);
  48. this.setData({
  49. active:0
  50. })
  51. if(this.data.value=='民宿'){
  52. this.getRoomOrder()
  53. }else{
  54. }
  55. },
  56. //改变订单状态
  57. onChange(event){
  58. let active = event.detail.name;
  59. this.setData({
  60. active: active
  61. });
  62. if(this.data.value=='民宿'){
  63. this.getRoomOrder()
  64. }else{
  65. }
  66. console.log(this.data.active,this.data.value);
  67. },
  68. formatDate2(date1, date2) {
  69. date1 = new Date(date1);
  70. date2 = new Date(date2);
  71. // 获取年份、月份和日期
  72. const year1 = date1.getFullYear();
  73. const month1 = date1.getMonth() + 1; // 月份从0开始,所以要加1
  74. const day1 = date1.getDate();
  75. const year2 = date2.getFullYear();
  76. const month2 = date2.getMonth() + 1; // 月份从0开始,所以要加1
  77. const day2 = date2.getDate();
  78. // 返回格式化的字符串
  79. return `${year1}年${month1}月${day1}日入住 - ${year2}年${month2}月${day2}日离店`;
  80. },
  81. async getRoomOrder(){
  82. let Order = new Parse.Query('RoomOrder');
  83. Order.equalTo('company', company);
  84. Order.include('room');
  85. Order.equalTo('user', Parse.User.current().id);
  86. Order.include('shopStore');
  87. if (this.data.active == 0) {
  88. Order.equalTo('status', 100);
  89. }
  90. if (this.data.active == 1) {
  91. Order.equalTo('status', 200);
  92. }
  93. if (this.data.active == 2) {
  94. console.log(this.data.active);
  95. Order.equalTo('status', 800);
  96. }
  97. let room = await Order.find();
  98. let roomList = room.map(async item => {
  99. let roomItme = item.toJSON();
  100. roomItme.tiem = await this.formatDate2(roomItme.startTime.iso,roomItme.endTime.iso)
  101. return roomItme
  102. });
  103. let roomList2 = await Promise.all(roomList);
  104. this.setData({
  105. roomList:roomList2
  106. })
  107. console.log(this.data.roomList);
  108. },
  109. /**
  110. * 生命周期函数--监听页面初次渲染完成
  111. */
  112. onReady: function () {
  113. },
  114. /**
  115. * 生命周期函数--监听页面显示
  116. */
  117. onShow: function () {
  118. },
  119. /**
  120. * 生命周期函数--监听页面隐藏
  121. */
  122. onHide: function () {
  123. },
  124. /**
  125. * 生命周期函数--监听页面卸载
  126. */
  127. onUnload: function () {
  128. },
  129. /**
  130. * 页面相关事件处理函数--监听用户下拉动作
  131. */
  132. onPullDownRefresh: function () {
  133. },
  134. /**
  135. * 页面上拉触底事件的处理函数
  136. */
  137. onReachBottom: function () {
  138. },
  139. /**
  140. * 用户点击右上角分享
  141. */
  142. onShareAppMessage: function () {
  143. }
  144. })