index.js 3.1 KB

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