personorder.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. // pages/personorder/personorder.js
  2. const app = getApp()
  3. import orderApi from '../../api/order'
  4. import storeApi from '../../api/store'
  5. import productApi from '../../api/product'
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. activeTab: 0,
  12. orderHeight: 0,
  13. tabs: [],
  14. orderList: [],
  15. pageNo: 1,
  16. loadingEnd: false,
  17. tabs: [{
  18. title: '全部'
  19. },
  20. {
  21. title: '代消费'
  22. },
  23. {
  24. title: '待评价'
  25. },
  26. {
  27. title: '已完成'
  28. },
  29. ]
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: async function () {
  35. console.log(this)
  36. const isAuth = await app.isAuth()
  37. if (!isAuth) {
  38. wx.redirectTo({
  39. url: '/pages/prompt/prompt?page=' + this.route,
  40. })
  41. }
  42. this.getOrderHeight();
  43. },
  44. //动态生成产品的父盒子高度
  45. getOrderHeight: function () {
  46. var h = wx.getSystemInfoSync().windowHeight * (750 / wx.getSystemInfoSync().windowWidth);
  47. var orderHeight = h - 95;
  48. this.setData({
  49. orderHeight
  50. })
  51. },
  52. getOrderList: async function (params) {
  53. var pageNo = this.data.pageNo;
  54. var orderList = await orderApi.getAllOrderList(pageNo, 3);
  55. var list = await this.handelOrderList(orderList.list);
  56. //代消费订单
  57. var writeOffOrderList = [];
  58. //待评价订单
  59. var commentOffOrderList = [];
  60. //已完成订单
  61. var finishOrderList = [];
  62. list.forEach(function (item, u, array) {
  63. if (item.status == 2 && item.writeOffStatus == 1) {
  64. writeOffOrderList.push(item)
  65. }
  66. if (item.status == 2 && item.writeOffStatus == 2) {
  67. finishOrderList.push(item)
  68. }
  69. })
  70. var tabs = this.data.tabs;
  71. tabs[0].list = list;
  72. },
  73. // 获取全部列表
  74. getAllOrderList: async function () {
  75. const self = this
  76. var pageNo = this.data.pageNo;
  77. // 获取全部订单
  78. var orderList = await orderApi.getAllOrderList(pageNo, 4);
  79. var list = await this.handelOrderList(orderList.list);
  80. var tabs = this.data.tabs;
  81. tabs[0].list = list;
  82. this.setData({
  83. tabs
  84. })
  85. // return list;
  86. },
  87. // 获取代消费列表
  88. getwriteOffOrderList: async function () {
  89. const self = this
  90. var pageNo = this.data.pageNo;
  91. // 获取代消费订单
  92. var orderList = await orderApi.getOrderList(pageNo, 4, 2, 1);
  93. var list = await this.handelOrderList(orderList.list);
  94. var tabs = this.data.tabs;
  95. tabs[1].list = list;
  96. this.setData({
  97. tabs
  98. })
  99. // return list;
  100. },
  101. // 获取待评价列表
  102. getcommentOffOrderList: async function () {
  103. const self = this
  104. var pageNo = this.data.pageNo;
  105. // 获取代消费订单
  106. var orderList = await orderApi.getOrderList(pageNo, 4, 2, 1);
  107. var list = await this.handelOrderList(orderList.list);
  108. var tabs = this.data.tabs;
  109. tabs[2].list = list;
  110. this.setData({
  111. tabs
  112. })
  113. // return list;
  114. },
  115. // 获取已经完成的列表
  116. getfinishOrderList: async function (params) {
  117. const self = this
  118. var pageNo = this.data.pageNo;
  119. // 获取代消费订单
  120. var orderList = await orderApi.getOrderList(pageNo, 4, 2, 1);
  121. var list = await this.handelOrderList(orderList.list);
  122. var tabs = this.data.tabs;
  123. tabs[3].list = list;
  124. this.setData({
  125. tabs
  126. })
  127. // return list;
  128. },
  129. onTabClick(e) {
  130. const index = e.detail.index
  131. this.setData({
  132. activeTab: index
  133. })
  134. },
  135. onChange(e) {
  136. const index = e.detail.index
  137. this.setData({
  138. activeTab: index
  139. })
  140. },
  141. handleClick(e) {
  142. },
  143. handelOrderList: async function (list) {
  144. list.forEach(async function (item, i, array) {
  145. let store = await storeApi.getStoreById(item.storeId);
  146. let product = await productApi.getProductById(item.productId);
  147. item.address = store.info.address;
  148. item.productName = product.info.productName;
  149. item.productImg = product.info.productImg;
  150. })
  151. return list
  152. },
  153. /**
  154. * 生命周期函数--监听页面初次渲染完成
  155. */
  156. onReady: async function () {
  157. await this.getOrderList()
  158. },
  159. /**
  160. * 生命周期函数--监听页面显示
  161. */
  162. onShow: function () {
  163. },
  164. /**
  165. * 生命周期函数--监听页面隐藏
  166. */
  167. onHide: function () {
  168. },
  169. /**
  170. * 生命周期函数--监听页面卸载
  171. */
  172. onUnload: function () {
  173. },
  174. /**
  175. * 页面相关事件处理函数--监听用户下拉动作
  176. */
  177. onPullDownRefresh: function () {
  178. },
  179. /**
  180. * 页面上拉触底事件的处理函数
  181. */
  182. onReachBottom: function () {
  183. },
  184. /**
  185. * 用户点击右上角分享
  186. */
  187. onShareAppMessage: function () {
  188. },
  189. gotoComment: function (e) {
  190. wx.navigateTo({
  191. url: '../commentinfo/commentinfo',
  192. })
  193. }
  194. })