index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. // nova-tourism/pages/my/my-order/order-detail/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. objectId:'',
  15. value:'',
  16. roomList:{},
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. const {
  23. objectId,
  24. value
  25. } = options;
  26. const Value = decodeURIComponent(value);
  27. this.setData({
  28. objectId,
  29. value:Value
  30. })
  31. console.log(this.data.value,this.data.objectId);
  32. const systemInfo = wx.getSystemInfoSync();
  33. const statusBarHeight = systemInfo.statusBarHeight || 0;
  34. const screenHeight = systemInfo.screenHeight || 0;
  35. const custom = wx.getMenuButtonBoundingClientRect();
  36. const customHeight = custom.height + 10 + 2 || 0;
  37. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  38. const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  39. this.setData({
  40. statusBarHeight,
  41. screenHeight,
  42. customHeight,
  43. bottomNavHeight,
  44. contentHeight
  45. });
  46. if(this.data.value=='民宿'){
  47. this.getRoomOrder()
  48. }
  49. },
  50. async getRoomOrder() {
  51. let Order = new Parse.Query('RoomOrder');
  52. Order.equalTo('company', company);
  53. Order.equalTo('objectId', this.data.objectId);
  54. Order.include('room');
  55. Order.equalTo('user', Parse.User.current().id);
  56. Order.include('shopStore');
  57. let room = await Order.find();
  58. let roomList = room.map(async item => {
  59. let roomItme = item.toJSON();
  60. roomItme.tiem = await this.formatDate2(roomItme.startTime.iso, roomItme.endTime.iso)
  61. roomItme.startTime = await this.formatDate(roomItme.startTime.iso)
  62. roomItme.endTime = await this.formatDate(roomItme.endTime.iso)
  63. return roomItme
  64. });
  65. let roomList2 = await Promise.all(roomList);
  66. this.setData({
  67. roomList: roomList2[0]
  68. })
  69. console.log(this.data.roomList);
  70. },
  71. formatDate2(date1, date2) {
  72. date1 = new Date(date1);
  73. date2 = new Date(date2);
  74. // 获取年份、月份和日期
  75. const year1 = date1.getFullYear();
  76. const month1 = date1.getMonth() + 1; // 月份从0开始,所以要加1
  77. const day1 = date1.getDate();
  78. const year2 = date2.getFullYear();
  79. const month2 = date2.getMonth() + 1; // 月份从0开始,所以要加1
  80. const day2 = date2.getDate();
  81. // 返回格式化的字符串
  82. return `${year1}年${month1}月${day1}日入住 - ${year2}年${month2}月${day2}日离店`;
  83. },
  84. formatDate(isoString) {
  85. const date = new Date(isoString);
  86. const year = date.getUTCFullYear();
  87. const month = String(date.getUTCMonth() + 1).padStart(2, '0'); // 月份从0开始
  88. const day = String(date.getUTCDate()).padStart(2, '0');
  89. const hours = String(date.getUTCHours()).padStart(2, '0');
  90. const minutes = String(date.getUTCMinutes()).padStart(2, '0');
  91. const seconds = String(date.getUTCSeconds()).padStart(2, '0');
  92. return `${year}-${month}-${day} 14:00:00`;
  93. },
  94. //复制
  95. copyOrderNum() {
  96. const orderNum = this.data.roomList.orderNum; // 获取订单编号
  97. if (orderNum) {
  98. wx.setClipboardData({
  99. data: orderNum,
  100. success: () => {
  101. wx.showToast({
  102. title: '复制成功',
  103. icon: 'success',
  104. duration: 2000
  105. });
  106. },
  107. fail: (err) => {
  108. console.error('复制失败:', err);
  109. wx.showToast({
  110. title: '复制失败',
  111. icon: 'none',
  112. duration: 2000
  113. });
  114. }
  115. });
  116. } else {
  117. wx.showToast({
  118. title: '没有订单编号',
  119. icon: 'none',
  120. duration: 2000
  121. });
  122. }
  123. },
  124. //续住
  125. gourl() {
  126. const start = new Date(this.data.roomList.endTime);
  127. const end = new Date(start); // 复制 start 日期
  128. end.setDate(start.getDate() + 1); // 将 end 设置为 start 的后一天
  129. // 构造要传递的信息
  130. const info = {
  131. objectId: this.data.roomList.room.objectId,
  132. date_start: start.toISOString(), // 转换为 ISO 格式字符串
  133. date_end: end.toISOString(), // 转换为 ISO 格式字符串
  134. };
  135. console.log('info', info);
  136. // 将信息转为查询字符串
  137. var queryString = Object.keys(info)
  138. .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(info[key])}`)
  139. .join('&');
  140. console.log(queryString);
  141. wx.navigateTo({
  142. url: `../../../homestay/homestay-order2/index?${queryString}`
  143. });
  144. },
  145. /**
  146. * 生命周期函数--监听页面初次渲染完成
  147. */
  148. onReady: function () {
  149. },
  150. /**
  151. * 生命周期函数--监听页面显示
  152. */
  153. onShow: function () {
  154. },
  155. /**
  156. * 生命周期函数--监听页面隐藏
  157. */
  158. onHide: function () {
  159. },
  160. /**
  161. * 生命周期函数--监听页面卸载
  162. */
  163. onUnload: function () {
  164. },
  165. /**
  166. * 页面相关事件处理函数--监听用户下拉动作
  167. */
  168. onPullDownRefresh: function () {
  169. },
  170. /**
  171. * 页面上拉触底事件的处理函数
  172. */
  173. onReachBottom: function () {
  174. },
  175. /**
  176. * 用户点击右上角分享
  177. */
  178. onShareAppMessage: function () {
  179. }
  180. })