<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false" %>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>信息绑定</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="/SinoGYS/css/newCss/reset.css" />
<link rel="stylesheet" href="/SinoGYS/css/newCss/login.css" />
<link rel="stylesheet" href="/SinoGYS/css/newCss/option.css" />
<link rel="stylesheet" href="/SinoGYS/weixincss/weui.min.css">
<link rel="stylesheet" href="/SinoGYS/weixincss/jquery-weui.css">
<script type="text/javascript" src="/SinoGYS/js/sweetalert.min.js"></script>
<script src="/SinoGYS/js/jquery-1.7.2.js" type="text/javascript"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="/SinoGYS/js/jquery-weui.js"></script>

 <script type="text/javascript">
     var ohtml=document.documentElement;
     function getWidth(){
         var screenWidth=ohtml.clientWidth;
         if(screenWidth<320){
             ohtml.style.fontSize="13.3333px";
         }else if(screenWidth>1080){
             ohtml.style.fontSize="45px";
         }else{
             ohtml.style.fontSize=screenWidth/(1080/45)+"px";
         }
     }
     getWidth();
     window.onresize=function(){
         getWidth();
     };
</script>
</head>
<%
String weixinUserId = request.getParameter("weixinUserId");
System.out.println("=======>>>"+weixinUserId);
if(weixinUserId==null||weixinUserId.equals("")){
	weixinUserId = request.getAttribute("weixinUserId").toString();
}

