index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. wx.navigateTo({ url: `/pages/teamDetails/detail?id=${id}` })
  56. },
  57. // 我的服务-功能按钮
  58. toCommon: function (e) {
  59. let { route, method } = e.currentTarget.dataset;
  60. let list = JSON.stringify(e.currentTarget.dataset.item);
  61. let id = e.currentTarget.dataset.id;
  62. if (method == 'signout') {
  63. wx.showModal({
  64. title: '提示',
  65. content: '是否确认退出登录',
  66. success(res) {
  67. if (res.confirm) {
  68. wx.removeStorage({
  69. key: 'token',
  70. success(res) {
  71. return wx.redirectTo({ url: '/pages/index/index', })
  72. }
  73. })
  74. }
  75. }
  76. })
  77. } else {
  78. wx.navigateTo({ url: `/${route}?id=` + id + `&list=` + list })
  79. }
  80. },
  81. /**
  82. * 生命周期函数--监听页面加载
  83. */
  84. onLoad: function (options) {
  85. // 计算高度
  86. this.searchHeight()
  87. // 监听用户是否登录
  88. this.watchLogin();
  89. },
  90. // 监听用户是否登录
  91. watchLogin: function () {
  92. const that = this;
  93. wx.getStorage({
  94. key: 'token',
  95. success: res => {
  96. //查询用户信息
  97. that.searchUser(res.data);
  98. //查询团队列表
  99. that.searchTeam(res.data);
  100. },
  101. fail: res => {
  102. wx.redirectTo({ url: '/pages/login/index', })
  103. }
  104. })
  105. },
  106. //查询用户信息
  107. searchUser: function (e) {
  108. const that = this;
  109. var id = e.id;
  110. wx.request({
  111. url: `${app.globalData.publicUrl}/courtAdmin/api/user/${id}`,
  112. method: "get",
  113. data: {},
  114. header: {},
  115. success: res => {
  116. that.setData({ item1: res.data.data })
  117. let type = res.data.data.type;
  118. let icon = res.data.data.icon[0];
  119. if (icon) this.setData({ icon: icon.url })
  120. else this.setData({ icon: '/image/tou.png' });
  121. // 判断用户身份显示不同功能按钮
  122. let jump = btn.filter((i) => i.type.includes(type));
  123. if (jump) that.setData({ jumpList: jump });
  124. },
  125. error: err => {
  126. }
  127. })
  128. },
  129. //查询团队列表
  130. searchTeam: function (e) {
  131. let id = e.id;
  132. let type = e.type
  133. if (type == 1) {
  134. //团队管理员-团队列表
  135. wx.request({
  136. url: `${app.globalData.publicUrl}/courtAdmin/api/team`,
  137. method: "get",
  138. data: { create_id: id },
  139. header: {},
  140. success: res => {
  141. this.setData({ list: res.data.data })
  142. //查询比赛列表
  143. this.searchMatch(res.data.data);
  144. },
  145. error: err => {
  146. }
  147. })
  148. } else if (type == 2) {
  149. //个人用户-所在团队列表
  150. wx.request({
  151. url: `${app.globalData.publicUrl}/courtAdmin/api/team/userteams`,
  152. method: "get",
  153. data: { user_id: id },
  154. header: {},
  155. success: res => {
  156. this.setData({ list: res.data.data })
  157. },
  158. error: err => {
  159. }
  160. })
  161. }
  162. },
  163. //查询比赛列表
  164. searchMatch: async function (e) {
  165. const that = this;
  166. let id = e[0]._id;
  167. let data = [];
  168. const res = await app.$get('/courtAdmin/api/schedule', { red_id: id });
  169. if (res.errcode === 0) data = res.data;
  170. const arr = await app.$get('/courtAdmin/api/schedule', { blue_id: id });
  171. if (arr.errcode === 0) data = [...data, ...arr.data];
  172. that.setData({ match: data })
  173. },
  174. // 计算高度
  175. searchHeight: function () {
  176. let frameStyle = this.data.frameStyle;
  177. let client = app.globalData.client;
  178. let infoHeight = client.windowHeight;
  179. // 是否去掉状态栏
  180. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  181. // 是否减去底部菜单
  182. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  183. if (infoHeight) this.setData({ infoHeight: infoHeight })
  184. },
  185. /**
  186. * 生命周期函数--监听页面初次渲染完成
  187. */
  188. onReady: function () {
  189. },
  190. /**
  191. * 生命周期函数--监听页面显示
  192. */
  193. onShow: function () {
  194. },
  195. /**
  196. * 生命周期函数--监听页面隐藏
  197. */
  198. onHide: function () {
  199. },
  200. /**
  201. * 生命周期函数--监听页面卸载
  202. */
  203. onUnload: function () {
  204. },
  205. /**
  206. * 页面相关事件处理函数--监听用户下拉动作
  207. */
  208. onPullDownRefresh: function () {
  209. },
  210. /**
  211. * 页面上拉触底事件的处理函数
  212. */
  213. onReachBottom: function () {
  214. },
  215. /**
  216. * 用户点击右上角分享
  217. */
  218. onShareAppMessage: function () {
  219. }
  220. })