index.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. const app = getApp();
  2. import { btn } from '../../utils/dict';
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. frameStyle: { useTop: true, name: '我的', leftArrow: false, useBar: true },
  9. // 主体高度
  10. infoHeight: '',
  11. bg: '/image/me_1.jpg',
  12. // 用户信息
  13. userInfo: {},
  14. // 正在比赛
  15. ismatchList: [
  16. {
  17. id: '1',
  18. _id: '1',
  19. status: '0',
  20. match_time: '2020-11-11 10:11',
  21. red_logo: [{
  22. name: "20220331104915.jpg",
  23. uri: "/files/court/elimg/20220331104915.jpg",
  24. url: "http://broadcast.waityou24.cn/files/court/elimg/20220331104915.jpg",
  25. }],
  26. red_name: '红方名称',
  27. red_branch: '11',
  28. blue_branch: '11',
  29. blue_name: '蓝方名称',
  30. blue_logo: [{
  31. name: "20220331104915.jpg",
  32. uri: "/files/court/elimg/20220331104915.jpg",
  33. url: "http://broadcast.waityou24.cn/files/court/elimg/20220331104915.jpg",
  34. }],
  35. },
  36. ],
  37. ismatch_url: '/image/me_2.png',
  38. // 我的团队
  39. teamList: [],
  40. // 我的服务
  41. btnList: [],
  42. // 弹框
  43. dialog: { title: '上传比分', show: false, type: '1' }
  44. },
  45. tabPath: function (e) {
  46. let { route } = e.detail.detail;
  47. if (route) wx.redirectTo({ url: `/${route}` })
  48. },
  49. // 上传比分
  50. toScore: function () {
  51. const that = this;
  52. that.setData({ dialog: { title: '上传比分', show: true, type: '1' } })
  53. },
  54. // 比赛信息
  55. matchView: function (e) {
  56. const { id } = e.currentTarget.dataset;
  57. wx.navigateTo({ url: `/pages/match/info?id=${id}` })
  58. },
  59. // 团队信息
  60. teamView: function (e) {
  61. const { id } = e.currentTarget.dataset;
  62. wx.navigateTo({ url: `/pages/teamInfo/info?id=${id}` })
  63. },
  64. // 公共跳转路由方法
  65. toCommon: function (e) {
  66. let { route, method } = e.currentTarget.dataset;
  67. if (method) {
  68. wx.showModal({
  69. title: '提示',
  70. content: '是否确认退出登录',
  71. success(res) {
  72. if (res.confirm) {
  73. wx.removeStorage({
  74. key: 'token',
  75. success(res) {
  76. return wx.redirectTo({ url: '/pages/index/index', })
  77. }
  78. })
  79. }
  80. }
  81. })
  82. } else {
  83. wx.navigateTo({ url: `/pages/${route}/index` })
  84. }
  85. },
  86. // 关闭弹框
  87. toClose: function () {
  88. const that = this;
  89. that.setData({ dialog: { title: '上传比分', show: false, type: '1' } })
  90. that.watchLogin()
  91. },
  92. /**
  93. * 生命周期函数--监听页面加载
  94. */
  95. onLoad: function (options) {
  96. // 计算高度
  97. this.searchHeight();
  98. // 监听用户是否登录
  99. this.watchLogin();
  100. },
  101. // 监听用户是否登录
  102. watchLogin: function () {
  103. const that = this;
  104. wx.getStorage({
  105. key: 'token',
  106. success: async res => {
  107. wx.request({
  108. url: `${app.globalData.publicUrl}/courtAdmin/api/user/${res.data.id}`, //接口地址
  109. method: 'get',
  110. data: {},
  111. async success(res) {
  112. if (res.data.errcode == 0) {
  113. let user = res.data.data;
  114. // 头像
  115. user.icons = user.icon[0] ? user.icon[0].url : '';
  116. // 我的服务,判断不同用户显示不同功能按钮
  117. let menu = btn.filter((i) => i.type.includes(user.type));
  118. if (menu) that.setData({ btnList: menu });
  119. // 团队信息,所在团队信息
  120. if (user.type == '0') {
  121. that.setData({ userInfo: user })
  122. } else if (user.type == '1') {
  123. let arr = await app.$get(`/courtAdmin/api/team`, { create_id: user._id, status: '1' });
  124. if (arr.errcode == '0') {
  125. let team = arr.data;
  126. that.setData({ teamList: team });
  127. if (arr.total > 0) {
  128. let teamInfo = team[0] ? team[0] : { name: '' };
  129. user.team_name = teamInfo.name;
  130. }
  131. that.setData({ userInfo: user })
  132. } else wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  133. } else if (user.type == '2') {
  134. const arr = await app.$get(`/courtAdmin/api/team/userteams`, { user_id: user._id });
  135. if (arr.errcode == '0') {
  136. let team = arr.data;
  137. that.setData({ teamList: team });
  138. let teamInfo = team[0] ? team[0] : { name: '' };
  139. user.team_name = teamInfo.name;
  140. that.setData({ userInfo: user })
  141. } else {
  142. wx.showToast({ title: arr.data.errmsg, icon: 'error', duration: 2000 })
  143. }
  144. }
  145. } else {
  146. wx.showToast({ title: res.data.errmsg, icon: 'error', duration: 2000 })
  147. }
  148. }
  149. })
  150. },
  151. fail: res => {
  152. wx.redirectTo({ url: '/pages/index/index', })
  153. }
  154. })
  155. },
  156. // 计算高度
  157. searchHeight: function () {
  158. let frameStyle = this.data.frameStyle;
  159. let client = app.globalData.client;
  160. let infoHeight = client.windowHeight;
  161. // 是否去掉状态栏
  162. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  163. // 是否减去底部菜单
  164. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  165. if (infoHeight) this.setData({ infoHeight: infoHeight })
  166. },
  167. /**
  168. * 生命周期函数--监听页面初次渲染完成
  169. */
  170. onReady: function () {
  171. },
  172. /**
  173. * 生命周期函数--监听页面显示
  174. */
  175. onShow: function () {
  176. this.watchLogin();
  177. },
  178. /**
  179. * 生命周期函数--监听页面隐藏
  180. */
  181. onHide: function () {
  182. },
  183. /**
  184. * 生命周期函数--监听页面卸载
  185. */
  186. onUnload: function () {
  187. },
  188. /**
  189. * 页面相关事件处理函数--监听用户下拉动作
  190. */
  191. onPullDownRefresh: function () {
  192. },
  193. /**
  194. * 页面上拉触底事件的处理函数
  195. */
  196. onReachBottom: function () {
  197. },
  198. /**
  199. * 用户点击右上角分享
  200. */
  201. onShareAppMessage: function () {
  202. }
  203. })