orders.ts 5.9 KB

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