%>
<body>
<form>
<input type="hidden" name="weixinUserId"  id="weixinUserId" value="<%=weixinUserId%>"/>
<input type="hidden" id="identity" name="identity" value="">
<input type="hidden" id="vehicleId" name="vehicleId" value="">
	<div class="loginWrapperBg"></div>
    <div class="loginWrapper" style="display: none;">
        <div class="loginTitle">
            <img src="/SinoGYS/images/newImage/zdLoginLogo.png" alt="">
            <p class="bindRole">供应商绑定</p>
            <div class="checkItem">
                <img class="checkImg" src="/SinoGYS/images/newImage/check.png" alt="">
               	 救援司机
            </div>
        </div>
        <div class="loginForm">
            <div class="loginFormItem">
                <div class="itemTitle">
                  	登录名
                </div>
                <input class="itemInput" id="loginName" name="loginName" placeholder="请输入登录名">

            </div>
            <div class="loginFormItem">
                <div class="itemTitle">
                    密&nbsp;&nbsp;&nbsp;&nbsp;码
                </div>
                <input class="itemInput" id="password" name="password" placeholder="请输入登录密码">
            </div>
        </div>
        <input class="loginFormSubmit loginBtnActive btn_bind_wap1" type="button" value="确       定" />
    </div>
    
    <div class="loginWrapper">
        <div class="loginTitle">
            <img src="/SinoGYS/images/newImage/trailer.png" alt="">
            <p class="bindRole">救援司机绑定</p>
            <div class="checkItem">
                <img class="checkImg" src="/SinoGYS/images/newImage/check.png" alt="">
               	 供应商
            </div>
        </div>
        <div class="loginForm">
            <div class="loginFormItem">
                <div class="itemTitle">
                   	司机姓名
                </div>
                <input class="itemInput" id="name" name="name" placeholder="请输入姓名">
            </div>
            <div class="loginFormItem">
                <div class="itemTitle">
                    	手机号码
                </div>
                <input class="itemInput" type='tel' id="phone" name="phone" placeholder="请输入手机号码">
            </div>
            <div class="loginFormItem">
                <div class="itemTitle">
                    	服务编号
                </div>
                <input class="itemInput" id="rescueCode" name="rescueCode" placeholder="请输入服务商编号">
            </div>
            <div class="loginFormItem selectCar">
                <div class="itemTitle">
                    	选择车辆
                </div>
                <span class="vehicleName"></span>
                <div class="arrowPosition">
					<img class="arrow" src="/SinoGYS/images/newImage/arrow.png" alt="">
				</div>
            </div>
        </div>
        <input class="loginFormSubmit loginBtnActive btn_bind_wap2" type="button" value="确       定" />
    </div>
    
    <div class="optionDialog" style="display: none;">
    	<div class="dialog_con dialog">
    		<p class="dialogTitle">请选择车辆</p>
    		<ul class="dialogList"></ul>
    		<div class="buttonWrap clearfix">
    			<a href="#" class="cancelBtn hideBtn">取&nbsp;&nbsp;&nbsp;&nbsp;消</a>
    			<a href="#" class="confirmBtn hideBtn">确&nbsp;&nbsp;&nbsp;&nbsp;认</a>
    		</div>
    	</div>
    </div>
    <script type="text/javascript">
	$(function(){
		 $.alert("请选择您的身份！", "提示！");
	});
	
	function chooseVehicle(){
		$(".dialogList").empty();
		var rescueCode=$("#rescueCode").val();
		if(rescueCode==""){
			alert("请输入服务商编号");
			return false;
		}else{
			$.ajax({
				        async: true,
				        url:"/SinoGYS/RescueVehicleAction.do?CMD=checkLoginName",
				        dataType: "json",
				        type: "POST",
				        data: {"rescueCode":$("#rescueCode").val()},
				        success: function (jsonObject) {
				        	var flag=jsonObject.code;
				        	if (flag==true) {
										$.getJSON(
												"/SinoGYS/RescueVehicleAction.do?CMD=queryRescueVehicle",
												{rescueCode : $("#rescueCode").val()},
												function(data) {
													var list = data.vehicleList;
													if(list!=null&&list.length>0){
														for ( var i in list) {
															console.log(list[i].ID);
															$(".dialogList")
																.append(
																		'<label for="mobike"><li class="carType_list" name="'+list[i].NAME+'">'+list[i].NAME+
																		'<div class="check-item carType check-item-bg">'+
																		'<input id="mobike" type="radio" name="type" value="'+list[i].ID+'">'+
																		'</div></li></label>');
													  		}
													  		setTimeout('$(".optionDialog").show()',300);
													}else{
    													alert("该服务商下没有可用车辆");
													}
													
												});
							} else{
								swal("不存在该服务商,请确认后重新输入");
								return false;
							}
						},
						
					});
			return true;		
		}
	}
	
	$().ready(function() {
		$(".btn_bind_wap1").click(function() {
			var loginName = $("#loginName").val();
			var password = $("#password").val();
			alert(loginName+"==="+password);
			if (loginName == "" || password == "") {
				alert("请输入完整信息");
			} else {
				$.ajax({
					async : true,
					url : "/SinoGYS/RescueVehicleAction.do?CMD=managerRegist",
					dataType : "json",
					type : "POST",
					data : {
						"loginName" : $("#loginName").val(),
						"password" : $("#password").val(),
						"weixinUserId" : $("#weixinUserId").val(),
						"identity":2
					},
					success : function(jsonObject) {
						//alert(jsonObject.code);
						if (jsonObject.code == true) {
							alert("注册成功");
							wx.closeWindow();

						} else {
							alert("绑定失败", "信息输入有误", "error");
							return false;
						}
					},
					error : function(result, status) {
						return false;
					}
				});
			}
		});
	});
	
	$().ready(function() {
		$(".btn_bind_wap2").click(function() {
			var name = $("#name").val();
			var phone = $("#phone").val();
			var rescueCode = $("#rescueCode").val();
			if (name == "" || password == "" || rescueCode == "") {
				alert("请输入完整信息");
			} else {
				$.ajax({
					async : true,
					url : "/SinoGYS/RescueVehicleAction.do?CMD=regist",
					dataType : "json",
					type : "POST",
					data : {
						"name" : $("#name").val(),
						"phone" : $("#phone").val(),
						"rescueCode" : $("#rescueCode").val(),
						"weixinUserId" : $("#weixinUserId").val(),
						"vehicleId" : $("#vehicleId").val(),
						"vehicleName":$(".vehicleName").text(),
					},
					success : function(jsonObject) {
						if (jsonObject.code == true) {
							alert("注册成功");
							wx.closeWindow();

						} else {
							alert("绑定失败", "信息输入有误", "error");
							return false;
						}
					},
				});
			}
		});
	});
    	// 单选
    	$(document).on("click",'.carType_list',function(){
    		$('.carType_list').find("div.check-item").removeClass('check-item-bg2').addClass('check-item-bg');
			$(this).find("div.check-item").removeClass('check-item-bg').addClass('check-item-bg2');
		});
		
    	// 选择车辆  点击事件
    	$(".selectCar").click(function(){
    		chooseVehicle();
    			
    	});
    	
    	// 取消点击事件
    	$(".cancelBtn").click(function(){
    		$(".optionDialog").hide();
    	});
    	
    	//确认按钮
		$(".confirmBtn").click(function(){
			$.getJSON("/SinoGYS/RescueVehicleAction.do?CMD=choosedVehicleName",
				{vehicleID:$(".check-item-bg2").children().val()}, function(data){
				if(data.code>0){  //被选择过
					alert("该车辆已被绑定，请重新选择！");	
				}else{
					$(".optionDialog").hide();
					$("#vehicleId").val($(".check-item-bg2").children().val());
    				$(".vehicleName").text($(".check-item-bg2").parent().attr("name"));
				}
			});
    	});
		
		$(".checkItem").on("click",function(){
			$(this).parents(".loginWrapper").hide().siblings(".loginWrapper").show();
		});
    </script>       
</form>    
</body>
</html>