index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. const app = getApp()
  2. const moment = require("../../utils/moment.min")
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. frameStyle: { useTop: true, name: '查询团队', leftArrow: false, useBar: true },
  9. // 主体高度
  10. infoHeight: '',
  11. // 用户
  12. user: {},
  13. list: [],
  14. },
  15. back: function () {
  16. wx.navigateBack({ url: '/pages/home/index' })
  17. },
  18. tabPath: function (e) {
  19. let { route } = e.detail.detail;
  20. if (route) wx.redirectTo({ url: `/${route}` })
  21. },
  22. // 系统团队查看详情
  23. toView: function (e) {
  24. let { id } = e.currentTarget.dataset;
  25. wx.navigateTo({ url: `/pages/teamInfo/info?id=${id}` })
  26. },
  27. // 申请加入队伍
  28. toJoin: function (e) {
  29. const that = this;
  30. const user = that.data.user;
  31. let { item } = e.currentTarget.dataset;
  32. wx.showModal({
  33. title: '是否确认申请加入该支团队?',
  34. async success(res) {
  35. if (res.confirm) {
  36. let obj = { team_id: item._id, team_name: item.name, apply_time: moment().format('YYYY-MM-DD HH:mm:ss'), apply_user: user.nickname, apply_id: user._id }
  37. const arr = await app.$post(`/courtAdmin/api/joinapply`, obj)
  38. if (arr.errcode == '0') { wx.showToast({ title: `成功,等待审核`, icon: 'success', duration: 2000 }); that.watchLogin() }
  39. else wx.showToast({ title: `${arr.errmsg}`, icon: 'error', duration: 2000 })
  40. } else if (res.cancel) {
  41. }
  42. }
  43. })
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad: function (options) {
  49. // 计算高度
  50. this.searchHeight();
  51. // 监听用户是否登录
  52. this.watchLogin();
  53. },
  54. // 监听用户是否登录
  55. watchLogin: async function () {
  56. const that = this;
  57. wx.getStorage({
  58. key: 'token',
  59. success: async res => {
  60. that.setData({ user: res.data })
  61. const arr = await app.$get(`/courtAdmin/api/team`, { status: '1' });
  62. if (arr.errcode == '0') {
  63. let list = arr.data;
  64. // 个人用户判断当前用户是否为团队成员
  65. if (res.data.type == '2') {
  66. for (const val of list) {
  67. let is_membes = val.members.find((i) => i.user_id == res.data._id);
  68. if (is_membes) val.is_membes = false
  69. else val.is_membes = true;
  70. }
  71. }
  72. that.setData({ list: list })
  73. } else {
  74. wx.showToast({ title: arr.errmsg, icon: 'error', duration: 2000 })
  75. }
  76. },
  77. fail: res => {
  78. wx.redirectTo({ url: '/pages/index/index', })
  79. }
  80. })
  81. },
  82. // 计算高度
  83. searchHeight: function () {
  84. let frameStyle = this.data.frameStyle;
  85. let client = app.globalData.client;
  86. let infoHeight = client.windowHeight;
  87. // 是否去掉状态栏
  88. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  89. // 是否减去底部菜单
  90. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  91. if (infoHeight) this.setData({ infoHeight: infoHeight })
  92. },
  93. /**
  94. * 生命周期函数--监听页面初次渲染完成
  95. */
  96. onReady: function () {
  97. },
  98. /**
  99. * 生命周期函数--监听页面显示
  100. */
  101. onShow: function () {
  102. },
  103. /**
  104. * 生命周期函数--监听页面隐藏
  105. */
  106. onHide: function () {
  107. },
  108. /**
  109. * 生命周期函数--监听页面卸载
  110. */
  111. onUnload: function () {
  112. },
  113. /**
  114. * 页面相关事件处理函数--监听用户下拉动作
  115. */
  116. onPullDownRefresh: function () {
  117. },
  118. /**
  119. * 页面上拉触底事件的处理函数
  120. */
  121. onReachBottom: function () {
  122. },
  123. /**
  124. * 用户点击右上角分享
  125. */
  126. onShareAppMessage: function () {
  127. }
  128. })