index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '我的团队', leftArrow: false, useBar: true },
  10. type: '',
  11. src: '/image/team.png',
  12. // 主体高度
  13. infoHeight: '',
  14. //团队列表
  15. teamlist: [],
  16. //判断
  17. keyindex:[],
  18. //用户id
  19. user_id: ''
  20. },
  21. // 跳转菜单
  22. tabPath(e) {
  23. let { route } = e.detail.detail;
  24. if (route) wx.redirectTo({ url: `/${route}` })
  25. },
  26. //跳转查看或加入
  27. jump: function (e) {
  28. let { id, type } = e.currentTarget.dataset;
  29. if (type) wx.navigateTo({ url: `/pages/team/${type}?id=${id}` })
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. // 计算高度
  36. this.searchHeight()
  37. // 监听用户是否登录
  38. this.watchLogin();
  39. },
  40. // 监听用户是否登录
  41. watchLogin: function () {
  42. var that = this;
  43. wx.getStorage({
  44. key: 'token',
  45. success: res => {
  46. that.setData({
  47. type: res.data.type,
  48. user_id: res.data.id
  49. })
  50. //查询数据
  51. wx.request({
  52. url: `${app.globalData.publicUrl}/courtAdmin/api/team`, //接口地址
  53. method: 'get',
  54. data: '',
  55. success(res) {
  56. if (res.data.errcode == 0) {
  57. let datas = res.data.data
  58. let user_id = that.data.user_id
  59. that.setData({
  60. teamlist: datas,
  61. });
  62. let arr = []
  63. for (let j = 0; j < datas.length; j++) {
  64. for (let i = 0; i < datas[j].members.length; i++) {
  65. arr.push(-1)
  66. if (user_id == datas[j].members[i].id) {
  67. arr[j]= j
  68. }
  69. }
  70. }
  71. that.setData({
  72. keyindex:arr,
  73. });
  74. } else {
  75. wx.showToast({
  76. title: res.data.errmsg,
  77. icon: 'none',
  78. duration: 2000
  79. })
  80. }
  81. }
  82. })
  83. },
  84. fail: res => {
  85. return wx.redirectTo({ url: '/pages/login/index', })
  86. }
  87. })
  88. },
  89. // 计算高度
  90. searchHeight: function () {
  91. let frameStyle = this.data.frameStyle;
  92. let client = app.globalData.client;
  93. let infoHeight = client.windowHeight;
  94. // 是否去掉状态栏
  95. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  96. // 是否减去底部菜单
  97. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  98. if (infoHeight) this.setData({ infoHeight: infoHeight })
  99. },
  100. /**
  101. * 生命周期函数--监听页面初次渲染完成
  102. */
  103. onReady: function () {
  104. },
  105. /**
  106. * 生命周期函数--监听页面显示
  107. */
  108. onShow: function () {
  109. },
  110. /**
  111. * 生命周期函数--监听页面隐藏
  112. */
  113. onHide: function () {
  114. },
  115. /**
  116. * 生命周期函数--监听页面卸载
  117. */
  118. onUnload: function () {
  119. },
  120. /**
  121. * 页面相关事件处理函数--监听用户下拉动作
  122. */
  123. onPullDownRefresh: function () {
  124. },
  125. /**
  126. * 页面上拉触底事件的处理函数
  127. */
  128. onReachBottom: function () {
  129. },
  130. /**
  131. * 用户点击右上角分享
  132. */
  133. onShareAppMessage: function () {
  134. }
  135. })