productdetail.js 2.4 KB

var goodid=GetQueryString("id");
			
new Vue({
	el:'#productsdetail',
	//商品详情信息
	data: {
		cartnum:0,
		banner:[],		
		good:[],
		
		

	},
	created: function() {
		this.details();
		this.num();
		
	},

	methods: {
        initSwiper(){
            var swiper = new Swiper('.swiper-container', {
                pagination: '.swiper-pagination',
                paginationClickable: true,
                observer:true, //修改swiper自己或子元素时,自动初始化swiper
                observeParents:true//修改swiper的父元素时,自动初始化swiper
            });
        },
		//获取信息
		details: function() {
			var that = this;
			var url = '/Goods/goodsDetail'
			var params = {
				goods_id: goodid
				
			}
			ajaxsend(url, params, function(res) {
				/*console.log(JSON.stringify(res))*/
				console.log(res);
				var data=res.data;
				that.banner=data.banner;
				console.log(that.banner);

                setTimeout(()=>{
                    that.initSwiper()

                },1500)
				var mySwiper = new Swiper('.swiper-container', {
				pagination: '.swiper-pagination',
				paginationType: 'bullets',
				autoPlay: true 
				});
				
				
				that.good=data;
				console.log(that.good)
				
										
			})
		},
		//购物车的数量
		num:function(){
			var that=this;
			var url='/CountNum/countCart';
	   		var params = {	
	   			unique_id: localStorage.getItem('unique_id')
				
			}
	   		ajaxsend(url, params, function(res) {
				/*console.log(JSON.stringify(res))*/
				console.log(res);
				var data=res.data;
				console.log(data[0].count);
				that.cartnum=data[0].count;
				console.log(that.cartnum)
							
			})
		},
		
		//加入购物车
		addcart:function(){
			var that=this;
			var num=1;	   			   		
	   		var url='/Cart/add';
	   		var params = {	
	   			goods_id:goodid,
				unique_id: localStorage.getItem('unique_id'),
				goods_num:num
				
			}
	   		ajaxsend(url, params, function(res) {
				/*console.log(JSON.stringify(res))*/
				console.log(res);
				if(res.state=="success"){
					alert("添加成功");
					window.location.reload();
				}else if(res.state=="fail"){
					alert("库存不足");
				}
								
			})
		},
		//商品评论列表
		commentlist:function(){
			window.location.href = linkPath+'/myorder/evaluateList.html?goodid='+goodid;
		},
		//进入购物车页面
		gocart:function(){
			window.location.href = linkPath+'/shopcar.html?goodid='+goodid;
		}
		
		
	},
	
	
})