var supplierHome = new Vue({
    el: "#supplierHome",
    data: {
        userId: 0,
        supplierId: 0,
        supplierBanner: [],
        mainProducts:[],
        productLists:[]
    },
    computed: {

    },
    methods: {
        getBanners: function(){
            var _self = this;
            $.getJSON("/supplier/images",{supplierId: this.supplierId}).done(function (r) {
                if (r.code === 0 && r.data) {
                    _self.supplierBanner = r.data;
                    setTimeout(function(){
                        if (isPC) {
                            $('#supplierBanner').slide({
                                mainCell:".swiper-wrapper"
                                ,titCell:".swiper-pagination span"
                                ,effect: "leftLoop"
                                ,prevCell:".swiper-button-prev"
		                        ,nextCell:".swiper-button-next"
                                ,interTime: 2000
                                ,autoPlay: true
                                ,autoPage: false
                                ,trigger: "mouseover"
                            });
                        } else {
                            var swiper = new Swiper('#supplierBanner', {
                                loop : true,
                                autoplay: {
                                    delay: 2000,
                                    disableOnInteraction: false
                                },
                                navigation: {
                                    nextEl: '.swiper-button-next',
                                    prevEl: '.swiper-button-prev'
                                },
                                pagination: {
                                    el: '.swiper-pagination',
                                    clickable :true
                                }
                            });
                        }
                    },500);
                }
            });
        },
        getMainProducts: function(){
            var _self = this;
            $.getJSON("/supplier/products",{supplierId: this.supplierId}).done(function (r) {
                if (r.code === 0 && r.data) {
                    if(_self.userId && _self.userId>0){
                        setProductPrice(r.data, _self.userId, function(){});
                    }
                    _self.mainProducts = r.data;
                }
            });
        },
        getProductLists: function(){
            var _self = this;
            $.getJSON(spiServer+"/search/query/product/shop",{
                id: this.supplierId,
                pageSize: 12,
                pageNum: 1
            }, function (r) {
                if (r.code === 0 && r.data) {
                    var result = JSON.parse(r.data);
                    _self.listRecord = result.total;
                    if(_self.userId && _self.userId>0){
                        setProductPrice(result.items, _self.userId, function(){});
                    }
                    _self.productLists = _self.productLists.concat(result.items);
                }
            })
        }
    },
    created: function () {
        this.supplierId = getUrlParam("id") ? getUrlParam("id") * 1 : 0;
        if(this.supplierId !== 0) {
            this.getBanners();
            this.getMainProducts();
            this.getProductLists();
        }
    },
    mounted: function () {
        var _self = this;
        $('.supplierInfo').slide({
            mainCell:".tabCon"
            ,titCell:".tabTit span"
            ,trigger: "click"
        });
        $('body').on("click", '.showSearch', function(){
            $('.supplierTit .search').show();
        })
    }
});
