import { MainColorType } from "@/context/themes/color"; import { followUser, getMyFollowers, getMyFollowings, getMyFriends } from "@/services/friend"; import { View, Image, Text, ScrollView } from "@tarojs/components"; import { useEffect, useState } from "react"; import './relation.scss' import NewButton, { NewButtonType } from "@/_health/base/new_button"; import { rpxToPx } from "@/utils/tools"; import { jumpPage } from "@/features/trackTimeDuration/hooks/Common"; import { IconArrow } from "@/components/basic/Icons"; import Taro from "@tarojs/taro"; import NoRecord from "@/_health/components/no_record"; export default function Relation() { const [count, setCount] = useState(0) const [count2, setCount2] = useState(0) const [count3, setCount3] = useState(0) const [friends, setFriends] = useState([]) const [followers, setFollowers] = useState([]) const [followings, setFollowings] = useState([]) const [index, setIndex] = useState(0) const [list, setList] = useState([]) const [loaded, setLoaded] = useState(false) const [page, setPage] = useState(1) const [isPulling, setIsPulling] = useState(false) const [isLoading, setIsLoading] = useState(false) const [total, setTotal] = useState(-1) useEffect(() => { // getRelation() // getFollowers() // getFollowings() Taro.eventCenter.on('followUser', listenFollowUser) Taro.eventCenter.on('unfollowUser', listenUnfollowUser) setPage(1) getList(1) return () => { // Taro.eventCenter.off('followUser') // Taro.eventCenter.off('unfollowUser') } }, []) useEffect(() => { setPage(1) getList(1) }, [index]) function getList(i) { setPage(i) if (index == 0) { getRelation(i) } else if (index == 1) { getFollowings(i) } else { getFollowers(i) } } function onRefresh() { setIsPulling(true) setPage(1) getList(1) } function more() { if (isLoading) return if (total == list.length) return var i = page + 1 getList(i) } function listenFollowUser(e) { console.log('follow user', e) // getRelation() // getFollowers() // getFollowings() getList(1) } function listenUnfollowUser(e) { console.log('unfollow user', e) // getRelation() // getFollowers() // getFollowings() getList(1) } function getRelation(i) { setPage(i) setIsLoading(true) getMyFriends({ page: i, limit: 20 }).then(res => { setIsLoading(false) setLoaded(true) setIsPulling(false) setCount((res as any).total) // setFriends((res as any).data) if (i == 1) { setList((res as any).data) } else { setList([...list, ...(res as any).data]) } }).catch(e => { setIsLoading(false) setLoaded(true) setIsPulling(false) }) } function getFollowers(i) { setPage(i) setIsLoading(true) getMyFollowers({ page: i, limit: 20 }).then(res => { setIsLoading(false) setLoaded(true) setIsPulling(false) setCount((res as any).total) // setFollowers((res as any).data) if (i == 1) { setList((res as any).data) } else { setList([...list, ...(res as any).data]) } }).catch(e => { setIsLoading(false) setLoaded(true) setIsPulling(false) }) } function getFollowings(i) { setPage(i) setIsLoading(true) getMyFollowings({ page: i, limit: 20 }).then(res => { setIsLoading(false) setLoaded(true) setIsPulling(false) setCount((res as any).total) // setFollowings((res as any).data) if (i == 1) { setList((res as any).data) } else { setList([...list, ...(res as any).data]) } }).catch(e => { setIsLoading(false) setLoaded(true) setIsPulling(false) }) } function friendsList() { return {/* 好友数量{count} */} { friends.map((item, index) => { return followItem(item, index * 1000) }) } } function followerList() { return {/* 我的关注{count2} */} { followers.map((item, index) => { return followItem(item, index * 1000) }) } } function followingList() { return {/* 我的粉丝{count3} */} { followings.map((item, index) => { return followItem(item, index) }) } } function userList() { return {/* 我的粉丝{count3} */} { list.map((item, index) => { return followItem(item, index) }) } } function tapFollow(item) { var params: any = { follow_origin: 'WECHAT_PRIVATE_CHAT', user_id: item.id, } followUser(params).then(res => { // getProfile() Taro.eventCenter.trigger('followUser', item.id) debugger }) } function followItem(item, index) { return { jumpPage('./home?uid=' + item.id) }}> {item.nickname} {/* {item.relation} */} { item.relation == 'FRIEND' && Friend } { item.relation == 'FOLLOWING' && Following } { item.relation == 'FOLLOWER' && { tapFollow(item) }} /> } } function onScroll() { } // if (loaded && list.length == 0) // return return { }} onScrollToLower={more} > { setIndex(0) }}>搭子 { setIndex(1) }}>关注 { setIndex(2) }}>粉丝 { userList() } { loaded && list.length == 0 && } {/* { index == 0 && friendsList() } { index == 1 && followingList() } { index == 2 && followerList() } */} }