var articleSide = new Vue({
    el: '#articleSide',
    data: {
        typeId: 0,
        labelId: 0,
        labelTxt: '',
        labelList: [],
        recommend: {},
        adList: [],
    },
    methods: {
        getLabels: function(){
            var _self = this;
            $.getJSON("/article/labels", function (r) {
                if (r.code === 0 && r.data) {
                    _self.labelList = r.data;
                    _self.labelList.map(function(item){
                        if (_self.labelId === item.id) {
                            _self.labelTxt = item.name;
                            $("#labelTxt").text(_self.labelTxt);
                        }
                    })
                }
            });
        },
        getRecommend: function(typeId, pageNum){
            var _self = this;
            $.getJSON("/article/recommend",{
                typeId: typeId,
                pageNum: pageNum
            }, function (r) {
                if (r.code === 0 && r.data) {
                    _self.recommend= r.data;
                }
            });
        },
        getAds: function(){
            var _self = this;
            $.getJSON("/article/ads", function (r) {
                if (r.code === 0 && r.data) {
                    _self.adList = r.data;
                }
            });
        },
        labelInfo: function(labelId, jumpStatus, link) {
            $.getJSON("/article/label/click", {id: labelId}, function (r) {
                if (jumpStatus && jumpStatus*1 === 1 && link) {
                    window.location.href = link;
                } else {
                    window.location.href = '/info/label-' + labelId + '-1.html';
                }
            });
        },
        clickAD: function(id, link){
            $.getJSON("/article/ad/click", {id: id}, function (r) {
                window.open(link);
            });
        },
    },
    mounted: function () {
        this.typeId = $("#typeId").val()*1;
        this.labelId = $("#labelId").val()*1;
        this.getLabels();
        if (isPC) {
            this.getRecommend(this.typeId, 1);
            this.getAds();
        }

    }
});
