export default {
    data() {
        return {
            isList: true
        };
    },
    methods: {
        like(info) {
            this.checkLogin().then(() => {
                if (!info.follow) {
                    this.$http.get(`/user/${info.id}/follow`).then(res => {
                        this.$message.success('关注成功');
                        this.changeInfo({
                            ...info,
                            follow: true,
                            followers: info.followers + 1
                        });
                    });
                } else {
                    this.$http.get(`/user/${info.id}/unfollow`).then(() => {
                        this.$message.success('取消关注');
                        this.changeInfo({
                            ...info,
                            follow: false,
                            followers: info.followers - 1
                        });
                    });
                }
            });
        },
        changeInfo(info) {
            if (this.isList) {
                let list = [...this.list];

                list.forEach((item, index) => {
                    if (item.id == info.id) {
                        list[index] = info;
                    }
                });

                this.list = list;
                this.$store.dispatch('getUserInfo');
            } else {
                this.getDetail();
            }
        }
    }
};
