index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. const moment = require("../../utils/moment.min")
  5. // pages/meMatch/index.js
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. frameStyle: { useTop: true, name: '比赛管理', leftArrow: true, useBar: false },
  12. src: '/image/home.png',
  13. // 主体高度
  14. infoHeight: '',
  15. //待申请-报名中比赛列表
  16. list: [],
  17. //已申请-报名的比赛列表
  18. alreadyList: [],
  19. //团队
  20. list1: {},
  21. apply_time: ''
  22. },
  23. back: function () {
  24. wx.navigateBack({ url: '/pages/me/index' })
  25. },
  26. //报名比赛
  27. signUp: function (e) {
  28. const that = this
  29. const arr = {
  30. team_id: this.data.list1._id,
  31. team_name: this.data.list1.name,
  32. logo: this.data.list1.logo,
  33. create_id: this.data.list1.create_id,
  34. create_user: this.data.list1.create_user,
  35. create_time: this.data.list1.create_time,
  36. members: this.data.list1.members,
  37. match_num: this.data.list1.members.length,
  38. apply_time: this.data.apply_time,
  39. match_id: e.currentTarget.dataset.id,
  40. match_name: e.currentTarget.dataset.name,
  41. }
  42. wx.showModal({
  43. title: '',
  44. content: '是否申请报名入',
  45. success(res) {
  46. if (res.confirm) {
  47. wx.request({
  48. url: `${app.globalData.publicUrl}/courtAdmin/api/matchteam`,
  49. method: 'post',
  50. data: arr,
  51. success(res) {
  52. if (res.data.errcode == 0) {
  53. wx.showToast({ title: `报名成功`, icon: 'success', duration: 2000 });
  54. that.watchLogin();
  55. } else {
  56. wx.showToast({ title: res.data.errmsg, icon: 'none', duration: 2000 })
  57. }
  58. }
  59. })
  60. } else if (res.cancel) { }
  61. }
  62. })
  63. },
  64. /**
  65. * 生命周期函数--监听页面加载
  66. */
  67. onLoad: function (options) {
  68. let apply_time = moment().format('YYYY-MM-DD HH:mm:ss');
  69. this.setData({ apply_time: apply_time });
  70. this.setData({ list1: JSON.parse(options.list) })
  71. // 计算高度
  72. this.searchHeight();
  73. // 监听用户是否登录
  74. this.watchLogin();
  75. },
  76. // 监听用户是否登录
  77. watchLogin: function () {
  78. var that = this;
  79. let team_id = this.data.list1._id;
  80. wx.getStorage({
  81. key: 'token',
  82. success: res => {
  83. //待申请-报名中的比赛
  84. wx.request({
  85. url: `${app.globalData.publicUrl}/courtAdmin/api/match`,
  86. method: 'get',
  87. data: { status: '1' },
  88. success(res) {
  89. that.setData({ list: res.data.data })
  90. }
  91. })
  92. //已申请-已报名的比赛
  93. wx.request({
  94. url: `${app.globalData.publicUrl}/courtAdmin/api/matchteam`,
  95. method: 'get',
  96. data: { team_id: team_id },
  97. success(res) {
  98. that.setData({ alreadyList: res.data.data })
  99. }
  100. })
  101. },
  102. fail: res => {
  103. return wx.redirectTo({ url: '/pages/login/index', })
  104. }
  105. })
  106. },
  107. // 计算高度
  108. searchHeight: function () {
  109. let frameStyle = this.data.frameStyle;
  110. let client = app.globalData.client;
  111. let infoHeight = client.windowHeight;
  112. // 减去状态栏
  113. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2)
  114. // 是否减去底部菜单
  115. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  116. if (infoHeight) this.setData({ infoHeight: infoHeight })
  117. },
  118. /**
  119. * 生命周期函数--监听页面初次渲染完成
  120. */
  121. onReady: function () {
  122. },
  123. /**
  124. * 生命周期函数--监听页面显示
  125. */
  126. onShow: function () {
  127. },
  128. /**
  129. * 生命周期函数--监听页面隐藏
  130. */
  131. onHide: function () {
  132. },
  133. /**
  134. * 生命周期函数--监听页面卸载
  135. */
  136. onUnload: function () {
  137. },
  138. /**
  139. * 页面相关事件处理函数--监听用户下拉动作
  140. */
  141. onPullDownRefresh: function () {
  142. },
  143. /**
  144. * 页面上拉触底事件的处理函数
  145. */
  146. onReachBottom: function () {
  147. },
  148. /**
  149. * 用户点击右上角分享
  150. */
  151. onShareAppMessage: function () {
  152. }
  153. })