index.js 6.2 KB

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