index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. const app = getApp()
  2. const moment = require("../../utils/moment.min");
  3. Page({
  4. data: {
  5. id: "",
  6. log: '',
  7. info: {},
  8. user: {},
  9. adminList: [],
  10. is_apply: true
  11. },
  12. // 申请加入团队
  13. async toAdd() {
  14. const that = this;
  15. let user = {}
  16. let arr = await app.$api(`user/${that.data.user._id}`, 'GET', {})
  17. if (arr.errcode == '0') {
  18. if (arr.data.name && arr.data.icon.length > 0) user = arr.data
  19. else {
  20. wx.showToast({ title: `请维护基础信息`, icon: 'none' });
  21. return
  22. }
  23. } else {
  24. wx.showToast({ title: `请维护基础信息`, icon: 'none' });
  25. return
  26. }
  27. const info = that.data.info
  28. const data = {
  29. team_id: info._id,
  30. team_name: info.name,
  31. apply_id: user._id,
  32. apply_name: user.name,
  33. apply_time: moment().format('YYYY-MM-DD HH:mm:ss')
  34. }
  35. let res = await app.$api(`teamApply`, 'POST', data);
  36. if (res.errcode == '0') {
  37. wx.showToast({ title: `申请加入团队成功`, icon: 'none' });
  38. that.search()
  39. } else {
  40. wx.showToast({ title: `${res.errmsg}`, icon: 'none' });
  41. }
  42. },
  43. // 退出团队
  44. async toOut() {
  45. const that = this;
  46. const memberList = that.data.info.member.filter(i => i._id !== that.data.user._id)
  47. const number = memberList.length.toString()
  48. const data = { member: memberList, number: number }
  49. let res = await app.$api(`team/${that.data.info._id}`, 'POST', data);
  50. if (res.errcode == '0') {
  51. that.setData({ is_apply: true })
  52. // 退出把申请都删掉
  53. await app.$api(`teamApply/out`, 'GET', { apply_id: that.data.user._id });
  54. wx.showToast({ title: `退出团队成功`, icon: 'success' });
  55. that.search()
  56. } else {
  57. wx.showToast({ title: `${res.errmsg}`, icon: 'none' });
  58. }
  59. },
  60. // 字典
  61. getDict(value, model) {
  62. const that = this;
  63. if (model == 'admin') {
  64. if (value) {
  65. let data = that.data.adminList.find(i => i._id == value)
  66. if (data) return data.name
  67. else return '暂无'
  68. }
  69. }
  70. },
  71. /**
  72. * 生命周期函数--监听页面加载
  73. */
  74. async onLoad(options) {
  75. const that = this;
  76. that.setData({ id: options.id });
  77. wx.showLoading({ title: '加载中', mask: true })
  78. await that.searchConfig()
  79. await that.searchOther()
  80. await that.search()
  81. wx.hideLoading()
  82. },
  83. async searchConfig() {
  84. const that = this;
  85. wx.getStorage({
  86. key: 'config',
  87. async success(res) {
  88. // logo
  89. if (res.data && res.data.logo_url && res.data.logo_url.length > 0) {
  90. let logo = res.data.logo_url[0].url
  91. that.setData({ logo })
  92. }
  93. },
  94. fail(err) {
  95. console.log(err);
  96. }
  97. })
  98. wx.getStorage({
  99. key: 'token',
  100. async success(res) {
  101. that.setData({ user: res.data })
  102. },
  103. fail(err) {
  104. console.log(err);
  105. }
  106. })
  107. },
  108. // 查询其他信息
  109. async searchOther() {
  110. const that = this;
  111. let res;
  112. res = await app.$api('user', 'GET', { status: '1', type: '1' })
  113. if (res.errcode == '0') that.setData({ adminList: res.data })
  114. },
  115. // 查询通知
  116. async search() {
  117. const that = this;
  118. let res = await app.$api(`team/${that.data.id}`, 'GET', {})
  119. if (res.errcode == '0') {
  120. let data = res.data.member.find(i => i._id === that.data.user._id)
  121. if (data) that.setData({ is_apply: false })
  122. res.data.admin_name = that.getDict(res.data.administrator, 'admin')
  123. that.setData({ info: res.data })
  124. }
  125. },
  126. /**
  127. * 生命周期函数--监听页面初次渲染完成
  128. */
  129. onReady() {
  130. },
  131. /**
  132. * 生命周期函数--监听页面显示
  133. */
  134. onShow() {
  135. },
  136. /**
  137. * 生命周期函数--监听页面隐藏
  138. */
  139. onHide() {
  140. },
  141. /**
  142. * 生命周期函数--监听页面卸载
  143. */
  144. onUnload() {
  145. },
  146. /**
  147. * 页面相关事件处理函数--监听用户下拉动作
  148. */
  149. onPullDownRefresh() {
  150. },
  151. /**
  152. * 页面上拉触底事件的处理函数
  153. */
  154. onReachBottom() {
  155. },
  156. /**
  157. * 用户点击右上角分享
  158. */
  159. onShareAppMessage() {
  160. }
  161. })