index.js 4.8 KB

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