index.js 4.8 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) {
  21. const that = this;
  22. that.setData({ 'searchInfo.name': e.detail.value });
  23. that.watchLogin()
  24. },
  25. // 查看
  26. toView: async function (e) {
  27. const that = this;
  28. const { item } = e.currentTarget.dataset;
  29. that.setData({ info: item })
  30. that.setData({ dialog: { title: '详细信息', show: true, type: '1' } })
  31. },
  32. // 组队申请
  33. toTeam: function (e) {
  34. const { item } = e.currentTarget.dataset;
  35. wx.navigateTo({ url: `/pages/usermyteam/add?id=${item.enroll_id}` })
  36. },
  37. // 支付
  38. toPay: async function (e) {
  39. const that = this;
  40. const enroll_id = e.currentTarget.dataset?.item?.enroll_id;
  41. wx.getStorage({
  42. key: 'user',
  43. success: async (res) => {
  44. let obj = { openid: res.data.openid, money: 0.1, enroll_id: enroll_id, type: '报名' }
  45. const arr = await app.$post(`/newCourt/api/payOrder`, obj)
  46. if (arr.errcode == '0') {
  47. wx.requestPayment({
  48. "timeStamp": arr.data.wxSign.timestamp,
  49. "nonceStr": arr.data.wxSign.nonceStr,
  50. "package": `prepay_id=${arr.data.wxSign.prepay_id}`,
  51. "signType": arr.data.wxSign.signType,
  52. "paySign": arr.data.wxSign.paySign,
  53. "success": async function (res) {
  54. wx.showToast({ title: `支付成功`, icon: 'success', duration: 2000 });
  55. const aee = await app.$post(`/newCourt/api/payOrder/${arr.data.data._id}`, { status: '1' });
  56. if (aee.errcode == '0') { that.watchLogin(); }
  57. },
  58. "fail": function (res) {
  59. wx.showToast({ title: `支付未成功`, icon: 'error', duration: 2000 })
  60. that.watchLogin()
  61. },
  62. })
  63. }
  64. },
  65. fail: async (res) => {
  66. wx.redirectTo({ url: '/pages/index/index' });
  67. },
  68. });
  69. },
  70. // 退款
  71. toOut: async function (e) {
  72. const that = this;
  73. const { item } = e.currentTarget.dataset;
  74. const arr = await app.$post('/newCourt/api/payOrder/toRefund', { id: item.pay_id })
  75. if (arr.errcode == '0') {
  76. wx.showToast({ title: `退款成功`, icon: 'success', duration: 2000 });
  77. that.watchLogin();
  78. } else {
  79. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 });
  80. }
  81. },
  82. // 关闭弹框
  83. toClose: function () {
  84. const that = this;
  85. that.setData({ dialog: { title: '详细信息', show: false, type: '1' } })
  86. },
  87. /**
  88. * 生命周期函数--监听页面加载
  89. */
  90. onLoad: function (options) {
  91. const that = this;
  92. that.watchLogin();
  93. },
  94. // 监听用户是否登录
  95. watchLogin: async function () {
  96. const that = this;
  97. let searchInfo = that.data.searchInfo;
  98. wx.getStorage({
  99. key: 'user',
  100. success: async res => {
  101. let info = {};
  102. if (searchInfo && searchInfo.name) info.match_name = searchInfo.name;
  103. const arr = await app.$get(`/newCourt/api/view/myMatchList/`, { openid: res.data.openid, ...info });
  104. if (arr.errcode == '0') {
  105. that.setData({ list: arr.data })
  106. }
  107. },
  108. fail: res => {
  109. wx.redirectTo({ url: '/pages/index/index', })
  110. }
  111. })
  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. })