index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. 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: 'user',
  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 memberList = []
  125. for (const val of res.data.member) {
  126. let arr = await app.$api(`user/${val}`, 'GET', {})
  127. if (arr.errcode == '0') {
  128. memberList.push({ _id: val, name: arr.data.name, icon: arr.data.icon })
  129. }
  130. }
  131. let data = memberList.find(i => i._id === that.data.user._id)
  132. if (data) that.setData({ is_apply: false })
  133. that.setData({ memberList })
  134. res.data.admin_name = that.getDict(res.data.administrator, 'admin')
  135. that.setData({ info: res.data })
  136. }
  137. },
  138. /**
  139. * 生命周期函数--监听页面初次渲染完成
  140. */
  141. onReady() {
  142. },
  143. /**
  144. * 生命周期函数--监听页面显示
  145. */
  146. onShow() {
  147. },
  148. /**
  149. * 生命周期函数--监听页面隐藏
  150. */
  151. onHide() {
  152. },
  153. /**
  154. * 生命周期函数--监听页面卸载
  155. */
  156. onUnload() {
  157. },
  158. /**
  159. * 页面相关事件处理函数--监听用户下拉动作
  160. */
  161. onPullDownRefresh() {
  162. },
  163. /**
  164. * 页面上拉触底事件的处理函数
  165. */
  166. onReachBottom() {
  167. },
  168. /**
  169. * 用户点击右上角分享
  170. */
  171. onShareAppMessage() {
  172. }
  173. })