index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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: async function (e) {
  16. const that = this;
  17. const id = e.currentTarget.dataset?.item?._id;
  18. const res = await app.$post('/newCourt/api/payOrder/toRePay', { id })
  19. if (res.errcode == '0') {
  20. wx.requestPayment({
  21. "timeStamp": res.data.wxSign.timestamp,
  22. "nonceStr": res.data.wxSign.nonceStr,
  23. "package": `prepay_id=${res.data.wxSign.prepay_id}`,
  24. "signType": res.data.wxSign.signType,
  25. "paySign": res.data.wxSign.paySign,
  26. "success": async function (arr) {
  27. wx.showToast({ title: `支付成功`, icon: 'success', duration: 2000 });
  28. const aee = await app.$post(`/newCourt/api/payOrder/${res.data.data._id}`, { status: '1' });
  29. if (aee.errcode == '0') { that.watchLogin(); }
  30. },
  31. "fail": function (res) {
  32. wx.showToast({ title: `支付未成功`, icon: 'error', duration: 2000 })
  33. that.watchLogin()
  34. },
  35. })
  36. }
  37. },
  38. // 退款
  39. toRefund: async function (e) {
  40. const that = this;
  41. const { item } = e.currentTarget.dataset;
  42. wx.showModal({
  43. title: '提示',
  44. content: '您是否确定要进行退款,一旦操作不可恢复?',
  45. async success(res) {
  46. if (res.confirm) {
  47. const arr = await app.$post('/newCourt/api/payOrder/toRefund', { id: item._id })
  48. if (arr.errcode == '0') {
  49. wx.showToast({ title: `退款成功`, icon: 'success', duration: 2000 });
  50. that.watchLogin();
  51. } else {
  52. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 });
  53. }
  54. } else if (res.cancel) { }
  55. }
  56. });
  57. },
  58. /**
  59. * 生命周期函数--监听页面加载
  60. */
  61. onLoad(options) {
  62. this.watchLogin();
  63. },
  64. // 监听用户是否登录
  65. watchLogin: async function () {
  66. const that = this;
  67. wx.getStorage({
  68. key: 'user',
  69. success: async res => {
  70. const arr = await app.$get(`/newCourt/api/payOrder`, { openid: res.data.openid, skip: 0, limit: 1000 })
  71. if (arr.errcode == '0') {
  72. let list = arr.data;
  73. list = list.map(i => ({ ...i, statusZh: that.getStatusZh(i.status) }))
  74. that.setData({ list })
  75. }
  76. },
  77. fail: res => {
  78. wx.redirectTo({ url: '/pages/index/index', })
  79. }
  80. })
  81. },
  82. getStatusZh(status) {
  83. let word = "未知"
  84. switch (status) {
  85. case '0':
  86. word = "未支付"
  87. break;
  88. case '1':
  89. word = "支付成功"
  90. break;
  91. case '-1':
  92. word = "支付失败"
  93. break;
  94. case '-2':
  95. word = "申请退款"
  96. break;
  97. case '-3':
  98. word = "已退款"
  99. break;
  100. default:
  101. break;
  102. }
  103. return word;
  104. },
  105. /**
  106. * 生命周期函数--监听页面初次渲染完成
  107. */
  108. onReady() {
  109. },
  110. /**
  111. * 生命周期函数--监听页面显示
  112. */
  113. onShow() {
  114. },
  115. /**
  116. * 生命周期函数--监听页面隐藏
  117. */
  118. onHide() {
  119. },
  120. /**
  121. * 生命周期函数--监听页面卸载
  122. */
  123. onUnload() {
  124. },
  125. /**
  126. * 页面相关事件处理函数--监听用户下拉动作
  127. */
  128. onPullDownRefresh() {
  129. },
  130. /**
  131. * 页面上拉触底事件的处理函数
  132. */
  133. onReachBottom() {
  134. },
  135. /**
  136. * 用户点击右上角分享
  137. */
  138. onShareAppMessage() {
  139. }
  140. })