index.js 4.5 KB

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