index.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. const app = getApp();
  2. const Parse = getApp().Parse;
  3. const company = getApp().globalData.company
  4. const dateF = require('../../../../../utils/date')
  5. let navigationBarHeight = getApp().globalData.statusBarHeight + 44;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. active: 0,
  12. navigationBarHeight,
  13. orders: []
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: async function (options) {
  19. this.setData({
  20. activeColor:getApp().globalData.activeColor || '#229293'
  21. })
  22. let orders = await this.getRoomOrders()
  23. console.log(orders);
  24. // let shopOrders = this.getShopOrders()
  25. // let roomOrders = this.getRoomOrders()
  26. // let orders = shopOrders.concat(roomOrders).sort((a,b)=> {return a.updatedAt - b.updatedAt})
  27. this.setData({
  28. orders
  29. })
  30. },
  31. async onChange(event) {
  32. let active = event.detail.name;
  33. let orders;
  34. if(active == 0){
  35. let shopOrders = await this.getShopOrders()
  36. let roomOrders = await this.getRoomOrders()
  37. orders = shopOrders.concat(roomOrders).sort((a,b)=> {return a.updatedAt - b.updatedAt})
  38. }
  39. if(active == 1){
  40. orders = await this.getShopOrders('meal')
  41. }
  42. if(active == 2){
  43. orders = await this.getShopOrders('shop')
  44. }
  45. if(active == 3){
  46. orders = await this.getRoomOrders()
  47. console.log(orders);
  48. }
  49. this.setData({
  50. active,
  51. orders
  52. })
  53. console.log(this.data.orders);
  54. },
  55. async getRoomOrders() {
  56. let userId = Parse.User.current().id;
  57. let Order1 = new Parse.Query('RoomOrder')
  58. let Order2 = new Parse.Query('RoomOrder')
  59. let Order3 = new Parse.Query('RoomOrder')
  60. let Order4 = new Parse.Query('RoomOrder')
  61. Order1.equalTo("status", 500)
  62. Order2.equalTo("status", 601)
  63. Order3.equalTo("status", 602)
  64. Order4.equalTo("status", 700)
  65. console.log(Order1,Order2,Order3,Order4);
  66. let mainQuery = Parse.Query.or(Order1,Order2,Order3,Order4);
  67. console.log(mainQuery);
  68. mainQuery.equalTo('company', company)
  69. mainQuery.equalTo('user', userId)
  70. mainQuery.include('room')
  71. mainQuery.include('shopStore')
  72. console.log(mainQuery);
  73. let res = await mainQuery.find()
  74. console.log(res);
  75. let list = []
  76. if(res&&res.length){
  77. res.forEach(item => {
  78. let activitys = item.toJSON()
  79. activitys.orderTime = dateF.formatTime("mm-dd", activitys.startTime.iso)
  80. activitys.Time = dateF.formatTime("mm-dd", activitys.endTime.iso)
  81. activitys.startTime = dateF.formatTime("YYYY/mm/dd", activitys.startTime.iso)
  82. activitys.endTime = dateF.formatTime("YYYY/mm/dd", activitys.endTime.iso)
  83. //计算天数
  84. activitys.day = parseInt((new Date(activitys.endTime.replace(/-/g, '/')).getTime() - new Date(activitys.startTime.replace(/-/g, '/')).getTime()) / (1000 * 60 * 60 * 24));
  85. list.push(activitys)
  86. })
  87. }
  88. console.log(list);
  89. return list
  90. },
  91. async getShopOrders() {
  92. let userId = Parse.User.current().id;
  93. let Order1 = new Parse.Query('ShopOrder')
  94. let Order2 = new Parse.Query('ShopOrder')
  95. let Order3 = new Parse.Query('ShopOrder')
  96. let Order4 = new Parse.Query('ShopOrder')
  97. Order1.equalTo("status", 500)
  98. Order2.equalTo("status", 601)
  99. Order3.equalTo("status", 602)
  100. Order4.equalTo("status", 700)
  101. console.log(Order1,Order2,Order3,Order4);
  102. let mainQuery = Parse.Query.or(Order1,Order2,Order3,Order4);
  103. console.log(mainQuery);
  104. mainQuery.equalTo('company', company)
  105. mainQuery.equalTo('user', userId)
  106. mainQuery.include('shopStore')
  107. console.log(mainQuery);
  108. let res = await mainQuery.find()
  109. let list = []
  110. res.forEach(item => {
  111. let activitys = item.toJSON()
  112. activitys.orderTime = dateF.formatTime("mm-dd", activitys.startTime.iso)
  113. activitys.Time = dateF.formatTime("mm-dd", activitys.endTime.iso)
  114. activitys.a = dateF.formatTime("YYYY-mm-dd HH:MM:SS", activitys.startTime.iso)
  115. activitys.e = dateF.formatTime("YYYY-mm-dd HH:MM:SS", activitys.endTime.iso)
  116. //计算天数
  117. activitys.day = parseInt((new Date(activitys.e.replace(/-/g, '/')).getTime() - new Date(activitys.a.replace(/-/g, '/')).getTime()) / (1000 * 60 * 60 * 24));
  118. list.push(activitys)
  119. })
  120. return list;
  121. },
  122. phone() {
  123. let phone = this.data.shopOrder.shopStore.mobile
  124. console.log(phone);
  125. wx.makePhoneCall({
  126. phoneNumber: phone
  127. })
  128. },
  129. /**
  130. * 生命周期函数--监听页面初次渲染完成
  131. */
  132. onReady: function () {
  133. },
  134. /**
  135. * 生命周期函数--监听页面显示
  136. */
  137. onShow: function () {
  138. },
  139. /**
  140. * 生命周期函数--监听页面隐藏
  141. */
  142. onHide: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面卸载
  146. */
  147. onUnload: function () {
  148. },
  149. /**
  150. * 页面相关事件处理函数--监听用户下拉动作
  151. */
  152. onPullDownRefresh: function () {
  153. },
  154. /**
  155. * 页面上拉触底事件的处理函数
  156. */
  157. onReachBottom: function () {
  158. },
  159. /**
  160. * 用户点击右上角分享
  161. */
  162. onShareAppMessage: function () {
  163. }
  164. })