index.js 5.9 KB

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