index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. import { btn } from "../../utils/dict";
  4. const app = getApp()
  5. var url = app.globalData.url;
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. frameStyle: { useTop: true, name: '我的', leftArrow: false, useBar: true },
  12. src: '/image/fen.jpg',
  13. src3: '/image/huang.png',
  14. src4: '/image/zan.png',
  15. showMore: false,
  16. // 主体高度
  17. infoHeight: '',
  18. total: '4',
  19. //上传比分
  20. match: [],
  21. //个人信息详情
  22. item1: {},
  23. //团队列表
  24. list: [],
  25. //头像
  26. icon: '',
  27. jumpList: [],
  28. },
  29. // 跳转菜单
  30. tabPath(e) {
  31. let { route } = e.detail.detail;
  32. if (route) wx.redirectTo({ url: `/${route}` })
  33. },
  34. //展开
  35. listToggle: function () {
  36. this.setData({ showMore: !this.data.showMore })
  37. },
  38. //修改个人信息
  39. modify: function () {
  40. wx.navigateTo({ url: `/pages/information/index` })
  41. },
  42. //上传比分
  43. upload: function (e) {
  44. let id = e.currentTarget.dataset.id
  45. wx.navigateTo({ url: `/pages/score/index?id=${id}` })
  46. },
  47. //创建团队
  48. create: function () {
  49. wx.navigateTo({ url: `/pages/createTeam/index` })
  50. },
  51. //团队创建人-团队详情
  52. //个人用户-团队详情
  53. ToDetails: function (e) {
  54. let id = e.currentTarget.dataset.id;
  55. let type = this.data.item1.type;
  56. wx.navigateTo({ url: `/pages/teamDetails/detail?id=${id}` })
  57. },
  58. // 我的服务-功能按钮
  59. toCommon: function (e) {
  60. let { route, method } = e.currentTarget.dataset;
  61. let list = JSON.stringify(e.currentTarget.dataset.item);
  62. let id = e.currentTarget.dataset.id;
  63. if (method == 'signout') {
  64. wx.showModal({
  65. title: '提示',
  66. content: '是否确认退出登录',
  67. success(res) {
  68. if (res.confirm) {
  69. wx.removeStorage({
  70. key: 'token',
  71. success(res) {
  72. return wx.redirectTo({ url: '/pages/index/index', })
  73. }
  74. })
  75. }
  76. }
  77. })
  78. } else {
  79. wx.navigateTo({ url: `/${route}?id=` + id + `&list=` + list })
  80. }
  81. },
  82. /**
  83. * 生命周期函数--监听页面加载
  84. */
  85. onLoad: function (options) {
  86. // 计算高度
  87. this.searchHeight()
  88. // 监听用户是否登录
  89. this.watchLogin();
  90. },
  91. // 监听用户是否登录
  92. watchLogin: function () {
  93. const that = this;
  94. wx.getStorage({
  95. key: 'token',
  96. success: res => {
  97. //查询用户信息
  98. that.searchUser(res.data);
  99. //查询团队列表
  100. that.searchTeam(res.data);
  101. },
  102. fail: res => {
  103. wx.redirectTo({ url: '/pages/login/index', })
  104. }
  105. })
  106. },
  107. //查询用户信息
  108. searchUser: function (e) {
  109. const that = this;
  110. var id = e.id;
  111. wx.request({
  112. url: `${app.globalData.publicUrl}/courtAdmin/api/user/${id}`,
  113. method: "get",
  114. data: {},
  115. header: {},
  116. success: res => {
  117. that.setData({ item1: res.data.data })
  118. let type = res.data.data.type;
  119. let icon = res.data.data.icon[0];
  120. if (icon) this.setData({ icon: icon.url })
  121. else this.setData({ icon: '/image/tou.png' });
  122. // 判断用户身份显示不同功能按钮
  123. let jump = btn.filter((i) => i.type.includes(type));
  124. if (jump) that.setData({ jumpList: jump });
  125. },
  126. error: err => {
  127. }
  128. })
  129. },
  130. //查询团队列表
  131. searchTeam: function (e) {
  132. let id = e.id;
  133. let type = e.type
  134. if (type == 1) {
  135. //团队管理员-团队列表
  136. wx.request({
  137. url: `${app.globalData.publicUrl}/courtAdmin/api/team`,
  138. method: "get",
  139. data: { create_id: id },
  140. header: {},
  141. success: res => {
  142. this.setData({ list: res.data.data })
  143. //查询比赛列表
  144. this.searchMatch(res.data.data);
  145. },
  146. error: err => {
  147. }
  148. })
  149. } else if (type == 2) {
  150. //个人用户-所在团队列表
  151. wx.request({
  152. url: `${app.globalData.publicUrl}/courtAdmin/api/team/userteams`,
  153. method: "get",
  154. data: { user_id: id },
  155. header: {},
  156. success: res => {
  157. this.setData({ list: res.data.data })
  158. },
  159. error: err => {
  160. }
  161. })
  162. }
  163. },
  164. //查询比赛列表
  165. searchMatch: async function (e) {
  166. const that = this;
  167. let id = e[0]._id;
  168. let data = [];
  169. const res = await app.$get('/courtAdmin/api/schedule', { red_id: id });
  170. if (res.errcode === 0) data = res.data;
  171. const arr = await app.$get('/courtAdmin/api/schedule', { blue_id: id });
  172. if (arr.errcode === 0) data = [...data, ...arr.data];
  173. that.setData({ match: data })
  174. },
  175. // 计算高度
  176. searchHeight: function () {
  177. let frameStyle = this.data.frameStyle;
  178. let client = app.globalData.client;
  179. let infoHeight = client.windowHeight;
  180. // 是否去掉状态栏
  181. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  182. // 是否减去底部菜单
  183. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  184. if (infoHeight) this.setData({ infoHeight: infoHeight })
  185. },
  186. /**
  187. * 生命周期函数--监听页面初次渲染完成
  188. */
  189. onReady: function () {
  190. },
  191. /**
  192. * 生命周期函数--监听页面显示
  193. */
  194. onShow: function () {
  195. },
  196. /**
  197. * 生命周期函数--监听页面隐藏
  198. */
  199. onHide: function () {
  200. },
  201. /**
  202. * 生命周期函数--监听页面卸载
  203. */
  204. onUnload: function () {
  205. },
  206. /**
  207. * 页面相关事件处理函数--监听用户下拉动作
  208. */
  209. onPullDownRefresh: function () {
  210. },
  211. /**
  212. * 页面上拉触底事件的处理函数
  213. */
  214. onReachBottom: function () {
  215. },
  216. /**
  217. * 用户点击右上角分享
  218. */
  219. onShareAppMessage: function () {
  220. }
  221. })