import config from '../data/config';
import socket from "$utils/socket";
import {NoticeType} from "$utils/socket/const";
import FriendsType from "$views/view-friends/const/type";
import followEntrust, {EntrustType} from '$utils/request/entrust';
import personDetail, {OpenType} from '$utils/control/personal-detail';

export default <LibMixins>{

    computed:{
        config(){
            return config[this.type];
        }
    },

    methods:{
        fetch(obj){
            return this.$request({
                url:  this.config.url,
                token:true,
                page:obj.data,
                entrust:followEntrust.getEntrust(this.type===FriendsType.follow ? EntrustType.follow : EntrustType.fans)
            }).then((data)=>{
                return obj.success(data.data);
            }).catch(obj.fail);
        },

        openDetail(item){

            if (item.uid) {

                return personDetail.openDetail(item,OpenType.user);
            }

        }
    },

    created() {

        if (this.type === FriendsType.follow) {
            socket.on('home-follow-user',(params)=>{

                if (params.uid) {
                    if (params.status) {
                        this.$refs.flat && this.$refs.flat.flat_unshift(params.uid,params.followUserInfo);
                    } else {
                        this.$refs.flat && this.$refs.flat.flat_delete(params.uid);
                    }
                }

            },NoticeType.follow);
        }

    },

    beforeUnmount() {
        if (this.type === FriendsType.follow){
            socket.off('my-follow-user',NoticeType.follow);
        }
    }

}
