layoutInfo.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. match_id: '',
  14. matchInfo: {},
  15. list: [],
  16. // 弹框
  17. dialog: { title: '详细信息', show: false, type: '1' },
  18. //详情
  19. form: {},
  20. // 状态
  21. statusList: [{ label: '未开始', value: '0' }, { label: '进行中', value: '1' }, { label: '已结束', value: '2' }],
  22. },
  23. back: function () {
  24. wx.navigateBack({ url: '/pages/matchadmin/index' })
  25. },
  26. // 添加
  27. toAdd: function () {
  28. const that = this;
  29. wx.navigateTo({ url: `/pages/matchadmin/layout?id=${that.data.match_id}` })
  30. },
  31. // 查看
  32. toView: async function (e) {
  33. const that = this;
  34. let { id } = e.currentTarget.dataset;
  35. const arr = await app.$get(`/courtAdmin/api/schedule/${id}`);
  36. if (arr.errcode == '0') {
  37. that.setData({ form: arr.data })
  38. that.setData({ dialog: { title: '详细信息', show: true, type: '1' } })
  39. }
  40. },
  41. //比赛进度
  42. toEdit: async function (e) {
  43. const that = this;
  44. let { id } = e.currentTarget.dataset;
  45. const arr = await app.$get(`/courtAdmin/api/schedule/${id}`);
  46. if (arr.errcode == '0') {
  47. that.setData({ form: arr.data })
  48. that.setData({ dialog: { title: '比赛进度', show: true, type: '2' } })
  49. }
  50. },
  51. // 选择状态
  52. statusChange: function (e) {
  53. const that = this;
  54. const { value } = e.detail;
  55. that.setData({ 'form.status': value })
  56. },
  57. // 提交
  58. onSubmit: async function (e) {
  59. const that = this;
  60. const data = that.data.form;
  61. const params = e.detail.value;
  62. const arr = await app.$post(`/courtAdmin/api/schedule/${data.id}`, params);
  63. if (arr.errcode == '0') {
  64. wx.showToast({ title: `维护信息成功`, icon: 'error', duration: 2000 });
  65. that.toClose();
  66. that.watchLogin();
  67. } else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  68. },
  69. // 维护赛程信息
  70. toRace: function (e) {
  71. const { id } = e.currentTarget.dataset;
  72. wx.navigateTo({ url: `/pages/matchadmin/layoutdetail?id=${id}` })
  73. },
  74. toClose: function () {
  75. const that = this;
  76. that.setData({ dialog: { title: '详细信息', show: false, } })
  77. },
  78. /**
  79. * 生命周期函数--监听页面加载
  80. */
  81. onLoad: function (options) {
  82. const that = this;
  83. that.setData({ match_id: options.id || '629eb5de78fa03648c0535d9' })
  84. // 计算高度
  85. this.searchHeight();
  86. // 监听用户是否登录
  87. this.watchLogin();
  88. },
  89. // 监听用户是否登录
  90. watchLogin: function () {
  91. const that = this;
  92. wx.getStorage({
  93. key: 'token',
  94. success: async res => {
  95. let arr;
  96. // 查询比赛信息
  97. arr = await app.$get(`/courtAdmin/api/match/${that.data.match_id}`,);
  98. if (arr.errcode == '0') that.setData({ matchInfo: arr.data });
  99. // 查询赛制信息
  100. arr = await app.$get(`/courtAdmin/api/schedule`, { match_id: that.data.match_id });
  101. if (arr.errcode == '0') that.setData({ list: arr.data });
  102. },
  103. fail: res => {
  104. return wx.redirectTo({ url: '/pages/login/index', })
  105. }
  106. })
  107. },
  108. // 计算高度
  109. searchHeight: function () {
  110. let frameStyle = this.data.frameStyle;
  111. let client = app.globalData.client;
  112. let infoHeight = client.windowHeight;
  113. // 是否去掉状态栏
  114. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  115. // 是否减去底部菜单
  116. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  117. if (infoHeight) this.setData({ infoHeight: infoHeight })
  118. },
  119. /**
  120. * 生命周期函数--监听页面初次渲染完成
  121. */
  122. onReady: function () {
  123. },
  124. /**
  125. * 生命周期函数--监听页面显示
  126. */
  127. onShow: function () {
  128. },
  129. /**
  130. * 生命周期函数--监听页面隐藏
  131. */
  132. onHide: function () {
  133. },
  134. /**
  135. * 生命周期函数--监听页面卸载
  136. */
  137. onUnload: function () {
  138. },
  139. /**
  140. * 页面相关事件处理函数--监听用户下拉动作
  141. */
  142. onPullDownRefresh: function () {
  143. },
  144. /**
  145. * 页面上拉触底事件的处理函数
  146. */
  147. onReachBottom: function () {
  148. },
  149. /**
  150. * 用户点击右上角分享
  151. */
  152. onShareAppMessage: function () {
  153. }
  154. })