orders.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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: 10,
  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 ? "CLOSED" : "",
  73. })
  74. if (data.code == 200) {
  75. const { rows, total } = data.data;
  76. rows.forEach((item: any) => {
  77. item.amount = this.formatPrice(item.paymentCashAmount, 'ALL')
  78. item.statusName = this.formatOrderStatus(item.wechatStatus)
  79. const studentPaymentOrderDetails = item.studentPaymentOrderDetails || [];
  80. console.log(studentPaymentOrderDetails, 'studentPaymentOrderDetails')
  81. studentPaymentOrderDetails.forEach((student: any) => {
  82. student.originalPrice = this.formatPrice(student.paymentCashAmount, 'ALL');
  83. student.typeName = this.formatPeriod(student.goodsNum, student.activationCodeInfo?.type);
  84. })
  85. item.studentPaymentOrderDetails = studentPaymentOrderDetails
  86. });
  87. const newList = this.data.recordList.concat(rows);
  88. console.log(newList, "newList");
  89. this.setData(
  90. {
  91. recordList: newList,
  92. maxPage: Math.ceil(total / currentRow),
  93. },
  94. () => wx.hideLoading()
  95. );
  96. } else {
  97. wx.hideLoading();
  98. }
  99. } catch(e) {
  100. console.log(e, 'e')
  101. wx.hideLoading()
  102. }
  103. },
  104. // 格式化中文
  105. formatOrderStatus(status: string) {
  106. // 订单状态 WAIT_PAY:待付款, WAIT_USE:待使用, SUCCESS:已完成, CLOSE:已取消
  107. const template: any = {
  108. WAIT_PAY: '等待付款',
  109. WAIT_USE: '等待使用',
  110. SUCCESS: '交易完成',
  111. CLOSED: '交易取消',
  112. }
  113. return template[status]
  114. },
  115. // 格式化价格
  116. formatPrice(price: number, type?: string) {
  117. const amountStr = price.toFixed(2)
  118. const [integerPart, decimalPart] = amountStr.split('.');
  119. if(type === 'ALL') {
  120. return amountStr
  121. }
  122. return {
  123. integerPart,
  124. decimalPart
  125. }
  126. },
  127. // 格式化类型
  128. formatPeriod(num: number, type: string) {
  129. if(!num || !type) {
  130. return ''
  131. }
  132. const template: any = {
  133. DAY: "天卡",
  134. MONTH: "月卡",
  135. YEAR: "年卡"
  136. }
  137. if(type === "YEAR" && num >= 99) {
  138. return '终生卡'
  139. }
  140. return num + template[type]
  141. },
  142. /** 加载更多 */
  143. loadMore() {
  144. const currentPage = this.data.page;
  145. if (this.data.page >= this.data.maxPage) {
  146. wx.showToast({
  147. title: "没有更多数据了",
  148. icon: "none",
  149. duration: 1000,
  150. });
  151. } else {
  152. this.setData(
  153. {
  154. page: currentPage + 1,
  155. },
  156. () => {
  157. this.getList();
  158. }
  159. );
  160. }
  161. },
  162. onPay(e: any) {
  163. console.log(e)
  164. const { currentTarget } = e
  165. const item = this.data.recordList.find((item: any) => item.id === e.currentTarget)
  166. },
  167. onOne(e: any) {
  168. console.log(e)
  169. wx.redirectTo({
  170. url: '../index/index',
  171. })
  172. },
  173. onDetail(e: any) {
  174. const { dataset } = e.currentTarget
  175. console.log(e)
  176. wx.navigateTo({
  177. url: '../orders/order-result?orderNo=' + dataset.orderno
  178. })
  179. },
  180. })