123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import {
- getOtherUser,
- setFans
- } from '~/api/user'
- import reachBottom from '~/mixins/reachBottom'
- Page({
- behaviors: [reachBottom],
- data: {
- text: '',
- historySearch: []
- },
- onShow() {
- this.setData({
- historySearch: wx.getStorageSync('userSearch')
- })
- this.resetData()
- },
- setSearch({
- detail
- }) {
- if (!detail.value) {
- this.setData({
- nullList: false
- })
- }
- this.setData({
- text: detail.value
- })
- },
- searchUser({
- currentTarget
- }) {
- if (currentTarget.dataset.text) {
- this.setData({
- text: currentTarget.dataset.text
- })
- }
- if (!this.data.text) {
- this.setData({
- list: [],
- })
- return
- }
- this.resetData()
- if (!this.data.historySearch.includes(this.data.text)) {
- this.setData({
- historySearch: [this.data.text, ...this.data.historySearch].slice(0, 10)
- })
- }
- wx.setStorageSync('userSearch', this.data.historySearch)
- },
- deleteHistory({
- currentTarget
- }) {
- let newList = this.data.historySearch.filter(item => {
- return item != currentTarget.dataset.text
- })
- this.setData({
- historySearch: newList.slice(0, 10)
- })
- wx.setStorageSync('userSearch', this.data.historySearch)
- },
- loadMore() {
- if (!this.data.text) {
- return
- }
- this.getData(getOtherUser, {
- query: this.data.text,
- })
- },
- jumpUserInfo({
- currentTarget
- }) {
- let uid = currentTarget.dataset.uid
- wx.navigateTo({
- url: `/pages/personal/index?uid=${uid}`,
- })
- },
- async setFans({
- currentTarget
- }) {
- if (!currentTarget.dataset.iseachother) {
- await setFans({
- uid: currentTarget.dataset.uid
- })
- let listCopy = JSON.parse(JSON.stringify(this.data.list))
- listCopy.forEach(item => {
- if (item.uid == currentTarget.dataset.uid) {
- item.isEachOther = true
- }
- })
- this.setData({
- list: listCopy
- })
- wx.showToast({
- title: '已关注',
- icon: 'none'
- })
- }
- },
- onReachBottom() {
- this.loadMore()
- }
- })
|