index.js 6.3 KB

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