detail.js 5.7 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. form: {},
  13. // 比赛id
  14. id: '',
  15. // 比赛信息
  16. matchInfo: {},
  17. // 参赛团队
  18. matchteamList: [],
  19. // 红方数据
  20. redInfo: {},
  21. // 蓝方数据
  22. blueInfo: {},
  23. },
  24. //验证必填项
  25. initValidate() {
  26. const rules = { red_id: { required: true }, blue_id: { required: true }, date: { required: true }, time: { required: true }, }
  27. // 验证字段的提示信息,若不传则调用默认的信息
  28. const messages = { red_id: { required: '选择红方' }, blue_id: { required: '选择蓝方' }, date: { required: '选择日期' }, time: { required: '选择时间' } };
  29. this.WxValidate = new WxValidate(rules, messages)
  30. },
  31. back: function () {
  32. wx.navigateBack({ url: '/pages/lays/index' })
  33. },
  34. // 选择红方
  35. redChange: function (e) {
  36. const that = this;
  37. let index = e.detail.value;
  38. let data = that.data.matchteamList[index];
  39. if (data) {
  40. that.setData({ 'form.red_id': data._id, 'form.red_name': data.team_name })
  41. that.setData({ redInfo: data })
  42. }
  43. },
  44. // 选择蓝方
  45. blueChange: function (e) {
  46. const that = this;
  47. let index = e.detail.value;
  48. let data = that.data.matchteamList[index];
  49. if (data) {
  50. that.setData({ 'form.blue_id': data._id, 'form.blue_name': data.team_name })
  51. that.setData({ blueInfo: data })
  52. }
  53. },
  54. // 日期选择
  55. dateChange: function (e) {
  56. const that = this;
  57. that.setData({ 'form.date': e.detail.value });
  58. that.setData({ 'form.match_time': that.data.form.date + ' ' + that.data.form.time })
  59. },
  60. // 时间选择
  61. timeChange: function (e) {
  62. const that = this;
  63. that.setData({ 'form.time': e.detail.value });
  64. that.setData({ 'form.match_time': that.data.form.date + ' ' + that.data.form.time })
  65. },
  66. // 保存信息
  67. onSubmit: async function (e) {
  68. const that = this;
  69. let red = that.data.redInfo;
  70. let blue = that.data.blueInfo;
  71. let parmas = e.detail.value;
  72. parmas.red_name = red.team_name;
  73. parmas.red_logo = red.logo;
  74. parmas.red_members = red.members;
  75. parmas.blue_name = blue.team_name;
  76. parmas.blue_logo = blue.logo;
  77. parmas.blue_members = blue.members;
  78. if (!this.WxValidate.checkForm(parmas)) {
  79. const error = this.WxValidate.errorList[0];
  80. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  81. return false
  82. } else {
  83. const arr = await app.$post(`/courtAdmin/api/schedule`, parmas);
  84. if (arr.errcode === 0) {
  85. wx.showToast({ title: '保存成功', icon: 'success', duration: 2000 })
  86. that.back();
  87. } else {
  88. wx.showToast({ title: arr.errmsg, icon: 'error', duration: 2000 })
  89. }
  90. }
  91. },
  92. /**
  93. * 生命周期函数--监听页面加载
  94. */
  95. onLoad: function (options) {
  96. const that = this;
  97. that.setData({ id: options.id})
  98. //验证规则函数
  99. this.initValidate();
  100. // 计算高度
  101. this.searchHeight();
  102. // 监听用户是否登录
  103. this.watchLogin();
  104. },
  105. // 验证用户登录
  106. watchLogin: async function () {
  107. const that = this;
  108. let id = that.data.id;
  109. wx.getStorage({
  110. key: 'token',
  111. success: async res => {
  112. // 查询比赛信息
  113. const arr = await app.$post(`/courtAdmin/api/match/${id}`);
  114. if (arr.errcode === 0) {
  115. that.setData({ matchInfo: arr.data });
  116. // 赋值form比赛信息
  117. that.setData({ 'form.match_id': arr.data._id, 'form.match_name': arr.data.name })
  118. }
  119. // 参赛团队
  120. const aee = await app.$get(`/courtAdmin/api/matchteam`, { match_id: id, status: 1 });
  121. if (aee.errcode === 0) that.setData({ matchteamList: aee.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. })