index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. const app = getApp()
  2. import { examine_status } from '../../utils/dict';
  3. import WxValidate from '../../utils/wxValidate';
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '订单管理', leftArrow: true, useBar: false },
  10. searchInfo: {},
  11. list: [],
  12. dialog: { title: '详细信息', show: false, type: '1' },
  13. info: {},
  14. },
  15. // 跳转菜单
  16. back(e) {
  17. wx.navigateBack({ delta: 1 })
  18. },
  19. // 查询
  20. search: function (e) { console.log('查询'); },
  21. // 查看
  22. toView: async function (e) {
  23. const that = this;
  24. const { item } = e.currentTarget.dataset;
  25. const arr = await app.$get(`/newCourt/api/payOrder/${item._id}`);
  26. if (arr.errcode == '0') {
  27. // 用户信息
  28. const user = await app.$get(`/newCourt/api/user/${arr.data.openid}`);
  29. if (user.errcode = '0') { arr.data.user_name = user.data.name };
  30. arr.data.statusZh = that.getStatusZh(arr.data.status)
  31. that.setData({ info: arr.data })
  32. that.setData({ dialog: { title: '详细信息', show: true, type: '1' } })
  33. }
  34. },
  35. // 关闭弹框
  36. toClose: function () {
  37. const that = this;
  38. that.setData({ dialog: { title: '详细信息', show: false, type: '1' } })
  39. },
  40. // 退款
  41. toRefund: async function (e) {
  42. const that = this;
  43. const { item } = e.currentTarget.dataset;
  44. const arr = await app.$post('/newCourt/api/payOrder/toRefund', { id: item._id })
  45. if (arr.errcode == '0') {
  46. wx.showToast({ title: `退款成功`, icon: 'success', duration: 2000 });
  47. that.watchLogin();
  48. } else {
  49. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 });
  50. }
  51. },
  52. /**
  53. * 生命周期函数--监听页面加载
  54. */
  55. onLoad: function (options) {
  56. const that = this;
  57. that.watchLogin();
  58. },
  59. // 监听用户是否登录
  60. watchLogin: async function () {
  61. const that = this;
  62. wx.getStorage({
  63. key: 'user',
  64. success: async res => {
  65. const arr = await app.$get(`/newCourt/api/payOrder`);
  66. if (arr.errcode == '0') {
  67. let list = arr.data;
  68. for (const val of list) {
  69. // 用户信息
  70. const user = await app.$get(`/newCourt/api/user/${val.openid}`);
  71. if (user.errcode = '0') { val.user_name = user.data.name };
  72. }
  73. list = list.map(i => ({ ...i, statusZh: this.getStatusZh(i.status) }))
  74. this.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: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面显示
  112. */
  113. onShow: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面隐藏
  117. */
  118. onHide: function () {
  119. },
  120. /**
  121. * 生命周期函数--监听页面卸载
  122. */
  123. onUnload: function () {
  124. },
  125. /**
  126. * 页面相关事件处理函数--监听用户下拉动作
  127. */
  128. onPullDownRefresh: function () {
  129. },
  130. /**
  131. * 页面上拉触底事件的处理函数
  132. */
  133. onReachBottom: function () {
  134. },
  135. /**
  136. * 用户点击右上角分享
  137. */
  138. onShareAppMessage: function () {
  139. }
  140. })