index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import {
  2. getOtherUser
  3. } from '~/api/user'
  4. import reachBottom from '~/mixins/reachBottom'
  5. Page({
  6. behaviors: [reachBottom],
  7. data: {
  8. text: '',
  9. historySearch: []
  10. },
  11. onShow() {
  12. this.setData({
  13. historySearch: wx.getStorageSync('userSearch')
  14. })
  15. this.resetData()
  16. },
  17. setSearch({
  18. detail
  19. }) {
  20. this.setData({
  21. text: detail.value
  22. })
  23. },
  24. searchUser({
  25. currentTarget
  26. }) {
  27. if (currentTarget.dataset.text) {
  28. this.setData({
  29. text: currentTarget.dataset.text
  30. })
  31. }
  32. if (!this.data.text) {
  33. this.setData({
  34. list: [],
  35. })
  36. return
  37. }
  38. this.resetData()
  39. if (!this.data.historySearch.includes(this.data.text)) {
  40. this.setData({
  41. historySearch: [...this.data.historySearch, this.data.text].slice(-10)
  42. })
  43. }
  44. wx.setStorageSync('userSearch', this.data.historySearch)
  45. },
  46. deleteHistory({
  47. currentTarget
  48. }) {
  49. let newList = this.data.historySearch.filter(item => {
  50. return item != currentTarget.dataset.text
  51. })
  52. this.setData({
  53. historySearch: newList.slice(-10)
  54. })
  55. wx.setStorageSync('userSearch', newList.slice(-10))
  56. },
  57. loadMore() {
  58. if (!this.data.text) {
  59. return
  60. }
  61. this.getData(getOtherUser, {
  62. query: this.data.text,
  63. })
  64. },
  65. async setFans({
  66. currentTarget
  67. }) {
  68. let uid = currentTarget.dataset.uid
  69. wx.navigateTo({
  70. url: `/pages/personal/index?uid=${uid}`,
  71. })
  72. },
  73. onReachBottom() {
  74. this.loadMore()
  75. }
  76. })