layoutInfo.js 6.4 KB

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