<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/tld/fns.tld" prefix="fns" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<link type="text/css" rel="stylesheet" href="<c:url value='/resources/version_new/css/public.css' />" />
<link type="text/css" rel="stylesheet" href="<c:url value='/resources/version_new/css/idangerous.swiper2.7.6.css' />" />
<link type="text/css" rel="stylesheet" href="<c:url value='/resources/version_new/css/basic.css' />" />
<link rel="stylesheet" href="<c:url value='/resources/versions-2.0.2/css/reset.css' />">
<link rel="stylesheet" href="<c:url value='/resources/versions-2.0.2/css/applicant.css' />">
<link rel="stylesheet" href="<c:url value='/resources/versions-2.0.2/css/laydate.css' />">
<link rel="stylesheet" href="<c:url value='/resources/versions-2.0.2/css/animate.min.css' />">
<div class="increased-styles news-increased animated" style="display: block;top: 0;left: 0;margin-left: 0;">
	<div class="payment-head">
		<span>新增人员</span>
	</div>
	<div class="increased-cont">
		<h2>企业人员变动-新员工入职，可在保单中增加被保险人。</h2>
		<form id="add_detail_list_form">
			<input type="hidden" name="ins_insurance_slip_id" value="${iprVo.ins_insurance_slip_id}">
			<input type="hidden" name="revise_type" value="1">
			<input type="hidden" name="sign" id="add_sign" value="1"><%--0暂存，1提交--%>
			<div class="increased-time clearfix">
				<div class="time">
					<span>生效时间</span>
					<input title="生效时间" type="text" data-val="required" readonly name="inception_date" id="add_inception_date" onclick="laydate({elem:'#add_inception_date',istime: true,istoday: false,min: '${min}',max: '${max}', format: 'YYYY-MM-DD'})"><%----%>
				</div>
				<%--<form id="uploadForm" name="uploadForm" method="post" enctype="multipart/form-data" action='<c:url value="/pc/preservation/resultSet/uploadRoleFile"/>' >--%>
				<div class="upload">
					<a href="<c:url value='/resources/files/批量导入范本.xls'/>">批量导入范本.xls</a>
					<a href="javascript:;" class="upload-text">批量上传导入文件</a>
					<input name="role_record" id="role_record" type="file" onchange="uploadInsure();">
				</div>
			</div>

			<div class="increased-table" id="add-increased-table">
				<div class="increased-thead">
					<ul class="clearfix">
						<li class="s1">
							<span>姓名</span>
						</li>
						<li class="s2">
							<span>证件类型</span>
						</li>
						<li class="s3">
							<span>证件号</span>
						</li>
						<li class="s4">
							<span>手机号</span>
						</li>
						<li class="s5">
							<span>工种</span>
						</li>
						<li class="s7">
							<span>性别</span>
						</li>
						<li class="s8">
							<span>出生日期</span>
						</li>
						<li class="s9">
							<span>操作</span>
						</li>
					</ul>
				</div>
				<div class="increased-tbody  ert-tbody">
					<ul>
						<c:choose>
							<c:when test="${empty ipdVoList }">
								<li >
									<p >暂无记录！！</p>
								</li>
							</c:when>
							<c:otherwise>
								<c:forEach items="${ipdVoList }" var="ipdVo" varStatus="i">
									<li class="clearfix">
										<div class="w1">
											<span>
												<input title="姓名" data-val="required" name="insPreservationDetailVoList[${i.index}].name" id="name_${i.index}" type="text" value="${ipdVo.name}" onblur="doValidator(this);">
											</span>
										</div>
										<div class="w2">
											<span>
												<select data-val="required" name="insPreservationDetailVoList[${i.index}].id_type" id="id_type_${i.index}">
													<option value="0"<c:if test="${ipdVo.id_type eq '0'}"> selected</c:if>>身份证</option>
													<option value="3"<c:if test="${ipdVo.id_type eq '3'}"> selected</c:if>>护照</option>
													<option value="4"<c:if test="${ipdVo.id_type eq '4'}"> selected</c:if>>台胞证</option>
													<option value="5"<c:if test="${ipdVo.id_type eq '5'}"> selected</c:if>>回乡证</option>
												</select>
											</span>
										</div>
										<div class="w3">
											<span>
												<input title="证件号" data-val="required" type="text" name="insPreservationDetailVoList[${i.index}].id_card" id="id_card_${i.index}" value="${ipdVo.id_card}" data-it-sign="id_type_${i.index}" onblur="robotizationGet(this,'sex_${i.index},birthday_${i.index}');">
											</span>
										</div>
										<div class="w4">
											<span>
												<input title="手机号" data-val="required" name="insPreservationDetailVoList[${i.index}].tel" id="tel_${i.index}" type="text" onblur="doValidator(this);" value="${ipdVo.tel}">
											</span>
										</div>
										<div class="w5">
											<span>
												<select data-val="required" name="insPreservationDetailVoList[${i.index}].career" id="career_${i.index}">
													<option value="1"<c:if test="${ipdVo.career eq '1'}"> selected</c:if>>内勤人员</option>
													<option value="2"<c:if test="${ipdVo.career eq '2'}"> selected</c:if>>保安人员</option>
													<c:if test="${fn:contains(orderVo.product_code,'TYX')||fn:contains(orderVo.product_code,'GZZRX-ZH')}">
														<option value="3"<c:if test="${ipdVo.career eq '3'}"> selected</c:if>>武装押运人员</option>
													</c:if>
													<c:if test="${fn:contains(orderVo.product_code,'GZZRX-TB')||fn:contains(orderVo.product_code,'GZZRX-QH')||fn:contains(orderVo.product_code,'GZZRX-PAC')}">
														<option value="4"<c:if test="${ipdVo.career eq '4'}"> selected</c:if>>保洁人员</option>
													</c:if>
												</select>
											</span>
										</div>
										<div class="w7">
											<span>
												<select data-val="required" name="insPreservationDetailVoList[${i.index}].sex" id="sex_${i.index}" onblur="doValidator(this);" data-it-sign="id_card_${i.index}">
													<option value="1"<c:if test="${ipdVo.sex eq '1'}"> selected</c:if>>男</option>
													<option value="2"<c:if test="${ipdVo.sex eq '2'}"> selected</c:if>>女</option>
												</select>
											</span>
										</div>
										<div class="w8">
											<span>
												<input title="出生日期" data-val="required" type="text" name="insPreservationDetailVoList[${i.index}].birthday" id="birthday_${i.index}" value="${ipdVo.birthday}" data-it-sign="id_card_${i.index}" onclick="laydate({elem:'#birthday_${i.index}',istime: false, format: 'YYYY-MM-DD',choose: function(dates){doValidator('#birthday_${i.index}');}})">
											</span>
										</div>
										<div class="w9">
											<span class="shan" onclick="deleteUpdateDetail(this)">删除</span>
										</div>
									</li>
								</c:forEach>
							</c:otherwise>
						</c:choose>
					</ul>
				</div>
			</div>
		</form>
		<div class="zeng">
				<span id="zeng" P-T-VAL="${fn:contains(orderVo.product_code,'GZZRX')?'1':'2'}" P-S-VAL="${fn:contains(orderVo.product_code,'GZZRX-PAC')?'1':fn:contains(orderVo.product_code,'GZZRX-CA')?'2':'0'}"><%--P-T-VAL 产品类型，用于职业区别，雇主跟团意险不一样(1:雇主，2：其它)；P-S-VAL 是否是平安雇主--%>
					<img src="<c:url value='/resources/versions-2.0.2/images/icon-zeng.png'/>">
					<i>增加一行</i>
				</span>
		</div>
	</div>
	<div class="increased-foot">
		<%--<span class="incre-cancel">取消</span>--%>
		<%--<span onclick="save_preservation('0');" class="incre-ts">暂存</span>--%>
		<span onclick="save_preservation();" class="incre-confirm">确认增员</span>
	</div>
