layoutdetail.js 6.5 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. // 数据id
  13. id: '',
  14. // 用户信息
  15. user: {},
  16. // 团队列表
  17. teamList: [],
  18. // 团队总数
  19. teamTotal: 0,
  20. // 表单
  21. form: { red_logo: [], red_members: [], blue_logo: [], blue_members: [] },
  22. // 是否轮空
  23. byeList: ['true', 'false',]
  24. },
  25. initValidate() {
  26. 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 } }
  27. // 验证字段的提示信息,若不传则调用默认的信息
  28. const messages = { date: { required: '比斯日期', }, time: { required: '比赛时间', }, position: { required: '比赛场次轮数', }, red_position: { required: '红方场次编号', }, red_id: { required: '红方团队', }, blue_id: { required: '蓝方团队', }, blue_position: { required: '蓝方场次编号', } };
  29. this.WxValidate = new WxValidate(rules, messages)
  30. },
  31. back: function () {
  32. wx.navigateBack({ url: '/pages/matchteam/layout' })
  33. },
  34. // 选择比赛时间
  35. dateChange: function (e) {
  36. const that = this;
  37. const { type } = e.currentTarget.dataset;
  38. const { value } = e.detail;
  39. if (type == 'date') that.setData({ 'form.date': value })
  40. else if (type == 'time') that.setData({ 'form.time': value });
  41. let match_time = that.data.form.date + '-' + that.data.form.time;
  42. that.setData({ 'form.match_time': match_time })
  43. },
  44. // 比赛场次轮数
  45. positionBlur: function (e) {
  46. const that = this;
  47. const { value } = e.detail;
  48. that.setData({ 'form.position': value });
  49. that.setData({ 'form.red_position': value + '-' });
  50. that.setData({ 'form.blue_position': value + '-' });
  51. },
  52. // 选择比赛双方
  53. teamChange: function (e) {
  54. const that = this;
  55. const { type } = e.currentTarget.dataset;
  56. const { value } = e.detail;
  57. let teamInfo = that.data.teamList[value];
  58. that.setData({ ['form.' + `${type}_id`]: teamInfo.team_id })
  59. that.setData({ ['form.' + `${type}_name`]: teamInfo.team_name })
  60. that.setData({ ['form.' + `${type}_logo`]: teamInfo.logo })
  61. that.setData({ ['form.' + `${type}_members`]: teamInfo.members })
  62. },
  63. // 选择是否轮空
  64. byeChange: function (e) {
  65. const that = this;
  66. const { value } = e.detail;
  67. let data = that.data.byeList[value];
  68. that.setData({ 'form.is_bye': data })
  69. },
  70. // 提交保存
  71. async onSubmit(e) {
  72. const that = this;
  73. const params = e.detail.value;
  74. const data = that.data.form;
  75. if (!this.WxValidate.checkForm(params)) {
  76. const error = this.WxValidate.errorList[0];
  77. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  78. return false
  79. } else {
  80. params.format = data.format;
  81. params.red_logo = data.red_logo;
  82. params.red_members = data.red_members;
  83. params.blue_logo = data.blue_logo;
  84. params.blue_members = data.blue_members;
  85. const arr = await app.$post(`/courtAdmin/api/schedule/${data.id}`, params)
  86. if (arr.errcode == '0') { wx.showToast({ title: `维护信息完成`, icon: 'success', duration: 2000 }); that.back(); }
  87. else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  88. }
  89. },
  90. /**
  91. * 生命周期函数--监听页面加载
  92. */
  93. onLoad: function (options) {
  94. const that = this;
  95. that.setData({ id: options.id || '62aa9dbdd82e7813d98e367f' })
  96. //验证规则函数
  97. that.initValidate();
  98. // 计算高度
  99. that.searchHeight();
  100. // 监听用户是否登录
  101. that.watchLogin();
  102. },
  103. // 监听用户是否登录
  104. watchLogin: async function () {
  105. const that = this;
  106. wx.getStorage({
  107. key: 'token',
  108. success: async res => {
  109. that.setData({ user: res.data })
  110. let arr;
  111. let schedule;
  112. // 查询赛程信息
  113. arr = await app.$get(`/courtAdmin/api/schedule/${that.data.id}`);
  114. if (arr.errcode == '0') {
  115. schedule = arr.data;
  116. let match = await app.$get(`/courtAdmin/api/match/${schedule.match_id}`);
  117. if (match.data) schedule.format = match.data.format;
  118. that.setData({ form: schedule });
  119. }
  120. // 查询报名团队
  121. arr = await app.$get(`/courtAdmin/api/matchteam`, { match_id: schedule.match_id })
  122. if (arr.errcode == '0') that.setData({ teamList: arr.data });
  123. that.setData({ teamTotal: arr.total });
  124. },
  125. fail: res => {
  126. wx.redirectTo({ url: '/pages/index/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. })