index.js 5.2 KB

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