orders.ts 6.1 KB

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