<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/include/header2.jsp"%>
<!-- <link type="text/css" rel="stylesheet" href="${ctx}/css/admin.css" /> -->
<title>疑案管理</title>
<style>
	.sel {
	    margin-top: 10px;
	}
	.sel input {
	    /*height: 25px;
	    line-height: 25px;*/
	    border: 1px solid #eee;
	    border-radius: 3px;
	    width: 150px;
	    padding:0px 5px;
	    background-color: #fff;
	}
	
	.sel_span {
	    margin-right: 20px;
	}
	.num{
		font-size: 20px;
	    font-family: initial;
	    color: #e09260;
	    font-weight: 700;
	}
	.table_main {
	    margin-top: 10px;
	}
	table#model_tab th, #model_tab td {
	    border: 1px solid #7482a2;
	    padding: 5px 10px;
	}
	/*申请按钮*/
	.apply_btn {
	    margin-top: 20px;
	    text-align: center;
	}
	.deliveryBtn{
		background-color: #00b591;
		padding: 5px 15px;
		border-radius: 5px;
		color: #fff;
		margin-right: 7px;
		cursor: pointer;
	}
	/*申请换页面布局，2018-01-09*/
	.model_apply {
	    margin-top: 15px;
	}
	.input_text{
		height: 25px;
	    line-height: 25px;
	    border: 1px solid #eee;
	    border-radius: 3px;
	    width: 150px;
	    padding-left: 5px;
	    background-color: #fff;
	}
	.model_apply span {
	  
	    margin-right:30px;
	}
	/*下拉样式修改，2018-01-29*/
	
