orders.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import { api_studentOrderPage } from "../../api/login";
  2. // 获取应用实例
  3. const app = getApp<IAppOption>()
  4. // pages/orders/orders.ts
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. tabList: [
  11. {
  12. id: 0,
  13. label: "全部",
  14. },
  15. {
  16. id: 1,
  17. label: "待付款",
  18. },
  19. {
  20. id: 2,
  21. label: "待使用",
  22. },
  23. {
  24. id: 3,
  25. label: "已完成",
  26. },
  27. {
  28. id: 4,
  29. label: "已取消",
  30. }
  31. ],
  32. tabIdx: 0, // 当前选中的tab索引
  33. page: 1,
  34. rows: 10,
  35. recordList: [],
  36. maxPage: 1, // 总分页数
  37. },
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. onLoad() {
  42. this.getList()
  43. },
  44. /** 切换分类 */
  45. switchTab(e: { currentTarget: { dataset: { idx: any } } }) {
  46. const idx = e.currentTarget.dataset.idx;
  47. if (idx != this.data.tabIdx) {
  48. this.setData(
  49. {
  50. tabIdx: idx,
  51. page: 1,
  52. maxPage: 1,
  53. recordList: [],
  54. },
  55. () => {
  56. this.getList();
  57. }
  58. );
  59. }
  60. },
  61. async getList() {
  62. wx.showLoading({
  63. mask: true,
  64. title: "加载中...",
  65. });
  66. const currentPage = this.data.page,
  67. currentRow = this.data.rows,
  68. tabIdx = this.data.tabIdx;
  69. try {
  70. // @ApiModelProperty("订单状态 WAIT_PAY:待付款,WAIT_USE:待使用,SUCCESS:已完成,CLOSE:已取消")
  71. const { data } = await api_studentOrderPage({
  72. openId: app.globalData.userInfo?.liteOpenid,
  73. page: currentPage,
  74. rows: this.data.rows,
  75. wechatOrderStatus: tabIdx == 0 ? "" : tabIdx == 1 ? "WAIT_PAY" : tabIdx == 2 ? "WAIT_USE" : tabIdx == 3 ? "PAID" : tabIdx == 4 ? "CLOSED" : "",
  76. })
  77. if (data.code == 200) {
  78. const { rows, total } = data.data;
  79. rows.forEach((item: any) => {
  80. item.amount = this.formatPrice(item.paymentCashAmount, 'ALL')
  81. item.statusName = this.formatOrderStatus(item.wechatStatus)
  82. const studentPaymentOrderDetails = item.studentPaymentOrderDetails || [];
  83. studentPaymentOrderDetails.forEach((student: any) => {
  84. student.originalPrice = this.formatPrice(student.paymentCashAmount, 'ALL');
  85. student.typeName = this.formatPeriod(student.activationCodeInfo?.times || 1, student.activationCodeInfo?.type);
  86. })
  87. item.studentPaymentOrderDetails = studentPaymentOrderDetails
  88. });
  89. const newList = this.data.recordList.concat(rows);
  90. console.log(newList, "newList");
  91. this.setData(
  92. {
  93. recordList: newList,
  94. maxPage: Math.ceil(total / currentRow),
  95. },
  96. () => wx.hideLoading()
  97. );
  98. } else {
  99. wx.hideLoading();
  100. }
  101. } catch(e) {
  102. console.log(e, 'e')
  103. wx.hideLoading()
  104. }
  105. },
  106. // 格式化中文
  107. formatOrderStatus(status: string) {
  108. // 订单状态 WAIT_PAY:待付款, WAIT_USE:待使用, SUCCESS:已完成, CLOSE:已取消
  109. const template: any = {
  110. WAIT_PAY: '等待付款',
  111. WAIT_USE: '等待使用',
  112. SUCCESS: '交易完成',
  113. CLOSED: '交易取消',
  114. REFUNDED: '退款成功'
  115. }
  116. return template[status]
  117. },
  118. // 格式化价格
  119. formatPrice(price: number, type?: string) {
  120. const amountStr = price.toFixed(2)
  121. const [integerPart, decimalPart] = amountStr.split('.');
  122. if(type === 'ALL') {
  123. return amountStr
  124. }
  125. return {
  126. integerPart,
  127. decimalPart
  128. }
  129. },
  130. // 格式化类型
  131. formatPeriod(num: number, type: string) {
  132. if(!num || !type) {
  133. return ''
  134. }
  135. const template: any = {
  136. DAY: "天卡",
  137. MONTH: "月卡",
  138. YEAR: "年卡"
  139. }
  140. if(type === "YEAR" && num >= 99) {
  141. return '终生卡'
  142. }
  143. return num + template[type]
  144. },
  145. /** 加载更多 */
  146. loadMore() {
  147. const currentPage = this.data.page;
  148. if (this.data.page >= this.data.maxPage) {
  149. wx.showToast({
  150. title: "没有更多数据了",
  151. icon: "none",
  152. duration: 1000,
  153. });
  154. } else {
  155. this.setData(
  156. {
  157. page: currentPage + 1,
  158. },
  159. () => {
  160. this.getList();
  161. }
  162. );
  163. }
  164. },
  165. onPay(e: any) {
  166. const { dataset } = e.currentTarget
  167. const item: any = this.data.recordList.find((item: any) => item.id === dataset.id)
  168. console.log(dataset, item, 'item')
  169. if(item) {
  170. const studentPaymentOrderDetails = item.studentPaymentOrderDetails[0]
  171. const prices: any = this.formatPrice(item.paymentCashAmount)
  172. const params = {
  173. // buyNum: "0",
  174. decimalPart: prices.decimalPart,
  175. // id: "1856596669912584193",
  176. integerPart: prices.integerPart,
  177. userPaymentOrderDetailId: studentPaymentOrderDetails.userPaymentOrderDetailId,
  178. name: studentPaymentOrderDetails.goodsName,
  179. num: studentPaymentOrderDetails.goodsNum,
  180. originalPrice: studentPaymentOrderDetails.originalPrice,
  181. period: studentPaymentOrderDetails.activationCodeInfo.type,
  182. pic: studentPaymentOrderDetails.goodsUrl,
  183. salePrice: item.paymentCashAmount,
  184. // shopId: "1815717514476302337",
  185. orderNo: item.orderNo,
  186. wechatStatus: item.wechatStatus,
  187. // stockNum: "10",
  188. typeName: studentPaymentOrderDetails.typeName
  189. }
  190. let info = JSON.stringify(params);
  191. console.log(params, "params")
  192. info = encodeURIComponent(info);
  193. wx.navigateTo({
  194. url: `../orders/order-detail?orderInfo=${info}`,
  195. })
  196. }
  197. },
  198. onOne() {
  199. wx.redirectTo({
  200. url: '../index/index',
  201. })
  202. },
  203. onDetail(e: any) {
  204. const { dataset } = e.currentTarget
  205. console.log(e)
  206. wx.navigateTo({
  207. url: '../orders/order-result?orderNo=' + dataset.orderno
  208. })
  209. },
  210. })