index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import {
  2. getOtherUser,
  3. setFans
  4. } from '~/api/user';
  5. import event from '~/mixins/event'
  6. import reachBottom from '~/mixins/reachBottom';
  7. Page({
  8. behaviors: [reachBottom,event],
  9. data: {
  10. text: '',
  11. historySearch: [],
  12. localUid: wx.getStorageSync('uid')
  13. },
  14. onShow() {
  15. // isEachOther 是否互相关注 isFans是否被关注 isFansOther是否关注别人
  16. this.setData({
  17. historySearch: wx.getStorageSync('userSearch')
  18. });
  19. this.resetData();
  20. },
  21. setSearch({
  22. detail
  23. }) {
  24. if (!detail.value) {
  25. this.setData({
  26. nullList: false,
  27. list: []
  28. });
  29. }
  30. this.setData({
  31. text: detail.value
  32. });
  33. },
  34. searchUser({
  35. currentTarget
  36. }) {
  37. if (currentTarget.dataset.text) {
  38. this.setData({
  39. text: currentTarget.dataset.text
  40. });
  41. }
  42. if (!this.data.text) {
  43. this.setData({
  44. list: []
  45. });
  46. return;
  47. }
  48. this.resetData();
  49. if (!this.data.historySearch.includes(this.data.text)) {
  50. this.setData({
  51. historySearch: [this.data.text, ...this.data.historySearch].slice(0, 20)
  52. });
  53. }
  54. wx.setStorageSync('userSearch', this.data.historySearch);
  55. },
  56. deleteHistory({
  57. currentTarget
  58. }) {
  59. let newList = this.data.historySearch.filter(item => {
  60. return item != currentTarget.dataset.text;
  61. });
  62. this.setData({
  63. historySearch: newList.slice(0, 20)
  64. });
  65. wx.setStorageSync('userSearch', this.data.historySearch);
  66. },
  67. clearHistory() {
  68. wx.showModal({
  69. title: '温馨提示',
  70. content: '历史记录清除后无法恢复,是否清除全部记录',
  71. success: res => {
  72. if (res.confirm) {
  73. this.setData({
  74. historySearch: []
  75. });
  76. wx.setStorageSync('search', this.data.historySearch);
  77. }
  78. }
  79. });
  80. },
  81. loadMore() {
  82. if (!this.data.text) {
  83. return;
  84. }
  85. this.getData(getOtherUser, {
  86. query: this.data.text
  87. });
  88. },
  89. jumpUserInfo({
  90. currentTarget
  91. }) {
  92. let uid = currentTarget.dataset.uid;
  93. wx.navigateTo({
  94. url: `/pages/personal/index?uid=${uid}`
  95. });
  96. },
  97. async setFans({
  98. currentTarget
  99. }) {
  100. if (!currentTarget.dataset.iseachother) {
  101. await setFans({
  102. uid: currentTarget.dataset.uid
  103. });
  104. let listCopy = JSON.parse(JSON.stringify(this.data.list));
  105. listCopy.forEach(item => {
  106. if (item.uid == currentTarget.dataset.uid) {
  107. item.isEachOther = true;
  108. }
  109. });
  110. this.setData({
  111. list: listCopy
  112. });
  113. wx.showToast({
  114. title: '已关注',
  115. icon: 'none'
  116. });
  117. }
  118. },
  119. sendMsg({
  120. currentTarget
  121. }) {
  122. let user = currentTarget.dataset.user
  123. let {
  124. nickName,
  125. eid,
  126. uid
  127. } = user
  128. if (this.data.localUid == uid) {
  129. return wx.showToast({
  130. title: '不可以给自己发私信哦~',
  131. icon: 'none'
  132. })
  133. }
  134. wx.navigateTo({
  135. url: `/pages/chat/index?title=${nickName||eid}&uid=${uid}`,
  136. })
  137. },
  138. clipboar({
  139. currentTarget
  140. }) {
  141. wx.setClipboardData({
  142. data: currentTarget.dataset.eid,
  143. success: function (res) { //成功回调函数
  144. wx.showToast({
  145. title: '已复制',
  146. icon: "none"
  147. })
  148. }
  149. })
  150. },
  151. onReachBottom() {
  152. this.loadMore();
  153. }
  154. });