index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. const arr = await app.$post('/newCourt/api/payOrder/toRefund', { id: item._id })
  43. if (arr.errcode == '0') {
  44. wx.showToast({ title: `退款成功`, icon: 'success', duration: 2000 });
  45. that.watchLogin();
  46. } else {
  47. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 });
  48. }
  49. },
  50. /**
  51. * 生命周期函数--监听页面加载
  52. */
  53. onLoad(options) {
  54. this.watchLogin();
  55. },
  56. // 监听用户是否登录
  57. watchLogin: async function () {
  58. const that = this;
  59. wx.getStorage({
  60. key: 'user',
  61. success: async res => {
  62. const arr = await app.$get(`/newCourt/api/payOrder`, { openid: res.data.openid })
  63. if (arr.errcode == '0') {
  64. let list = arr.data;
  65. list = list.map(i => ({ ...i, statusZh: that.getStatusZh(i.status) }))
  66. that.setData({ list })
  67. }
  68. },
  69. fail: res => {
  70. wx.redirectTo({ url: '/pages/index/index', })
  71. }
  72. })
  73. },
  74. getStatusZh(status) {
  75. let word = "未知"
  76. switch (status) {
  77. case '0':
  78. word = "未支付"
  79. break;
  80. case '1':
  81. word = "支付成功"
  82. break;
  83. case '-1':
  84. word = "支付失败"
  85. break;
  86. case '-2':
  87. word = "申请退款"
  88. break;
  89. case '-3':
  90. word = "已退款"
  91. break;
  92. default:
  93. break;
  94. }
  95. return word;
  96. },
  97. /**
  98. * 生命周期函数--监听页面初次渲染完成
  99. */
  100. onReady() {
  101. },
  102. /**
  103. * 生命周期函数--监听页面显示
  104. */
  105. onShow() {
  106. },
  107. /**
  108. * 生命周期函数--监听页面隐藏
  109. */
  110. onHide() {
  111. },
  112. /**
  113. * 生命周期函数--监听页面卸载
  114. */
  115. onUnload() {
  116. },
  117. /**
  118. * 页面相关事件处理函数--监听用户下拉动作
  119. */
  120. onPullDownRefresh() {
  121. },
  122. /**
  123. * 页面上拉触底事件的处理函数
  124. */
  125. onReachBottom() {
  126. },
  127. /**
  128. * 用户点击右上角分享
  129. */
  130. onShareAppMessage() {
  131. }
  132. })