var id=GetQueryString("id");

id=id.toString();
console.log(typeof(id));
console.log(id);
new Vue({
	el:'#order',
	data: {	
	cartListSelected:[],
	//自提点列表
	selfarea:[],
	//每个位置对应的地址
	spot:[],
	//地点选择
	//头部地点就近自提
	address:'',
	distance:'',
	//头部地点堂食地点
	storeaddress:'',
	storedistance:'',
	
	//食堂列表
	storelist:[],
	//自取点城市
	selfarea:[],
	//每个区域的具体自提
	spot:[],
	//就近自提地点
	nearest_spot:[],
	//就近堂食地点
	nearest_store:[],
	nearaddress:'',
	yespot:true,
	yestore:false,
	//微信支付
	weipay:false,
	remainpay:true,
	dc_list:[],
	printer:[],

	num:0,
	//填写的信息
	info:{
		name:'',
		tel:'',
		time:''
	},
	selectstop:true,
	selectstore:false,
	//备注
	remark:'',
	//遮罩层
	mask:false,
	spotblock:false,
	storeblock:false,
	
	//姓名
	name:'',
	//手机号
	telephone:'',
	//自提或堂食
	order_type:1,
	//余额支付或者微信支付
	payment:1,
	//优惠券的id
	discount_coupon_id:'',
	//打印机id
	printer_id:'',
    //定制时间
    time_zone:''
	
	},
	created: function() {
		this.details();
		this.addressinfo();
		this.store();
	},
	methods: {
		//获取信息
		details: function() {
			var that = this;
			//默认选中1号打印机
			var pr=$(".icon-weixuanzhongyuanquan");
			$(pr[0]).addClass("icon-xuanzhong");
			$(pr[0]).removeClass("icon-weixuanzhongyuanquan");
			var remark=localStorage.getItem('remark');
			//获取本地的就近自提点
			that.address=localStorage.getItem('spotaddress');
			//获取到店堂食的地址
			that.storeaddress=localStorage.getItem('storeaddress')
			that.remark=remark;
			//姓名
			that.name=localStorage.getItem('ordername');
			that.telephone=localStorage.getItem('orderphone');
			console.log(that.picktime);
			var url = '/Flow/confirm';
			var params = {
				cart_id_str:id,
				unique_id: localStorage.getItem('unique_id')
			}
			ajaxsend(url, params, function(res) {
				/*console.log(JSON.stringify(res))*/
				console.log(res);
				var data=res.data;
				var cartListSelected=data.cartListSelected;
				that.cartListSelected=cartListSelected;
				var dc_list=data.dc_list;
				that.dc_list=dc_list;
				console.log(dc_list);
				that.num=data.sum;
				that.printer=data.printer;
				console.log(that.printer);
				//默认第一个打印机的id
				console.log(that.printer[0])
				that.printer_id=that.printer[0].printer_id;

                that.time_zone=data.time_zone[0];
                //console.log(that.time_zone);

			})
		},

		//切换动作
		spotchange:function(){
			var that=this;
			that.selectstop=true;
			that.selectstore=false;
			that.order_type=1;
			
		},
		storechange:function(){
			var that=this;
			that.selectstop=false;
			that.selectstore=true;
			that.order_type=2;
		},
	//选择打印机
		selectprinter:function(obj,event){
		var that=this;
		var el = event.currentTarget;
		that.printer_id=obj.printer_id;
		$(el).addClass("icon-xuanzhong");
		$(el).parents(".printer").siblings(".printer").children(".iconfont").removeClass("icon-xuanzhong")
		//$(el).removeClass("icon-weixuanzhongyuanquan");
		console.log($(el))
		if(obj.status==true){
			$(el).addClass("icon-xuanzhong")
			$(el).removeClass("icon-weixuanzhongyuanquan")
		}
	},
	//自提点地址重置
	resetspot:function(){
		
		var that=this;
		that.mask=true;
		that.spotblock=true;
		
	},
	//堂食地点重置
	resetstore:function(){	
		var that=this;
		that.mask=true;
		that.storeblock=true;
		
	},
	
	//隐藏遮罩层
	mars:function(){
		
		var that=this;
		that.mask=false;
		that.spotblock=false;
		that.storblock=true;
	},
	
	//获取自提点信息
		addressinfo:function(){
			var that = this;
			var url = '/Spot/index'
			var params = {
				area_id: '',
				unique_id: localStorage.getItem('unique_id')
			}
			
			ajaxsend(url, params, function(res) {
				/*console.log(JSON.stringify(res))*/
				console.log(res);
				var data=res.data;
				var selfarea=data.area;
				that.selfarea=selfarea;
			})
		},
		//每个区域的自提点
		add:function(area_id){
			window.event.stopPropagation();
			var that=this;
			var areaid=area_id;					
			var url = '/Spot/index'
			var params = {
				area_id: areaid,
				unique_id: localStorage.getItem('unique_id')
			}
			
			ajaxsend(url, params, function(res) {
				/*console.log(JSON.stringify(res))*/
				console.log(res);
				var data=res.data;
				var spot=data.spot;
				that.spot=spot;
						
			})
		},
		//获取店铺列表
		store:function(){
			var that=this;
			var url = '/Store/storeList'
			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;
				that.storelist=data;

			})
		},
		//切换就近自提地点
		cartpay:function(obj){
			var that=this;	
			that.yespot=true;
			that.yestore=false;
			console.log(obj);
			that.address=obj.spot_name;
			that.distance=',距您'+obj.distance_text;
			localStorage.setItem('spot_id',obj.spot_id);
		},
		//切换食堂地点
		changespot:function(obj){
			var that=this;	
			that.yespot=false;
			that.yestore=true;
			console.log(obj);
			that.storeaddress=obj.store_address;
			that.storedistance=',距您'+obj.distance_text;
			localStorage.setItem('store_id',obj.store_id)
		},
		//选择期望地址
		hopeaddress:function(){
			window.event.stopPropagation();
			
			window.location.href=linkPath+'/hopeaddress.html';
		},
		//微信支付或余额支付
		wexinpay:function(){
			var that=this;
			that.weipay=true;
			that.remainpay=false;
			that.payment=2;
		},
		//余额支付
		remain:function(){
			var that=this;
			that.weipay=false;
			that.remainpay=true;
			that.payment=1;
		},

        //自提地点详情
        spotdetail:function(){
            var id=localStorage.getItem('spot_id');
            window.location.href=linkPath+'/TakeDetails.html?id='+id;
        },
        //食堂地点详情
        storedetail:function(){
            var id=localStorage.getItem('store_id');
            window.location.href=linkPath+'/addressdetails.html?id='+id;
        },
		//提交支付
		paymentorder:function(){
			var spot_id='';
			var store_id='';
			var that=this;
			//名字
			var nick_name=that.name;
			localStorage.setItem('ordername',nick_name);
			//电话
			var tel_phone=that.telephone;
			localStorage.setItem('orderphone',tel_phone);
			console.log(localStorage)
			//就近自提或堂食
			var ordertype=that.order_type;
			//自取时间
			var pick_up_time='';
			//打印机id
			var printer_id='';
			//地点id
			if(ordertype==1){
			  spot_id=localStorage.getItem('spot_id');
			  pick_up_time=$("#time4").val();
                console.log( pick_up_time.length);
             if(pick_up_time==""){
                 alert("请选择定制时间");
                 return false;
              }
			//console.log(pick_up_time.length)
             if(pick_up_time.length==13){
                 alert("请选择具体时间");
                 return false;
             }
			  if(nick_name==''){
			  	alert("请输入名字");
			  	return false;
			  }
			  if(!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(tel_phone))){
			  	alert('请输入正确手机号码');
			  	return false;
			  }
			}else if(ordertype==2){
				store_id=localStorage.getItem('store_id');
				
				printer_id=that.printer_id;
				if(printer_id==''){
					alert("请选择打印机");
					return false;
				}
			}
			
			var order_note=that.remark;
			var payment=that.payment;
			var discount_coupon_id=that.discount_coupon_id;
			var url = '/Flow/done'
			var params = {		
				unique_id: localStorage.getItem('unique_id'),
				consignee:nick_name,
				tel:tel_phone,
				cart_id_str:id,
				order_type:ordertype,
				spot_id:spot_id,
				store_id:store_id,
				order_notes:order_note,
				payment:payment,
				discount_coupon_id:discount_coupon_id,
				pick_up_time:pick_up_time,
				printer_id:printer_id,
				from:2
			}


			ajaxsend(url, params, function(res) {
				/*console.log(JSON.stringify(res))*/
				console.log(res);
				if(res.status==true){
					alert("下单成功");
					//window.location.reload();
					window.location.href=linkPath+'/PersonCenter/PersonCenter.html'
				}else if(res.status==false){
					alert(res.msg);
					alert("下单失败");
				}

			})

		}

		
	}
	
	
})

//});