123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- import {
- getOtherUser,
- setFans
- } from '~/api/user';
- import event from '~/mixins/event'
- import reachBottom from '~/mixins/reachBottom';
- Page({
- behaviors: [reachBottom, event],
- data: {
- text: '',
- placeholderText:'查找昵称/学号/手机号',
- historySearch: [],
- localUid: wx.getStorageSync('uid')
- },
- onShow() {
- // isEachOther 是否互相关注 isFans是否被关注 isFansOther是否关注别人
- this.setData({
- historySearch: wx.getStorageSync('userSearch')
- });
- this.resetData();
- },
- setSearch({
- detail
- }) {
- if (!detail.value) {
- this.setData({
- nullList: false,
- list: []
- });
- }
- 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, 20)
- });
- }
- 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, 20)
- });
- wx.setStorageSync('userSearch', this.data.historySearch);
- },
- clearHistory() {
- wx.showModal({
- title: '温馨提示',
- content: '历史记录清除后无法恢复,是否清除全部记录',
- success: res => {
- if (res.confirm) {
- this.setData({
- historySearch: []
- });
- wx.setStorageSync('search', 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'
- });
- }
- },
- sendMsg({
- currentTarget
- }) {
- let user = currentTarget.dataset.user
- let {
- nickName,
- eid,
- uid
- } = user
- if (this.data.localUid == uid) {
- return wx.showToast({
- title: '不可以给自己发私信哦~',
- icon: 'none'
- })
- }
- wx.navigateTo({
- url: `/pages/chat/index?title=${nickName||eid}&uid=${uid}`,
- })
- },
- clipboar({
- currentTarget
- }) {
- wx.setClipboardData({
- data: currentTarget.dataset.eid,
- success: function (res) { //成功回调函数
- wx.showToast({
- title: '已复制',
- icon: "none"
- })
- }
- })
- },
- cleanPlaceholder() {
- this.setData({
- placeholderText: ''
- })
- },
- setPlaceholder() {
- this.setData({
- placeholderText: '请输入搜索内容'
- })
- },
- onReachBottom() {
- this.loadMore();
- }
- });
|