index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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(item => {
  99. let roomItme = item.toJSON();
  100. let startTime = roomItme.startTime
  101. let endTime = roomItme.endTime
  102. roomItme.tiem = this.formatDate2(startTime,endTime)
  103. return roomItme
  104. });
  105. this.setData({
  106. roomList
  107. })
  108. console.log(this.data.roomList);
  109. },
  110. /**
  111. * 生命周期函数--监听页面初次渲染完成
  112. */
  113. onReady: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面显示
  117. */
  118. onShow: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面隐藏
  122. */
  123. onHide: function () {
  124. },
  125. /**
  126. * 生命周期函数--监听页面卸载
  127. */
  128. onUnload: function () {
  129. },
  130. /**
  131. * 页面相关事件处理函数--监听用户下拉动作
  132. */
  133. onPullDownRefresh: function () {
  134. },
  135. /**
  136. * 页面上拉触底事件的处理函数
  137. */
  138. onReachBottom: function () {
  139. },
  140. /**
  141. * 用户点击右上角分享
  142. */
  143. onShareAppMessage: function () {
  144. }
  145. })