index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. debugger
  42. wx.getStorage({
  43. key: 'user',
  44. success: async (res) => {
  45. let obj = { openid: res.data.openid, money: 0.1, enroll_id: enroll_id, type: '报名' }
  46. const arr = await app.$post(`/newCourt/api/payOrder`, obj)
  47. if (arr.errcode == '0') {
  48. wx.requestPayment({
  49. "timeStamp": arr.data.wxSign.timestamp,
  50. "nonceStr": arr.data.wxSign.nonceStr,
  51. "package": `prepay_id=${arr.data.wxSign.prepay_id}`,
  52. "signType": arr.data.wxSign.signType,
  53. "paySign": arr.data.wxSign.paySign,
  54. "success": async function (res) {
  55. wx.showToast({ title: `支付成功`, icon: 'success', duration: 2000 });
  56. const aee = await app.$post(`/newCourt/api/payOrder/${arr.data.data._id}`, { status: '1' });
  57. if (aee.errcode == '0') { that.watchLogin(); }
  58. },
  59. "fail": function (res) {
  60. wx.showToast({ title: `支付未成功`, icon: 'error', duration: 2000 })
  61. that.watchLogin()
  62. },
  63. })
  64. }
  65. },
  66. fail: async (res) => {
  67. wx.redirectTo({ url: '/pages/index/index' });
  68. },
  69. });
  70. },
  71. // 退款
  72. toOut: async function (e) {
  73. const that = this;
  74. const { item } = e.currentTarget.dataset;
  75. const arr = await app.$post('/newCourt/api/payOrder/toRefund', { id: item.pay_id })
  76. if (arr.errcode == '0') {
  77. wx.showToast({ title: `退款成功`, icon: 'success', duration: 2000 });
  78. that.watchLogin();
  79. } else {
  80. wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 });
  81. }
  82. },
  83. // 关闭弹框
  84. toClose: function () {
  85. const that = this;
  86. that.setData({ dialog: { title: '详细信息', show: false, type: '1' } })
  87. },
  88. /**
  89. * 生命周期函数--监听页面加载
  90. */
  91. onLoad: function (options) {
  92. const that = this;
  93. that.watchLogin();
  94. },
  95. // 监听用户是否登录
  96. watchLogin: async function () {
  97. const that = this;
  98. let searchInfo = that.data.searchInfo;
  99. wx.getStorage({
  100. key: 'user',
  101. success: async res => {
  102. let info = {};
  103. if (searchInfo && searchInfo.name) info.match_name = searchInfo.name;
  104. const arr = await app.$get(`/newCourt/api/view/myMatchList/`, { openid: res.data.openid, ...info });
  105. if (arr.errcode == '0') {
  106. for (const val of arr.data) {
  107. // 赛事信息
  108. const match = await app.$get(`/newCourt/api/match/${val.match_id}`);
  109. if (match.errcode = '0') { val.match_name = match.data.name };
  110. }
  111. that.setData({ list: arr.data })
  112. console.log(arr.data);
  113. }
  114. },
  115. fail: res => {
  116. wx.redirectTo({ url: '/pages/index/index', })
  117. }
  118. })
  119. },
  120. /**
  121. * 生命周期函数--监听页面初次渲染完成
  122. */
  123. onReady: function () {
  124. },
  125. /**
  126. * 生命周期函数--监听页面显示
  127. */
  128. onShow: function () {
  129. },
  130. /**
  131. * 生命周期函数--监听页面隐藏
  132. */
  133. onHide: function () {
  134. },
  135. /**
  136. * 生命周期函数--监听页面卸载
  137. */
  138. onUnload: function () {
  139. },
  140. /**
  141. * 页面相关事件处理函数--监听用户下拉动作
  142. */
  143. onPullDownRefresh: function () {
  144. },
  145. /**
  146. * 页面上拉触底事件的处理函数
  147. */
  148. onReachBottom: function () {
  149. },
  150. /**
  151. * 用户点击右上角分享
  152. */
  153. onShareAppMessage: function () {
  154. }
  155. })