layout.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '编排比赛赛制', leftArrow: true, useBar: false },
  10. // 主体高度
  11. infoHeight: '',
  12. // 用户信息
  13. user: {},
  14. // 比赛信息
  15. match_id: '629eb5de78fa03648c0535d9',
  16. matchInfo: {},
  17. // 团队列表
  18. teamList: [],
  19. // 团队总数
  20. teamTotal: 0,
  21. // 表单
  22. form: { red_logo: [], red_members: [], blue_logo: [], blue_members: [] },
  23. // 是否轮空
  24. byeList: ['true', 'false',]
  25. },
  26. initValidate() {
  27. const rules = { date: { required: true }, time: { required: true }, position: { required: true }, red_position: { required: true }, red_id: { required: true }, blue_position: { required: false }, blue_id: { required: false } }
  28. // 验证字段的提示信息,若不传则调用默认的信息
  29. const messages = { date: { required: '比斯日期', }, time: { required: '比赛时间', }, position: { required: '比赛场次轮数', }, red_position: { required: '红方场次编号', }, red_id: { required: '红方团队', }, blue_id: { required: '蓝方团队', }, blue_position: { required: '蓝方场次编号', } };
  30. this.WxValidate = new WxValidate(rules, messages)
  31. },
  32. back: function () {
  33. wx.navigateBack({ url: '/pages/matchadmin/index' })
  34. },
  35. // 选择比赛时间
  36. dateChange: function (e) {
  37. const that = this;
  38. const { type } = e.currentTarget.dataset;
  39. const { value } = e.detail;
  40. if (type == 'date') that.setData({ 'form.date': value })
  41. else if (type == 'time') that.setData({ 'form.time': value });
  42. let match_time = that.data.form.date + '-' + that.data.form.time;
  43. that.setData({ 'form.match_time': match_time })
  44. },
  45. // 比赛场次轮数
  46. positionBlur: function (e) {
  47. const that = this;
  48. const { value } = e.detail;
  49. that.setData({ 'form.position': value });
  50. that.setData({ 'form.red_position': value + '-' });
  51. that.setData({ 'form.blue_position': value + '-' });
  52. },
  53. // 选择比赛双方
  54. teamChange: function (e) {
  55. const that = this;
  56. const { type } = e.currentTarget.dataset;
  57. const { value } = e.detail;
  58. let teamInfo = that.data.teamList[value];
  59. that.setData({ ['form.' + `${type}_id`]: teamInfo.team_id })
  60. that.setData({ ['form.' + `${type}_name`]: teamInfo.team_name })
  61. that.setData({ ['form.' + `${type}_logo`]: teamInfo.logo })
  62. that.setData({ ['form.' + `${type}_members`]: teamInfo.members })
  63. },
  64. // 选择是否轮空
  65. byeChange: function (e) {
  66. const that = this;
  67. const { value } = e.detail;
  68. let data = that.data.byeList[value];
  69. that.setData({ 'form.is_bye': data })
  70. },
  71. // 提交保存
  72. async onSubmit(e) {
  73. const that = this;
  74. const params = e.detail.value;
  75. const data = that.data.form;
  76. if (!this.WxValidate.checkForm(params)) {
  77. const error = this.WxValidate.errorList[0];
  78. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  79. return false
  80. } else {
  81. params.format = data.format;
  82. params.red_logo = data.red_logo;
  83. params.red_members = data.red_members;
  84. params.blue_logo = data.blue_logo;
  85. params.blue_members = data.blue_members;
  86. const arr = await app.$post(`/courtAdmin/api/schedule`, params)
  87. if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
  88. else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  89. }
  90. },
  91. /**
  92. * 生命周期函数--监听页面加载
  93. */
  94. onLoad: function (options) {
  95. const that = this;
  96. if (options && options.id) that.setData({ match_id: options.id })
  97. //验证规则函数
  98. this.initValidate();
  99. // 计算高度
  100. this.searchHeight();
  101. // 监听用户是否登录
  102. this.watchLogin();
  103. },
  104. // 监听用户是否登录
  105. watchLogin: function () {
  106. const that = this;
  107. wx.getStorage({
  108. key: 'token',
  109. success: async res => {
  110. that.setData({ user: res.data });
  111. let arr;
  112. // 查询比赛信息
  113. arr = await app.$get(`/courtAdmin/api/match/${that.data.match_id}`);
  114. if (arr.errcode == '0') that.setData({ matchInfo: arr.data });
  115. // 查询报名团队
  116. arr = await app.$get(`/courtAdmin/api/matchteam`, { match_id: that.data.match_id })
  117. if (arr.errcode == '0') that.setData({ teamList: arr.data });
  118. that.setData({ teamTotal: arr.total });
  119. // 组织表单数据
  120. let data = { match_id: that.data.matchInfo._id, match_name: that.data.matchInfo.name, format: that.data.matchInfo.format };
  121. that.setData({ form: data })
  122. },
  123. fail: res => {
  124. return wx.redirectTo({ url: '/pages/login/index', })
  125. }
  126. })
  127. },
  128. // 计算高度
  129. searchHeight: function () {
  130. let frameStyle = this.data.frameStyle;
  131. let client = app.globalData.client;
  132. let infoHeight = client.windowHeight;
  133. // 是否去掉状态栏
  134. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  135. // 是否减去底部菜单
  136. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  137. if (infoHeight) this.setData({ infoHeight: infoHeight })
  138. },
  139. /**
  140. * 生命周期函数--监听页面初次渲染完成
  141. */
  142. onReady: function () {
  143. },
  144. /**
  145. * 生命周期函数--监听页面显示
  146. */
  147. onShow: function () {
  148. },
  149. /**
  150. * 生命周期函数--监听页面隐藏
  151. */
  152. onHide: function () {
  153. },
  154. /**
  155. * 生命周期函数--监听页面卸载
  156. */
  157. onUnload: function () {
  158. },
  159. /**
  160. * 页面相关事件处理函数--监听用户下拉动作
  161. */
  162. onPullDownRefresh: function () {
  163. },
  164. /**
  165. * 页面上拉触底事件的处理函数
  166. */
  167. onReachBottom: function () {
  168. },
  169. /**
  170. * 用户点击右上角分享
  171. */
  172. onShareAppMessage: function () {
  173. }
  174. })