order.js 11.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
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;
                that.ads();
			})
		},
        ads(){
            var that=this;
            console.log(that.selfarea[0]);
            var areaid=that.selfarea[0].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;

            })
        },
		//每个区域的自提点
		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="/index.php/Portal/Template/hopeaddress";
		},
		//微信支付或余额支付
		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;
			  }


                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,
                    order_notes:order_note,
                    payment:payment,
                    discount_coupon_id:discount_coupon_id,
                    pick_up_time:pick_up_time,
                    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("下单失败");
                    }

                })
			}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'),
                    cart_id_str:id,
                    order_type:ordertype,
                    store_id:store_id,
                    order_notes:order_note,
                    payment:payment,
                    discount_coupon_id:discount_coupon_id,
                    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("下单失败");
                    }

                })
			}
			
			//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("下单失败");
			//	}
            //
			//})

		}

		
	}
	
	
})

//});