index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. const app = getApp()
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. frameStyle: { useTop: true, name: '淘汰赛管理', leftArrow: true, useBar: false },
  8. dialog: { title: '赛程信息', show: false, type: '1' },
  9. form: {},
  10. // 赛事信息
  11. matchList: [],
  12. // 组别
  13. groupingList: [],
  14. //组内项目
  15. projectList: [],
  16. },
  17. // 跳转菜单
  18. back(e) {
  19. wx.navigateBack({
  20. delta: 1,
  21. })
  22. },
  23. // 添加
  24. toAdd: function () {
  25. const that = this;
  26. that.setData({ dialog: { title: '赛程信息', show: true, type: '1' } })
  27. },
  28. // 关闭弹框
  29. toClose: function () {
  30. const that = this;
  31. that.setData({ form: {} })
  32. that.setData({ dialog: { title: '赛程信息', show: true, type: '1' } })
  33. },
  34. // 选择赛事
  35. matchChange: function (e) {
  36. const that = this;
  37. let data = that.data.matchList[e.detail.value];
  38. if (data) {
  39. that.setData({ 'form.match_id': data._id });
  40. that.setData({ 'form.match_name': data.name });
  41. if (data.grouping && data.grouping.length > 0) {
  42. that.setData({ groupingList: data.grouping })
  43. }
  44. }
  45. },
  46. // 选择赛事组别
  47. grpupChange: async function (e) {
  48. const that = this;
  49. let data = that.data.groupingList[e.detail.value];
  50. if (data) {
  51. that.setData({ 'form.grouping_id': data._id });
  52. that.setData({ 'form.grouping_name': data.name });
  53. if (data.project && data.project.length > 0) {
  54. let projectList = [];
  55. for (const val of data.project) {
  56. const arr = await app.$get(`/newCourt/api/matchProject/${val}`)
  57. if (arr.errcode == '0') projectList.push(arr.data);
  58. that.setData({ projectList: projectList })
  59. }
  60. }
  61. }
  62. },
  63. // 选择组内项目
  64. projectChange: function (e) {
  65. const that = this;
  66. let data = that.data.projectList[e.detail.value];
  67. if (data) {
  68. that.setData({ 'form.project_id': data._id });
  69. that.setData({ 'form.project_name': data.name });
  70. }
  71. },
  72. // 赛程信息
  73. onSubmit: function (e) {
  74. const that = this;
  75. const params = e.detail.value;
  76. if (params.match_id && params.grouping_id && params.project_id) {
  77. wx.navigateTo({ url: `/pages/eliminate/add?match_id=${params.match_id}&grouping_id=${params.grouping_id}&project_id=${params.project_id}` })
  78. } else {
  79. wx.showToast({ title: `缺少必要信息`, icon: 'error', duration: 2000 })
  80. }
  81. },
  82. /**
  83. * 生命周期函数--监听页面加载
  84. */
  85. onLoad: function (options) {
  86. const that = this;
  87. },
  88. /**
  89. * 生命周期函数--监听页面初次渲染完成
  90. */
  91. onReady: function () {
  92. },
  93. /**
  94. * 生命周期函数--监听页面显示
  95. */
  96. onShow: function () {
  97. const that = this;
  98. that.watchLogin();
  99. },
  100. // 监听用户是否登录
  101. watchLogin: async function () {
  102. const that = this;
  103. wx.getStorage({
  104. key: 'user',
  105. success: async res => {
  106. let arr;
  107. // 比赛信息
  108. arr = await app.$get(`/newCourt/api/match`, { status: '0' });//2
  109. if (arr.errcode == '0') { that.setData({ matchList: arr.data }) }
  110. },
  111. fail: res => {
  112. wx.redirectTo({ url: '/pages/index/index', })
  113. }
  114. })
  115. },
  116. /**
  117. * 生命周期函数--监听页面隐藏
  118. */
  119. onHide: function () {
  120. },
  121. /**
  122. * 生命周期函数--监听页面卸载
  123. */
  124. onUnload: function () {
  125. },
  126. /**
  127. * 页面相关事件处理函数--监听用户下拉动作
  128. */
  129. onPullDownRefresh: function () {
  130. },
  131. /**
  132. * 页面上拉触底事件的处理函数
  133. */
  134. onReachBottom: function () {
  135. },
  136. /**
  137. * 用户点击右上角分享
  138. */
  139. onShareAppMessage: function () {
  140. }
  141. })