orders.ts 5.9 KB

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