</div>
<script type="text/javascript" src="<c:url value='/resources/version_new/js/jquery-1.8.3.min.js' />"></script>
<script type="text/javascript" charset="utf-8" src="<c:url value='/resources/version_new/js/layer/layer.js' />"></script>
<script type="text/javascript" charset="utf-8" src="<c:url value='/resources/versions-2.0.2/js/laydate.js' />"></script>
<script type="text/javascript" charset="utf-8" src="<c:url value='/resources/versions-2.0.2/js/assure.js' />"></script>
<script type="text/javascript" charset="utf-8" src="<c:url value='/resources/commonJS/normalCheck.js' />"></script>
<script type="text/javascript" src="<c:url value='/resources/commonJS/validateIdent.js' />"></script>
<script type="text/javascript" src="<c:url value='/resources/version_new/js/FileSaver.js'/>"></script>
<jsp:include page="../../../index/multi_init_param.jsp"/>
<script type="text/javascript">
    var baseUrl = '${pageContext.request.contextPath }';
    function save_preservation(){
        var index = laySomenType(0,null,'',0);
        var isT = 0;
        if($('#add_inception_date').val() != ''){
            isT = 0;
        }else{
            layer.msg("请选择生效时间！");
            isT = 1;
        }
        if(isT == 0){
            $.ajax({
                type : 'POST',
                url : baseUrl + "/api/preservation/resultSet/add_preservation_service",
                data : $("#add_detail_list_form").serialize(),
                dataType : "json",
                success : function(data) {
                    if(data.statusCode == "200"){
						if(data.forwardUrl && data.forwardUrl != 'null'){
							window.open(data.forwardUrl);
							layer.confirm('已完成在线支付？（批改结果预计将在1分钟后更新，请注意查看“批改申请记录”状态）', {  btn: ['是', '否'] }, function () {
								location.href = baseUrl + "/api/preservation/resultSet/openMessage";
							});
						}else{
							layer.msg(data.message);
							location.href = baseUrl + "/api/preservation/resultSet/openMessage";
						}
                    }else{
                        if(data.message.indexOf('部分证件号已在保，无法重复投保：')!=-1){
                            layer.msg("部分证件号已在保，无法重复投保!",{time:2000});
                            var reg = new RegExp(',','g');
                            var blob = new Blob(['(注：以下证件号已在保，请检查并剔除后重新提交。)\n'+data.message.split('：')[1].replace(reg,'\n')], {type: "text/plain;charset=utf-8"});
                            saveAs(blob, "人员重复投保清单.txt");
                        }else{
                            layer.msg(data.message,{time:2000});
                        }
                    }
                    laySomenType(2,index,'',0);
                },
                error: function(){
                    laySomenType(2,index,'',0);
                }
            });
        }else{
            laySomenType(2,index,'',0);
        }
    }

    function uploadInsure(){
        var formData = new FormData();
        var files = document.getElementById("role_record").files[0];
        if(files == undefined){
            return;
        }
        if(files.name.split('.')[1].indexOf('xls')==-1&&files.name.split('.')[1].indexOf('xlsx')==-1){
            layer.msg('请下载模板文件，填充人员信息后上传！',{time:3000});
            return;
        }
        var index = laySomenType(0,null,'',0);
        formData.append('role_record', files);
        $('#role_record').val('');
        $.ajax({
            type: 'POST',
            url:baseUrl + '/api/preservation/resultSet/uploadRoleFile',
            dataType:"json",
            data: formData,
            processData: false,
            contentType: false,
            success: function(json){
                if(json.statusCode == '200') {
                    $.ajax({
                        type: 'POST',
                        url:baseUrl + "/api/preservation/resultSet/add_upload_view",
                        data:$("#add_detail_list_form").serialize(),
                        dataType:"text",
                        success: function(data){
                            $("#add-increased-table").html(data);
                            laySomenType(2,index,'',0);
                        },
                        error : function(XMLHttpRequest, textStatus, errorThrown) {
                            layer.msg(textStatus);
                            laySomenType(2,index,'',0);
                        }
                    });
                }else{
                    laySomenType(2,index,'',0);
                    layer.msg("出现异常数据，请查看异常清单");
                    var reg = new RegExp(';','g');
                    var blob = new Blob(['(注：以下异常信息行号对应Excel自带行号。)\n'+json.message.replace(reg,'\n')], {type: "text/plain;charset=utf-8"});
                    saveAs(blob, "excel保全人员数据异常清单.txt");
                }
            },
            error : function(XMLHttpRequest, textStatus, errorThrown) {
                layer.msg(textStatus);
                laySomenType(2,index,'',0);
            }
        });
    }
    $(function(){
        $('.news-increased').parent().css("min-width","1100px");
        $('.news-increased').parent().css("background","#FFF");
    });
</script>
