layout.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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/layoutInfo' })
  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. const { info_id, id } = options;
  97. that.setData({ match_id: id })
  98. that.setData({ info_id: info_id })
  99. //验证规则函数
  100. this.initValidate();
  101. // 计算高度
  102. this.searchHeight();
  103. // 监听用户是否登录
  104. this.watchLogin();
  105. },
  106. // 监听用户是否登录
  107. watchLogin: function () {
  108. const that = this;
  109. wx.getStorage({
  110. key: 'token',
  111. success: async res => {
  112. that.setData({ user: res.data });
  113. let arr;
  114. // 查询比赛信息
  115. arr = await app.$get(`/courtAdmin/api/match/${that.data.match_id}`);
  116. if (arr.errcode == '0') that.setData({ matchInfo: arr.data });
  117. // 查询报名团队
  118. arr = await app.$get(`/courtAdmin/api/matchteam`, { match_id: that.data.match_id })
  119. if (arr.errcode == '0') that.setData({ teamList: arr.data });
  120. that.setData({ teamTotal: arr.total });
  121. // 组织表单数据
  122. let data = { match_id: that.data.matchInfo._id, match_name: that.data.matchInfo.name, format: that.data.matchInfo.format };
  123. that.setData({ form: data })
  124. },
  125. fail: res => {
  126. return wx.redirectTo({ url: '/pages/login/index', })
  127. }
  128. })
  129. },
  130. // 计算高度
  131. searchHeight: function () {
  132. let frameStyle = this.data.frameStyle;
  133. let client = app.globalData.client;
  134. let infoHeight = client.windowHeight;
  135. // 是否去掉状态栏
  136. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  137. // 是否减去底部菜单
  138. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  139. if (infoHeight) this.setData({ infoHeight: infoHeight })
  140. },
  141. /**
  142. * 生命周期函数--监听页面初次渲染完成
  143. */
  144. onReady: function () {
  145. },
  146. /**
  147. * 生命周期函数--监听页面显示
  148. */
  149. onShow: function () {
  150. },
  151. /**
  152. * 生命周期函数--监听页面隐藏
  153. */
  154. onHide: function () {
  155. },
  156. /**
  157. * 生命周期函数--监听页面卸载
  158. */
  159. onUnload: function () {
  160. },
  161. /**
  162. * 页面相关事件处理函数--监听用户下拉动作
  163. */
  164. onPullDownRefresh: function () {
  165. },
  166. /**
  167. * 页面上拉触底事件的处理函数
  168. */
  169. onReachBottom: function () {
  170. },
  171. /**
  172. * 用户点击右上角分享
  173. */
  174. onShareAppMessage: function () {
  175. }
  176. })