index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: true, name: '我的报名', leftArrow: true, useBar: false },
  8. searchInfo: {},
  9. list: [],
  10. dialog: { title: '详细信息', show: false, type: '1' },
  11. info: {},
  12. },
  13. // 跳转菜单
  14. back(e) {
  15. wx.navigateBack({ delta: 1 })
  16. },
  17. // 查询
  18. search: function (e) {
  19. const that = this;
  20. that.setData({ 'searchInfo.name': e.detail.value });
  21. that.watchLogin()
  22. },
  23. // 查看
  24. toView: async function (e) {
  25. const that = this;
  26. const { item } = e.currentTarget.dataset;
  27. that.setData({ info: item })
  28. that.setData({ dialog: { title: '详细信息', show: true, type: '1' } })
  29. },
  30. // 组队申请
  31. toTeam: function (e) {
  32. const { item } = e.currentTarget.dataset;
  33. wx.navigateTo({ url: `/pages/usermyteam/add?id=${item.enroll_id}` })
  34. },
  35. // 支付
  36. toPay: async function (e) {
  37. const that = this;
  38. const enroll_id = e.currentTarget.dataset?.item?.enroll_id;
  39. wx.getStorage({
  40. key: 'user',
  41. success: async (res) => {
  42. let obj = { openid: res.data.openid, money: 0.1, enroll_id: enroll_id, type: '报名' }
  43. const arr = await app.$post(`/newCourt/api/payOrder`, obj)
  44. if (arr.errcode == '0') {
  45. wx.requestPayment({
  46. "timeStamp": arr.data.wxSign.timestamp,
  47. "nonceStr": arr.data.wxSign.nonceStr,
  48. "package": `prepay_id=${arr.data.wxSign.prepay_id}`,
  49. "signType": arr.data.wxSign.signType,
  50. "paySign": arr.data.wxSign.paySign,
  51. "success": async function (res) {
  52. wx.showToast({ title: `支付成功`, icon: 'success', duration: 2000 });
  53. const aee = await app.$post(`/newCourt/api/payOrder/${arr.data.data._id}`, { status: '1' });
  54. if (aee.errcode == '0') { that.watchLogin(); }
  55. },
  56. "fail": function (res) {
  57. wx.showToast({ title: `支付未成功`, icon: 'error', duration: 2000 })
  58. that.watchLogin()
  59. },
  60. })
  61. }
  62. },
  63. fail: async (res) => {
  64. wx.redirectTo({ url: '/pages/index/index' });
  65. },
  66. });
  67. },
  68. // 退款
  69. toOut: async function (e) {
  70. const that = this;
  71. const { item } = e.currentTarget.dataset;
  72. const arr = await app.$post('/newCourt/api/payOrder/toRefund', { id: item.pay_id })
  73. if (arr.errcode == '0') {
  74. wx.showToast({ title: `退款成功`, icon: 'success', duration: 2000 });
  75. that.watchLogin();
  76. } else {
  77. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 });
  78. }
  79. },
  80. // 关闭弹框
  81. toClose: function () {
  82. const that = this;
  83. that.setData({ dialog: { title: '详细信息', show: false, type: '1' } })
  84. },
  85. /**
  86. * 生命周期函数--监听页面加载
  87. */
  88. onLoad: function (options) {
  89. const that = this;
  90. that.watchLogin();
  91. },
  92. // 监听用户是否登录
  93. watchLogin: async function () {
  94. const that = this;
  95. let searchInfo = that.data.searchInfo;
  96. wx.getStorage({
  97. key: 'user',
  98. success: async res => {
  99. let info = {};
  100. if (searchInfo && searchInfo.name) info.match_name = searchInfo.name;
  101. const arr = await app.$get(`/newCourt/api/view/myMatchList/`, { openid: res.data.openid, ...info });
  102. if (arr.errcode == '0') {
  103. that.setData({ list: arr.data })
  104. }
  105. },
  106. fail: res => {
  107. wx.redirectTo({ url: '/pages/index/index', })
  108. }
  109. })
  110. },
  111. /**
  112. * 生命周期函数--监听页面初次渲染完成
  113. */
  114. onReady: function () {
  115. },
  116. /**
  117. * 生命周期函数--监听页面显示
  118. */
  119. onShow: function () {
  120. },
  121. /**
  122. * 生命周期函数--监听页面隐藏
  123. */
  124. onHide: function () {
  125. },
  126. /**
  127. * 生命周期函数--监听页面卸载
  128. */
  129. onUnload: function () {
  130. },
  131. /**
  132. * 页面相关事件处理函数--监听用户下拉动作
  133. */
  134. onPullDownRefresh: function () {
  135. },
  136. /**
  137. * 页面上拉触底事件的处理函数
  138. */
  139. onReachBottom: function () {
  140. },
  141. /**
  142. * 用户点击右上角分享
  143. */
  144. onShareAppMessage: function () {
  145. }
  146. })