index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. let team_id = this.data.list1._id;
  29. let team_name = this.data.list1.name;
  30. let logo = this.data.list1.logo;
  31. let create_id = this.data.list1.create_id;
  32. let create_user = this.data.list1.create_user;
  33. let create_time = this.data.list1.create_time;
  34. let members = this.data.list1.members;
  35. let match_num = this.data.list1.members.length;
  36. let apply_time = this.data.apply_time;
  37. wx.showModal({
  38. title: '',
  39. content: '是否申请报名入',
  40. success(res) {
  41. if (res.confirm) {
  42. wx.request({
  43. url: `${app.globalData.publicUrl}/courtAdmin/api/matchteam`, //接口地址
  44. method: 'post',
  45. data: {
  46. match_id: e.currentTarget.dataset.id,
  47. match_name: e.currentTarget.dataset.name,
  48. team_id: team_id,
  49. team_name: team_name,
  50. logo: logo,
  51. create_id: create_id,
  52. create_user: create_user,
  53. create_time: create_time,
  54. members: members,
  55. match_num: match_num,
  56. apply_time: apply_time,
  57. },
  58. success(res) {
  59. if (res.data.errcode == 0) {
  60. wx.showToast({
  61. title: `报名成功`,
  62. icon: 'success',
  63. duration: 2000
  64. })
  65. } else {
  66. wx.showToast({
  67. title: res.data.errmsg,
  68. icon: 'none',
  69. duration: 2000
  70. })
  71. }
  72. }
  73. })
  74. } else if (res.cancel) { }
  75. }
  76. })
  77. },
  78. /**
  79. * 生命周期函数--监听页面加载
  80. */
  81. onLoad: function (options) {
  82. let apply_time = moment().format('YYYY-MM-DD HH:mm:ss');
  83. this.setData({ apply_time: apply_time });
  84. this.setData({ list1: JSON.parse(options.list) })
  85. // 计算高度
  86. this.searchHeight();
  87. // 监听用户是否登录
  88. this.watchLogin();
  89. },
  90. // 监听用户是否登录
  91. watchLogin: function () {
  92. var that = this;
  93. let team_id = this.data.list1._id;
  94. wx.getStorage({
  95. key: 'token',
  96. success: res => {
  97. //待申请-报名中的比赛
  98. wx.request({
  99. url: `${app.globalData.publicUrl}/courtAdmin/api/match`, //接口地址
  100. method: 'get',
  101. data: { status: '1' },
  102. success(res) {
  103. that.setData({ list: res.data.data })
  104. }
  105. })
  106. //已申请-已报名的比赛
  107. wx.request({
  108. url: `${app.globalData.publicUrl}/courtAdmin/api/matchteam`, //接口地址
  109. method: 'get',
  110. data: { team_id: team_id },
  111. success(res) {
  112. that.setData({ alreadyList: res.data.data })
  113. }
  114. })
  115. },
  116. fail: res => {
  117. return wx.redirectTo({ url: '/pages/login/index', })
  118. }
  119. })
  120. },
  121. // 计算高度
  122. searchHeight: function () {
  123. let frameStyle = this.data.frameStyle;
  124. let client = app.globalData.client;
  125. let infoHeight = client.windowHeight;
  126. // 减去状态栏
  127. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2)
  128. // 是否减去底部菜单
  129. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  130. if (infoHeight) this.setData({ infoHeight: infoHeight })
  131. },
  132. /**
  133. * 生命周期函数--监听页面初次渲染完成
  134. */
  135. onReady: function () {
  136. },
  137. /**
  138. * 生命周期函数--监听页面显示
  139. */
  140. onShow: function () {
  141. },
  142. /**
  143. * 生命周期函数--监听页面隐藏
  144. */
  145. onHide: function () {
  146. },
  147. /**
  148. * 生命周期函数--监听页面卸载
  149. */
  150. onUnload: function () {
  151. },
  152. /**
  153. * 页面相关事件处理函数--监听用户下拉动作
  154. */
  155. onPullDownRefresh: function () {
  156. },
  157. /**
  158. * 页面上拉触底事件的处理函数
  159. */
  160. onReachBottom: function () {
  161. },
  162. /**
  163. * 用户点击右上角分享
  164. */
  165. onShareAppMessage: function () {
  166. }
  167. })