</style>
</head>
<body class="bg1">
	<div class="headCon">
		<jsp:include page="/WEB-INF/jsp/top2.jsp">
		<jsp:param name="index" value="疑案管理" />
		</jsp:include>
	</div>
	<div class="container_fluid">
		<div class="searchCon left_menu managerLeft">
			<jsp:include page="/include/personalLeft.jsp">
				<jsp:param name="index" value="机器学习申请" />
			</jsp:include>
		</div>

		<div class="resultCon" style="margin-left: 255px;position:relative;">
			<div class="reSearch">
				<div class="p_bar"style="border-bottom: 1px dashed #afb4bb;">您当前的位置：机器学习申请</div>
				<div class="sel" style="position: relative;">
					
					<span class="sel_span">申请数量上限/每天：<b class="num maxNum">${total}</b>个</span>	
					<span class="sel_span">当天已申请数量：<b class="num already">${applied}</b>个</span>
					<span class="sel_span">当天可申请数量：<b class="num canNum">${rest}</b>个</span>
				</div>
			</div>
			<div class="table_main resultTable" style="width: 99%;padding: 10px;border-radius: 5px;">
				<table id="model_tab" style="white-space:nowrap;width: 100%;">
					<thead>
						<tr><th>内容</th><th>概率</th></tr>
					</thead>
					<tbody>
						<tr>
							<td><input type="radio" name="risk" data-prob1=70 data-prob2=0 data-source="1"/>高风险案件</td>
							<td><input type="number" class="input_txt case" style="width:60px;" min="70" max="100" value="70">%以上</td>
						</tr>
						<tr>
							<td><input type="radio" name="risk" data-prob1=40 data-prob2=70 data-source="2"/>中风险案件</td>
							<td>
								<input type="number" class="input_txt case" style="width:60px;" min="40" max="70" value="40">%~
								<input type="number" class="input_txt case" style="width:60px;" min="40" max="70" value="70">%
							</td>
						</tr>
						<tr>
							<td><input type="radio" name="risk" data-prob1=40 data-prob2=0 data-source="3"/>低风险案件</th>
							<td><input type="number" class="input_txt case" style="width:60px;" min="0" max="40" value="40">%以下</td>
						</tr>
					</tbody>
				</table>
				<div class="model_apply">
					<span>
						<label>分公司代码：</label>
						<select id="branch_code" class="input_txt"><option>请选择...</option></select>
					</span>
					<span style="margin-top: 10px;">
						<label>时间范围:</label>
						      	<input 
						      		
									name="minY" 
									id="minY" 
									class="input_txt" 
									style="width:155px;" 
									readonly="readonly"
									placeholder="请输入起始日期"
									onfocus="WdatePicker({isShowWeek:true,dateFmt:'yyyy-MM-dd HH:mm:ss',realDateFmt:'yyyy-MM-dd',realTimeFmt:'HH:mm:ss',minDate:'2010-01-01',maxDate:'#F{$dp.$D(\'maxY\')||\'%y-%M-%d\'}'})"/>
							    <b style="font-size:16px">/</b>
							    <input 
							 
									name="maxY" 
									id="maxY" 
									class="input_txt" 
									style="width:155px;"  
									readonly="readonly" 
									placeholder="请输入结束日期"
									onfocus="WdatePicker({isShowWeek:true,dateFmt:'yyyy-MM-dd HH:mm:ss',realDateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'minY\')||\'2010-01-01\'}',maxDate:'%y-%M-%d'})" />
					</span>								
					<span>
						<label>申请数量：</label>
						<input id="saveNumber" type="number" name="number" class="input_txt" style="width: 60px;" min="0" value="1">
					</span>
				</div>
				<div class="apply_btn">
					<button id="apply" class="btn btn-primary"><i class="glyphicon glyphicon-send" aria-hidden="ture"></i>申请</button>
				</div>
			</div>
		</div>
	</div>


	<script src="${ctx}/js/lib/core.js"></script>
	<script src="${ctx}/component/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
	<script src="${ctx}/js/lib/perfect-scrollbar.jquery.js"></script>
	<script>
	    $(function () {
			//窗口大小变化
			resize();	
			//resultCon下的js
	    	/*var result={"datalist": [
                {"p": "人伤","id":"1","c": [{"n": "同一电话报案2次及以上人伤案件","describe":"是否存在同一电话多次报案的人为制造虚假事故"}, {"n": "同一伤者在不同案件中出现","describe":"是否存在同一电话多次报案的人为制造虚假事故"}, {"n": "同一车辆出险次数3次以上的人伤案件","describe":"是否存在同一电话多次报案的人为制造虚假事故"},{"n": "三者2同一车辆出险次数3次以上的人伤案件","describe":"是否存在同一电话多次报案的人为制造虚假事故"}]},
                {"p": "人伤2","id":"2", "c": [{"n": "三者2","describe":"三者2三者2"}, {"n": "电话2","describe":"三者2三者2"}, {"n": "保单2","describe":"三者2三者2"}]},
                {"p": "人伤3","id":"3", "c": [{"n": "三者3","describe":"三者2三者2"}, {"n": "电话3","describe":"三者2三者2"}, {"n": "保单3","describe":"三者2三者2"}]}
            ]};*/
           
             $("#model_tab").delegate("input[type='radio']","click",function(){
             	var source=$("#model_tab input[type='radio']:checked").data("source");
             	var prob1=$("#model_tab input[type='radio']:checked").data("prob1");
				var prob2=$("#model_tab input[type='radio']:checked").data("prob2");
				$.ajax({
					type:"POST",
					data:{prob1:prob1,prob2:prob2,source:source},
					url:"${ctx}/sysTaskMachine/branchList.do",//请求接口
					success:function(result){
						console.log(result);
						branchCode=result.branchCodeList;
						if(branchCode.length>0){
							branchCode.unshift("全部");
						}else{
							branchCode.unshift("暂无数据");
						}
						
						$("#branch_code").html(select(branchCode));
						$("#minY").val(result.minDate);
						$("#maxY").val(result.maxDate);
					},error:function(){
						alert("分公司显示失败");
					}
				})
             })

            $(".case").bind("keyup",function(){

            	var prob1,prob2;
            	if($(this).parent().find(".case").length>1){
            		 prob1=$(this).val();
            		 prob2=$(this).siblings().val();
            	}else{
            		 prob1=$(this).val();
            	}
            	var source=$(this).parent().parent().find("input[type='radio']").data("source");
            	var source2=$("#model_tab input[type='radio']:checked").data("source");
            	if(source!=source2){
            		return;
            	}
            	$.ajax({
					type:"POST",
					data:{prob1:prob1,prob2:prob2,source:source},
					url:"${ctx}/sysTaskMachine/branchList.do",//请求接口
					success:function(result){
						console.log(result);
						branchCode=result.branchCodeList;
						if(branchCode.length>0){
							branchCode.unshift("全部");
						}else{
							branchCode.unshift("暂无数据");
						}
						
						$("#branch_code").html(select(branchCode));
						$("#minY").val(result.minDate);
						$("#maxY").val(result.maxDate);
					},error:function(){
						alert("分公司显示失败");
					}
				})

			});
              function select(data){
            	var str="";
            	if(data.length>0){
            		for(var k=0;k<data.length;k++){
		            	str+="<option value="+data[k]+">"+data[k]+"</option>";
		            }
            	}
            	
	            return str;
            }
            //点击下拉选择并赋值
            //点击申请时
            $("#apply").click(function(){
            	//时间判断
            	var beginDate = $("#minY").val().toString();
			    var endDate = $("#maxY").val().toString();
				var minTime = new Date(Date.parse(beginDate.replace(/-/g,"/")));
				var maxTime = new Date(Date.parse(endDate.replace(/-/g,"/")));
				if(minTime.getTime()>maxTime.getTime()){
					alert("起始时间不能大于终止时间！");
					return false;
				}
            	//判断数字不能小于0
				var numberVal=[];
				$("input[type='number']").each(function(){
					var thisVal=$(this).val();
					if(thisVal<0){
						numberVal.push(thisVal);						
					}
				});
				if(numberVal.length>0){
					alert("输入的数字不能为负数！");
					return false;
				}
				//获取模型值
				var check_num,ischecked=false,prob1,prob2,branchCode,isselArg=false;
				$("#model_tab input[type='radio']").each(function(){
					if(this.checked){
						if($(this).parent().siblings().find(".case").length>1){
							prob1=$(this).parent().siblings().find(".case").eq(0).val();
            		 		prob2=$(this).parent().siblings().find(".case").eq(1).val();
						}else{
							prob1=$(this).parent().siblings().find(".case").val();
						}
						ischecked=true;
						/*check_num=$(this).parent().parent().find("input[type='number']").val();*/
						check_num=$("#saveNumber").val();
						branchCode=$("#branch_code").find("option:selected").text();
						if(branchCode=="暂无数据"||branchCode=="请选择..."){
							branchCode="";
						}
					}
				})
				if(isselArg){
					alert("申请的模型条件不能为空或0！");
					return false;
				}
				if(!ischecked){
					alert("请选择需要申请的内容！");
					return;
				}
				//判断选择的数量
				if(check_num=='' || check_num==0){
					alert("申请的数量不能为空或0！");
					return false;
				}
				if(Number(check_num)>Number($(".resultCon .canNum").text())){
					alert("不能超过当天可申请数量，请重新输入");
					return false;
				}
				var data={prob1:prob1,prob2:prob2,branchCode:branchCode,startDate:beginDate,endDate:endDate,taskNum:check_num};
				$.ajax({
					type:"POST",
					data:data,
					url:"${ctx}/sysTaskMachine/personalTaskPlus.do",//请求接口
					success:function(result){
						if(typeof(result)=="string"){
							result=JSON.parse(result);
						}
						if(result.code=="succ"){
							$(".resultCon .already").text(result.applied);
							$(".resultCon .canNum").text(result.rest);
							alert("分配成功！");
							top.location.replace("${ctx}/sysPersonal/modelTaskApply.do?ts="+ new Date().getTime()); 
						}else if(result.status=="err"){
							alert(result.mess);
						}else{
							alert("分配失败！");
						}	
					},
					error:function(){
						alert("分配失败！");	
					}
				})
				
            })
            
		})
          	//字符串遇数字截取并把数字的地方换为输入框
          
	    function resize(){
			//获取窗口高度
			var windowheight=$(window).height();
			var leftList = windowheight-40;
			$(".searchCon").css({"height":leftList+"px"});
			$(".resultCon").css({"height":leftList-12+"px"});
			$(".tbwrap").css({})
			$(".resultTable").perfectScrollbar("update");
			$(".resultCon").perfectScrollbar("update");
		}
	</script>
	<%@ include file="/include/footer.jsp"%>
</body>
</html>
