index.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. // nova-tourism/pages/my/my-order/order-detail/index.js
  2. let Parse = getApp().Parse;
  3. const company = getApp().globalData.company
  4. const dateF = require("../../../../../utils/date")
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. statusBarHeight: 0,
  11. screenHeight: 0,
  12. customHeight: 0,
  13. bottomNavHeight: 0,
  14. contentHeight: 0,
  15. objectId: '',
  16. value: '',
  17. roomList: {},
  18. isQr: false, //二维码弹框
  19. statusMap: {
  20. 100: '未入住',
  21. 200: '已入住',
  22. 300: '续住',
  23. 400: '已退房',
  24. 500: '申请退款',
  25. 601: '退款审核通过',
  26. 602: '退款已驳回',
  27. 700: '退款成功',
  28. 800: '已完成',
  29. 101: '已取消支付',
  30. 102: '已完申请退房成',
  31. 103: '退房成功',
  32. 104: '退房被驳回',
  33. 105: '未支付',
  34. },
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad: function (options) {
  40. const {
  41. objectId,
  42. value
  43. } = options;
  44. const Value = decodeURIComponent(value);
  45. this.setData({
  46. objectId,
  47. value: Value
  48. })
  49. console.log(this.data.value, this.data.objectId);
  50. const systemInfo = wx.getSystemInfoSync();
  51. const statusBarHeight = systemInfo.statusBarHeight || 0;
  52. const screenHeight = systemInfo.screenHeight || 0;
  53. const custom = wx.getMenuButtonBoundingClientRect();
  54. const customHeight = custom.height + 10 + 2 || 0;
  55. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  56. const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  57. this.setData({
  58. statusBarHeight,
  59. screenHeight,
  60. customHeight,
  61. bottomNavHeight,
  62. contentHeight
  63. });
  64. if (this.data.value == '民宿') {
  65. this.getRoomOrder()
  66. }
  67. },
  68. async getRoomOrder() {
  69. let Order = new Parse.Query('RoomOrder');
  70. Order.equalTo('company', company);
  71. Order.equalTo('objectId', this.data.objectId);
  72. Order.include('room');
  73. Order.equalTo('user', Parse.User.current().id);
  74. Order.include('shopStore');
  75. let room = await Order.find();
  76. let roomList = room.map(async item => {
  77. let roomItme = item.toJSON();
  78. roomItme.tiem = await this.formatDate2(roomItme.startTime.iso, roomItme.endTime.iso)
  79. roomItme.startTime = await this.formatDate(roomItme.startTime.iso)
  80. roomItme.endTime = await this.formatDate(roomItme.endTime.iso)
  81. return roomItme
  82. });
  83. let roomList2 = await Promise.all(roomList);
  84. this.setData({
  85. roomList: roomList2[0]
  86. })
  87. console.log(this.data.roomList);
  88. },
  89. formatDate2(date1, date2) {
  90. date1 = new Date(date1);
  91. date2 = new Date(date2);
  92. // 获取年份、月份和日期
  93. const year1 = date1.getFullYear();
  94. const month1 = date1.getMonth() + 1; // 月份从0开始,所以要加1
  95. const day1 = date1.getDate();
  96. const year2 = date2.getFullYear();
  97. const month2 = date2.getMonth() + 1; // 月份从0开始,所以要加1
  98. const day2 = date2.getDate();
  99. // 返回格式化的字符串
  100. return `${year1}年${month1}月${day1}日入住 - ${year2}年${month2}月${day2}日离店`;
  101. },
  102. formatDate(isoString) {
  103. const date = new Date(isoString);
  104. const year = date.getUTCFullYear();
  105. const month = String(date.getUTCMonth() + 1).padStart(2, '0'); // 月份从0开始
  106. const day = String(date.getUTCDate()).padStart(2, '0');
  107. const hours = String(date.getUTCHours()).padStart(2, '0');
  108. const minutes = String(date.getUTCMinutes()).padStart(2, '0');
  109. const seconds = String(date.getUTCSeconds()).padStart(2, '0');
  110. return `${year}-${month}-${day} 14:00:00`;
  111. },
  112. //复制
  113. copyOrderNum() {
  114. const orderNum = this.data.roomList.orderNum; // 获取订单编号
  115. if (orderNum) {
  116. wx.setClipboardData({
  117. data: orderNum,
  118. success: () => {
  119. wx.showToast({
  120. title: '复制成功',
  121. icon: 'success',
  122. duration: 2000
  123. });
  124. },
  125. fail: (err) => {
  126. console.error('复制失败:', err);
  127. wx.showToast({
  128. title: '复制失败',
  129. icon: 'none',
  130. duration: 2000
  131. });
  132. }
  133. });
  134. } else {
  135. wx.showToast({
  136. title: '没有订单编号',
  137. icon: 'none',
  138. duration: 2000
  139. });
  140. }
  141. },
  142. //续住
  143. gourl() {
  144. const start = new Date();
  145. const end = new Date(start); // 复制 start 日期
  146. end.setDate(start.getDate() + 1); // 将 end 设置为 start 的后一天
  147. // 构造要传递的信息
  148. const info = {
  149. objectId: this.data.roomList.room.objectId,
  150. date_start: dateF.formatTime('YYYY-mm-dd', start),
  151. date_end: dateF.formatTime('YYYY-mm-dd', end),
  152. };
  153. console.log('info', info);
  154. wx.navigateTo({
  155. url: `../../../homestay/homestay-order2/index?objectId=${info.objectId}&date_start=${info.date_start}&date_end=${info.date_end}`
  156. });
  157. },
  158. /**展开订单二维码 */
  159. async openQr() {
  160. let {
  161. qr
  162. } = this.data
  163. if (qr) {
  164. this.setData({
  165. isQr: true
  166. })
  167. return
  168. }
  169. let that = this
  170. let {
  171. roomList
  172. } = this.data
  173. let url = 'https://server.fmode.cn/api/common/qrcode'
  174. wx.request({
  175. url: url,
  176. data: {
  177. qrCode: roomList?.objectId || '',
  178. darkColor: "#000000",
  179. lightColor: "#ffffff"
  180. },
  181. method: 'GET',
  182. header: {
  183. 'content-type': 'application/json'
  184. },
  185. success: function (res) {
  186. let qr = res.data.data
  187. that.setData({
  188. qr,
  189. isQr: true,
  190. })
  191. },
  192. fail: function () {
  193. wx.showToast({
  194. title: '请求二维码失败,请稍后再试',
  195. })
  196. }
  197. })
  198. },
  199. closeQr() {
  200. this.setData({
  201. isQr: false
  202. })
  203. },
  204. /**
  205. * 生命周期函数--监听页面初次渲染完成
  206. */
  207. onReady: function () {
  208. },
  209. /**
  210. * 生命周期函数--监听页面显示
  211. */
  212. onShow: function () {
  213. },
  214. /**
  215. * 生命周期函数--监听页面隐藏
  216. */
  217. onHide: function () {
  218. },
  219. /**
  220. * 生命周期函数--监听页面卸载
  221. */
  222. onUnload: function () {
  223. },
  224. /**
  225. * 页面相关事件处理函数--监听用户下拉动作
  226. */
  227. onPullDownRefresh: function () {
  228. },
  229. /**
  230. * 页面上拉触底事件的处理函数
  231. */
  232. onReachBottom: function () {
  233. },
  234. /**
  235. * 用户点击右上角分享
  236. */
  237. onShareAppMessage: function () {
  238. }
  239. })