orders.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. import { api_studentOrderPage } from "../../api/login";
  2. // 获取应用实例
  3. const app = getApp<IAppOption>()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. tabList: [
  10. {
  11. id: 0,
  12. label: "全部",
  13. },
  14. {
  15. id: 1,
  16. label: "待付款",
  17. },
  18. {
  19. id: 2,
  20. label: "待使用",
  21. },
  22. {
  23. id: 3,
  24. label: "已完成",
  25. },
  26. {
  27. id: 4,
  28. label: "已取消",
  29. },
  30. {
  31. id: 5,
  32. label: "售后",
  33. },
  34. // {
  35. // id: 6,
  36. // label: "已退款",
  37. // },
  38. ],
  39. tabIdx: 0, // 当前选中的tab索引
  40. page: 1,
  41. rows: 10,
  42. recordList: [],
  43. maxPage: 1, // 总分页数
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad() {
  49. this.getList()
  50. },
  51. /** 切换分类 */
  52. switchTab(e: { currentTarget: { dataset: { idx: any } } }) {
  53. const idx = e.currentTarget.dataset.idx;
  54. if (idx != this.data.tabIdx) {
  55. this.setData(
  56. {
  57. tabIdx: idx,
  58. page: 1,
  59. maxPage: 1,
  60. recordList: [],
  61. },
  62. () => {
  63. this.getList();
  64. }
  65. );
  66. }
  67. },
  68. async getList() {
  69. wx.showLoading({
  70. mask: true,
  71. title: "加载中...",
  72. });
  73. const currentPage = this.data.page,
  74. currentRow = this.data.rows,
  75. tabIdx = this.data.tabIdx;
  76. try {
  77. // @ApiModelProperty("订单状态 WAIT_PAY:待付款,WAIT_USE:待使用,SUCCESS:已完成,CLOSE:已取消")
  78. const { data } = await api_studentOrderPage({
  79. openId: app.globalData.userInfo?.liteOpenid,
  80. page: currentPage,
  81. rows: this.data.rows,
  82. wechatOrderStatus: tabIdx == 0 ? "" : tabIdx == 1 ? "WAIT_PAY" : tabIdx == 2 ? "WAIT_USE" : tabIdx == 3 ? "PAID" : tabIdx == 4 ? "CLOSED" : tabIdx == 5 ? 'REFUNDED' : "",
  83. })
  84. if (data.code == 200) {
  85. const { rows, total } = data.data;
  86. rows.forEach((item: any) => {
  87. item.amount = this.formatPrice(item.paymentCashAmount, 'ALL')
  88. item.statusName = this.formatOrderStatus(item.wechatStatus)
  89. const studentPaymentOrderDetails = item.studentPaymentOrderDetails || [];
  90. studentPaymentOrderDetails.forEach((student: any) => {
  91. student.originalPrice = this.formatPrice(student.paymentCashAmount, 'ALL');
  92. student.typeName = this.formatPeriod(student.activationCodeInfo?.times || 1, student.activationCodeInfo?.type);
  93. })
  94. item.studentPaymentOrderDetails = studentPaymentOrderDetails
  95. });
  96. const newList = this.data.recordList.concat(rows);
  97. console.log(newList, "newList");
  98. this.setData(
  99. {
  100. recordList: newList,
  101. maxPage: Math.ceil(total / currentRow),
  102. },
  103. () => wx.hideLoading()
  104. );
  105. } else {
  106. wx.hideLoading();
  107. }
  108. } catch(e) {
  109. console.log(e, 'e')
  110. wx.hideLoading()
  111. }
  112. },
  113. // 格式化中文
  114. formatOrderStatus(status: string) {
  115. // 订单状态 WAIT_PAY:待付款, WAIT_USE:待使用, SUCCESS:已完成, CLOSE:已取消
  116. const template: any = {
  117. WAIT_PAY: '等待付款',
  118. WAIT_USE: '等待使用',
  119. PAID: '交易完成',
  120. CLOSED: '交易取消',
  121. REFUNDING: '售后中',
  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. wx.navigateTo({
  214. url: '../orders/order-result?orderNo=' + dataset.orderno
  215. })
  216. },
  217. })