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() } })