index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // pages/usermyorder/index.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. frameStyle: { useTop: true, name: '订单管理', leftArrow: true, useBar: false },
  9. list: [],
  10. userInfo: {}
  11. },
  12. async search() {
  13. const openid = this.data.userInfo?.openid;
  14. if (!openid) {
  15. wx.showToast({
  16. title: '用户未登录',
  17. icon: 'error'
  18. })
  19. return;
  20. }
  21. const res = await app.$get(`/newCourt/api/payOrder`, { openid })
  22. if (app.$checkRes(res)) {
  23. let list = res.data;
  24. list = list.map(i => ({ ...i, statusZh: this.getStatusZh(i.status) }))
  25. this.setData({ list })
  26. }
  27. },
  28. // 付款
  29. async toPay(e) { },
  30. // 退款
  31. async toRefund(e) {
  32. const id = e.target.dataset?.id;
  33. const res = await app.$post('/newCourt/api/payOrder/toRefund', { id })
  34. if (app.$checkRes(res)) {
  35. wx.showToast({
  36. title: '退款成功',
  37. })
  38. this.search();
  39. }
  40. },
  41. getStatusZh(status) {
  42. let word = "未知"
  43. switch (status) {
  44. case '0':
  45. word = "未支付"
  46. break;
  47. case '1':
  48. word = "支付成功"
  49. break;
  50. case '-1':
  51. word = "支付失败"
  52. break;
  53. case '-2':
  54. word = "申请退款"
  55. break;
  56. case '-3':
  57. word = "已退款"
  58. break;
  59. default:
  60. break;
  61. }
  62. return word;
  63. },
  64. back() {
  65. wx.navigateBack({ delta: 1 })
  66. },
  67. /**
  68. * 生命周期函数--监听页面加载
  69. */
  70. onLoad(options) {
  71. this.watchLogin();
  72. this.search();
  73. },
  74. // 监听用户是否登录
  75. watchLogin: async function () {
  76. const userInfo = wx.getStorageSync('user')
  77. if (!userInfo) wx.redirectTo({ url: '/pages/index/index', })
  78. this.setData({ userInfo })
  79. },
  80. /**
  81. * 生命周期函数--监听页面初次渲染完成
  82. */
  83. onReady() {
  84. },
  85. /**
  86. * 生命周期函数--监听页面显示
  87. */
  88. onShow() {
  89. },
  90. /**
  91. * 生命周期函数--监听页面隐藏
  92. */
  93. onHide() {
  94. },
  95. /**
  96. * 生命周期函数--监听页面卸载
  97. */
  98. onUnload() {
  99. },
  100. /**
  101. * 页面相关事件处理函数--监听用户下拉动作
  102. */
  103. onPullDownRefresh() {
  104. },
  105. /**
  106. * 页面上拉触底事件的处理函数
  107. */
  108. onReachBottom() {
  109. },
  110. /**
  111. * 用户点击右上角分享
  112. */
  113. onShareAppMessage() {
  114. }
  115. })