/*var articleTypeNav = new Swiper('#articleTypeNav');*/
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;
                }
            });
        },
        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();
        }
        if (this.labelId>0) {
            // 添加一个标签点击量
            $.get("/article/label/click", {id: this.labelId}, function(res){
                console.log(res);
            });
        }

    }
});
