export default {
    methods: {
        like(info) {
            this.checkLogin().then(() => {
                this.$toast.loading({
                    message: '加载中...',
                    forbidClick: true
                });
                if (!info.liked) {
                    this.$http
                        .get(`/newsLike/${info.id}/likeRoom/`)
                        .then(() => {
                            if (this.getDetail) {
                                this.getDetail({
                                    ...info,
                                    liked: true
                                });
                            }
                            this.$toast.success('点赞成功');
                        })
                        .catch(() => {
                            this.$toast.clear();
                        });
                } else {
                    this.$http
                        .get(`/newsLike/${info.id}/unlikeRoom/`)
                        .then(() => {
                            if (this.getDetail) {
                                this.getDetail({
                                    ...info,
                                    liked: false
                                });
                            }
                            this.$toast.success('取消成功');
                        })
                        .catch(() => {
                            this.$toast.clear();
                        });
                }
            });
        }
    }
};
