index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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: 50, 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. wx.showModal({
  73. title: '提示',
  74. content: '您是否确定要进行退款,一旦操作不可恢复?',
  75. async success(res) {
  76. if (res.confirm) {
  77. const arr = await app.$post('/newCourt/api/payOrder/toRefund', { id: item.pay_id })
  78. if (arr.errcode == '0') {
  79. wx.showToast({ title: `退款成功`, icon: 'success', duration: 2000 });
  80. that.watchLogin();
  81. } else {
  82. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 });
  83. }
  84. } else if (res.cancel) { }
  85. }
  86. });
  87. },
  88. // 关闭弹框
  89. toClose: function () {
  90. const that = this;
  91. that.setData({ dialog: { title: '详细信息', show: false, type: '1' } })
  92. },
  93. /**
  94. * 生命周期函数--监听页面加载
  95. */
  96. onLoad: function (options) {
  97. const that = this;
  98. that.watchLogin();
  99. },
  100. // 监听用户是否登录
  101. watchLogin: async function () {
  102. const that = this;
  103. let searchInfo = that.data.searchInfo;
  104. wx.getStorage({
  105. key: 'user',
  106. success: async res => {
  107. let info = { skip: 0, limit: 1000 };
  108. if (searchInfo && searchInfo.name) info.match_name = searchInfo.name;
  109. const arr = await app.$get(`/newCourt/api/view/myMatchList/`, { openid: res.data.openid, ...info });
  110. if (arr.errcode == '0') {
  111. that.setData({ list: arr.data })
  112. }
  113. },
  114. fail: res => {
  115. wx.redirectTo({ url: '/pages/index/index', })
  116. }
  117. })
  118. },
  119. /**
  120. * 生命周期函数--监听页面初次渲染完成
  121. */
  122. onReady: function () {
  123. },
  124. /**
  125. * 生命周期函数--监听页面显示
  126. */
  127. onShow: function () {
  128. },
  129. /**
  130. * 生命周期函数--监听页面隐藏
  131. */
  132. onHide: function () {
  133. },
  134. /**
  135. * 生命周期函数--监听页面卸载
  136. */
  137. onUnload: function () {
  138. },
  139. /**
  140. * 页面相关事件处理函数--监听用户下拉动作
  141. */
  142. onPullDownRefresh: function () {
  143. },
  144. /**
  145. * 页面上拉触底事件的处理函数
  146. */
  147. onReachBottom: function () {
  148. },
  149. /**
  150. * 用户点击右上角分享
  151. */
  152. onShareAppMessage: function () {
  153. }
  154. })