orders.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import { api_studentOrderPage } from "../../api/login";
  2. // pages/orders/orders.ts
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. tabList: [
  9. {
  10. id: 0,
  11. label: "全部",
  12. },
  13. {
  14. id: 1,
  15. label: "待付款",
  16. },
  17. {
  18. id: 2,
  19. label: "待使用",
  20. },
  21. {
  22. id: 3,
  23. label: "已完成",
  24. },
  25. {
  26. id: 4,
  27. label: "已取消",
  28. }
  29. ],
  30. tabIdx: 0, // 当前选中的tab索引
  31. page: 1,
  32. rows: 20,
  33. recordList: [],
  34. maxPage: 1, // 总分页数
  35. },
  36. /**
  37. * 生命周期函数--监听页面加载
  38. */
  39. onLoad() {
  40. this.getList()
  41. },
  42. /** 切换分类 */
  43. switchTab(e: { currentTarget: { dataset: { idx: any } } }) {
  44. const idx = e.currentTarget.dataset.idx;
  45. if (idx != this.data.tabIdx) {
  46. this.setData(
  47. {
  48. tabIdx: idx,
  49. page: 1,
  50. maxPage: 1,
  51. recordList: [],
  52. },
  53. () => {
  54. this.getList();
  55. }
  56. );
  57. }
  58. },
  59. async getList() {
  60. wx.showLoading({
  61. mask: true,
  62. title: "加载中...",
  63. });
  64. const currentPage = this.data.page,
  65. currentRow = this.data.rows,
  66. tabIdx = this.data.tabIdx;
  67. try {
  68. // @ApiModelProperty("订单状态 WAIT_PAY:待付款,WAIT_USE:待使用,SUCCESS:已完成,CLOSE:已取消")
  69. const { data } = await api_studentOrderPage({
  70. page: currentPage,
  71. rows: this.data.rows,
  72. wechatOrderStatus: tabIdx == 0 ? "" : tabIdx == 1 ? "WAIT_PAY" : tabIdx == 2 ? "WAIT_USE" : tabIdx == 3 ? "SUCCESS" : tabIdx == 4 ? "CLOSE" : "",
  73. })
  74. if (data.code == 200) {
  75. const { rows, total } = data.data;
  76. console.log(rows, 'rows')
  77. rows.forEach((item: any) => {
  78. // item.purchaseStatusDesc = item.purchaseStatus == "WAIT_PAY" ? "待支付" : item.purchaseStatus == "PAID" ? "已付款" : item.purchaseStatus == "CLOSE" ? "已关闭" : "";
  79. // // purchaseType;
  80. // item.purchaseTypeStr = this.formatUnitTimer(item.purchaseType);
  81. // item.showPrice = item.purchasePrice;
  82. // if (item.purchasePrice !== null) {
  83. // item.showPrice = Number(item.purchasePrice).toFixed(2);
  84. // }
  85. });
  86. console.log(rows);
  87. const newList = this.data.recordList.concat(rows);
  88. this.setData(
  89. {
  90. recordList: newList,
  91. maxPage: Math.ceil(total / currentRow),
  92. },
  93. () => wx.hideLoading()
  94. );
  95. } else {
  96. wx.hideLoading();
  97. }
  98. } catch {
  99. wx.hideLoading()
  100. }
  101. },
  102. /** 加载更多 */
  103. loadMore() {
  104. wx.showLoading({
  105. mask: true,
  106. title: "加载中...",
  107. });
  108. setTimeout(() => {
  109. wx.hideLoading()
  110. }, 3000);
  111. },
  112. /**
  113. * 生命周期函数--监听页面初次渲染完成
  114. */
  115. onReady() {
  116. },
  117. /**
  118. * 生命周期函数--监听页面显示
  119. */
  120. onShow() {
  121. },
  122. /**
  123. * 生命周期函数--监听页面隐藏
  124. */
  125. onHide() {
  126. },
  127. /**
  128. * 生命周期函数--监听页面卸载
  129. */
  130. onUnload() {
  131. },
  132. /**
  133. * 页面相关事件处理函数--监听用户下拉动作
  134. */
  135. onPullDownRefresh() {
  136. },
  137. /**
  138. * 页面上拉触底事件的处理函数
  139. */
  140. onReachBottom() {
  141. },
  142. /**
  143. * 用户点击右上角分享
  144. */
  145. onShareAppMessage() {
  146. }
  147. })