index.js 5.2 KB

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