var productDetail = new Vue({
    el: "#productDetail",
    data: {
        productId: 0,
        userId: 6,
        userIdentity: '',
        images: [],
        price: 564,
        priceFlag: 2,
        recommendType: 1,
        recommendPage: 1,
        recommends: [],
        parameters: [],

    },
    computed: {},
    methods: {
        getImages: function(){
            var _self = this;
            if(this.productId ===0){return;}
            $.getJSON("/product/images",{productId: this.productId}).done(function (r) {
                if (r.code === 0 && r.data) {
                    _self.images = r.data;
                    setTimeout(function(){
                        if (isPC) {
                            var magnifier = new ImageMagnifier(
                                '#imgShown .smallImage li'
                                ,'#imgShown .bigImage'
                                ,'#imgShown .zoomImage'
                                ,'#imgShown .mask'
                                ,'#imgShown .zoom'
                                ,"on"
                            ).init();
                        } else {
                            var swiper = new Swiper('#swiperImage', {
                                loop : true,
                                autoplay: {
                                    delay: 2000,
                                    disableOnInteraction: false
                                },
                                pagination: {
                                    el: '.swiper-pagination',
                                    type: 'fraction'
                                }
                            });
                        }
                    },500);
                }
            });
        },
        getRecommends: function(){
            var _self = this;
            if(this.productId ===0){return;}
            $.getJSON("/product/recommend",{
                productId: this.productId,
                recommendType: this.recommendType
            }).done(function (r) {
                if (r.code === 0 && r.data) {
                    _self.recommends = r.data;
                    _self.recommendPage = Math.ceil(r.data.length / 7);
                    setTimeout(function(){
                        if (isPC) {
                            $('#productRecommend').slide({
                                mainCell:".swiper-wrapper"
                                ,titCell:".swiper-pagination span"
                                ,effect: "leftLoop"
                                ,interTime: 3000
                                ,autoPlay: true
                                ,scroll:7
                                ,vis:7
                                ,trigger: "mouseover"
                            });
                        } else {
                            var swiper = new Swiper('#productRecommend', {
                                slidesPerView: 3,
                                freeMode: true,
                                spaceBetween: 0
                            });
                        }
                    },500);
                }
            });
        },
        getParameters: function(){
            var _self = this;
            if(this.productId ===0){return;}
            $.getJSON("/product/parameter",{
                productId: this.productId
            }).done(function (r) {
                if (r.code === 0 && r.data) {
                    _self.parameters = r.data;
                }
            });
        },
    },
    created: function () {
        this.productId = getUrlParam("id") ? getUrlParam("id")*1 : 0;
        var userInfo = localStorage.getItem('userInfo');
        if(userInfo){
            this.userId = JSON.parse(userInfo).userId*1;
        }
        this.getImages();
    },
    mounted: function () {
        this.getRecommends();
        $('.productInfo').slide({
            mainCell:".tabCon"
            ,titCell:".tabTit span"
            ,trigger: "click"
        });
    }
});
