index.js 2.8 KB

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