<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/webpage/include/taglib.jsp"%>
<html>
<head>
	<title>调转部门管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
        function doSubmit(){//回调函数，在编辑和保存动作时，供openDialog调用提交表单。
            var idArr = $("#workOfficeChangeUserList tr:visible");
            if(idArr.length<1){
                parent.layer.msg("请选择调转成员!", {icon: 5});
                return false;
            }
            if(validateForm.form()){
                $("#inputForm").submit();
                return true;
            }
            return false;
        }
        var validateForm;
        var count = 0;
        $(document).ready(function() {
            checkContentKeyUp('changeFor',255);
            if($("#changeDate").val()==null || $("#changeDate").val()==''){
                $("#changeDate").val(getNowFormatDate());
            }
            validateForm = $("#inputForm").validate({
                submitHandler: function(form){
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                rules:{
                },
                messages:{
                },
                errorContainer: "#messageBox",
                errorPlacement: function(error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
           /* laydate.render({
                elem: '#changeDate', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
                format: 'yyyy-MM-dd',
                type : 'date'
            });*/
        });

        function deleteRow(obj,index){
            $(obj).parent().parent().remove();
            str[index] = " ";
            mon[index] = 0;
        }
        function getNowFormatDate() {
            var date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            month = (month < 10)?"0"+month:month;
            strDate = (strDate < 10)?"0"+strDate:strDate;
            var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
            return currentdate;
        }
        function addRow(list, idx, tpl, row){
            var idx1 = $("#workOfficeChangeUserList tr").length;
            //tpl = tpl.replace("workMonthlyPlanThisList[0]_workClientInfoId","workMonthlyPlanThisList["+idx1+"].workClientInfoId");

            bornTemplete(list, idx, tpl, row, idx1);
        }
        function bornTemplete(list, idx, tpl, row, idx1){
            $(list).append(Mustache.render(tpl, {
                idx: idx, delBtn: true, row: row,
                order:idx1 + 1
            }));
            $(list+idx).find("select").each(function(){
                $(this).val($(this).attr("data-value"));
            });
            $(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
                var ss = $(this).attr("data-value").split(',');
                for (var i=0; i<ss.length; i++){
                    if($(this).val() == ss[i]){
                        $(this).attr("checked","checked");
                    }
                }
            });
        }
        function delRow(obj, prefix){
            var id = $(prefix+"_id");
            var delFlag = $(prefix+"_delFlag");
            if (id.val() == ""){
                delFlag.val("1");
                $(obj).parent().parent().remove();
            }else if(delFlag.val() == "0"){
                delFlag.val("1");
                $(obj).html("&divide;").attr("title", "撤销删除");
                $(obj).parent().parent().addClass("error");
                $(obj).parent().parent().addClass("hide");
            }else if(delFlag.val() == "1"){
                delFlag.val("0");
                $(obj).html("&times;").attr("title", "删除");
                $(obj).parent().parent().removeClass("error");
            }
        }


        function isNumber(val){
            if(val === "" || val ==null){
                return false;
            }
            var regPos = /^\d+(\.\d+)?$/; //非负浮点数
            var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
            if(regPos.test(val) || regNeg.test(val)){
                return true;
            }else{
                return false;
            }

        }
        function hasInArr(id,idArr) {
            for(var i=0;i<idArr.length;i++){
                if(id==$(idArr[i]).val()){
                    return true;
                }
            }
            return false;
        }
        function setUserInfo(d){
            $.ajax({
                type:'post',
                url:'${ctx}/workofficechange/workOfficeChange/getBasicInfo',
                data:{
                    "ids":d
                },
                success:function(data){
                    for(var i=0;i<data.length;i++){
                        var idArr = $("#workOfficeChangeUserList tr:visible .basicInfoId");
                        if(data[i].id!=''&&!hasInArr(data[i].id,idArr)){
                            addRow('#workOfficeChangeUserList', workOfficeChangeUserListRowIdx, workOfficeChangeUserListTpl);
                            workOfficeChangeUserListRowIdx = workOfficeChangeUserListRowIdx + 1;
                            var row = workOfficeChangeUserListRowIdx - 1 ;
                            $("#"+"workOfficeChangeUserList"+row+"_basicInfoId").val(data[i].id);
                            $("#"+"workOfficeChangeUserList"+row+"_userId").val(data[i].userId);
                            if(data[i].jobGrade!=null){
                                $("#"+"workOfficeChangeUserList"+row+"_before").val(data[i].jobGrade.id);
                                $("#"+"workOfficeChangeUserList"+row+"_6").val(data[i].jobGrade.name);
                            }
                            $("#"+"workOfficeChangeUserList"+row+"_1").val(data[i].no);
                            $("#"+"workOfficeChangeUserList"+row+"_2").val(data[i].name);
                            $("#"+"workOfficeChangeUserList"+row+"_3").val(data[i].office.name);
                            $("#"+"workOfficeChangeUserList"+row+"_4").val(data[i].idCard);
                            $("#"+"workOfficeChangeUserList"+row+"_5").val(data[i].status);
                        }
                    }
                }
            });
        }
        function setExcelInfo(data){
            for(var i=0;i<data.length;i++){
                var idArr = $("#workOfficeChangeUserList tr:visible .basicInfoId");
                if(data[i].id!=''&&!hasInArr(data[i].id,idArr)){
                    addRow('#workOfficeChangeUserList', workOfficeChangeUserListRowIdx, workOfficeChangeUserListTpl);
                    workOfficeChangeUserListRowIdx = workOfficeChangeUserListRowIdx + 1;
                    var row = workOfficeChangeUserListRowIdx - 1 ;
                    $("#"+"workOfficeChangeUserList"+row+"_basicInfoId").val(data[i].id);
                    $("#"+"workOfficeChangeUserList"+row+"_userId").val(data[i].userId);
                    if(data[i].jobGrade!=null){
                        $("#"+"workOfficeChangeUserList"+row+"_before").val(data[i].jobGrade.id);
                        $("#"+"workOfficeChangeUserList"+row+"_6").val(data[i].jobGrade.name);
                    }
                    $("#"+"workOfficeChangeUserList"+row+"_1").val(data[i].no);
                    $("#"+"workOfficeChangeUserList"+row+"_2").val(data[i].name);
                    $("#"+"workOfficeChangeUserList"+row+"_3").val(data[i].office.name);
                    $("#"+"workOfficeChangeUserList"+row+"_4").val(data[i].idCard);
                    $("#"+"workOfficeChangeUserList"+row+"_5").val(data[i].status);
                    $("#"+"workOfficeChangeUserList"+row+"_afterId").val(data[i].bankName);
                    $("#"+"workOfficeChangeUserList"+row+"_afterName").val(data[i].sqlStr);
                }
            }
        }

        function openDialogreUser(title,url,width,height,target){

            if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端，就使用自适应大小弹窗
                width='auto';
                height='auto';
            }else{//如果是PC端，根据用户设置的width和height显示。

            }
            top.layer.open({
                type: 2,
                area: ['90%','90%'],
                title:title,
                skin:"two-btns",
                name:'friend',
                content: encodeURI("${ctx}/sys/office/gridSelectUser?url=${ctx}/sys/office/gridSelectUser&isAll=true&type=null&isSingle=false") ,
                btn: ['确定', '关闭'],
                yes: function(index, layero){
                    var iframeWin = layero.find('iframe')[0].contentWindow; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                    var item = iframeWin.getSelectedItem();
                    if(item == "-1"){
                        return;
                    }
                    if(false){//单选
                        selectUserInfo(item.userId);
                    }else{//多选
                        var ids = [], names = [];
                        for (var i=0;i<item.length;i++){
                            ids.push(item[i].id);
                            names.push(item[i].name);
                        }
                        var arr=ids.join(",").replace(/u_/ig,"");
                        setUserInfo(arr);
                    }
                    top.layer.close(index);//关闭对话框。

                },
                cancel: function(index){
                }
            });
        }
        function openDialogreExcel(title,url,width,height,target){
            if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端，就使用自适应大小弹窗
                width='auto';
                height='auto';
            }else{//如果是PC端，根据用户设置的width和height显示。

            }
            top.layer.open({
                type: 1,
                area: [500, 300],
                title:"导入数据",
                skin: 'three-btns with-demo',
                content:$("#importBox").html() ,
                btn: ['下载模板','确定', '关闭'],
                btn1: function(index, layero){
                    window.location.href=url+'/template';
                },
                btn2: function(index, layero){
                    var formData = new FormData();
                    formData.append("file",top.$("#uploadFile")[0].files[0]);
                    $.ajax({
                        type: 'post',
                        url:url,
                        data: formData,
                        dataType: "json",
                        cache: false,
                        processData: false,
                        contentType: false,
                    }).success(function (result) {
                        setExcelInfo(result.data);
                        top.layer.msg(result.message);
                    }).error(function () {
                        top.layer.msg("导入文件失败！");
                    });
                    top.layer.close(index);
                },

                btn3: function(index){
                    top.layer.close(index);
                }
            });
        }
	</script>
	<style>
		/*超过5个汉字，调整label的长度，以下是配套的*/
		.layui-item .layui-form-label{
			width:90px;
		}
		.form-group .layui-item .layui-input-block,
		.query .layui-input-block {
			margin-left: 116px;
		}
	</style>
</head>
<body>
<div class="single-form">
	<div class="container">
		<form:form id="inputForm" modelAttribute="workOfficeChange" action="${ctx}/workofficechange/workOfficeChange/saveAudit" method="post" class="form-horizontal" >
			<form:hidden path="id"/>
			<form:hidden  path="changer"/>
			<form:hidden path="home"/>
			<form:hidden path="act.taskId"/>
			<form:hidden path="act.taskName"/>
			<form:hidden path="act.taskDefKey"/>
			<form:hidden path="act.procInsId"/>
			<form:hidden path="act.procDefId"/>
			<form:hidden id="flag" path="act.flag"/>
			<div class="form-group layui-row first">
				<div class="form-group-label"><h2>基础信息</h2></div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>调入部门：</label>
					<div class="layui-input-block with-icon">
						<sys:treeselect id="changeOffice" name="changeOffice" value="${workOfficeChange.changeOffice}" labelName="changeOfficeName" labelValue="${workOfficeChange.changeOfficeName}"
										title="部门" url="/sys/office/treeDataAllOffice?type=2" cssClass="form-control required layui-input" allowClear="true" notAllowSelectParent="true" />
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>调转编号：</label>
					<div class="layui-input-block">
						<div class="input-group">
							<form:input path="number" htmlEscape="false"  readonly="true"  class="form-control  layui-input"/>
							<span class="input-group-btn">
                                <label class="form-status"><c:choose><c:when test="${not empty workOfficeChange.state}">${fns:getDictLabel(workOfficeChange.state, 'audit_state', '')}</c:when><c:otherwise>新添</c:otherwise></c:choose></label>
                             </span>
						</div>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>调转日期：</label>
					<div class="layui-input-block">
						<input id="changeDate" name="changeDate"  readonly="true" type="text"  maxlength="20" class="laydate-icondate form-control layer-date  layui-input laydate-icon"
							   value="<fmt:formatDate value="${workOfficeChange.changeDate}" pattern="yyyy-MM-dd"/>"/>
					</div>
				</div>
				<div class="layui-item layui-col-sm6">
					<label class="layui-form-label"><span class="require-item">*</span>调转人：</label>
					<div class="layui-input-block">
						<form:input id="userName" readonly="true" path="userName" htmlEscape="false" class="form-control   layui-input"/>

					</div>
				</div>
				<div class="layui-item layui-col-sm12  with-textarea">
					<label class="layui-form-label"><span class="require-item">*</span>调转事由：</label>
					<div class="layui-input-block">
						<form:textarea path="changeFor" htmlEscape="false" rows="4" onkeyup="checkContentKeyUp('changeFor',255);"   maxlength="255" class="form-control required"/>
					</div>
					<span id="contentMsg" style="float: right"></span>
				</div>
			</div>

			<div class="form-group layui-row">
				<div class="form-group-label"><h2>调转成员</h2></div>
				<div class="layui-item nav-btns">
					<a href="javascript:void(0)" onclick="openDialogreUser('选择用户', '${ctx}/sys/office/gridSelectUser','90%','90%')" class="nav-btn nav-btn-add" ><i class="fa fa-plus"></i>&nbsp;选择</a>
					<a href="javascript:void(0)" onclick="openDialogreExcel('导入数据', '${ctx}/workofficechange/workOfficeChangeUser/import','90%','90%')" class="nav-btn nav-btn-import" ><i class="fa fa-plus"></i>&nbsp;导入</a>
						<%--<table:importExcelChangeOffice url="${ctx}/workofficechange/workOfficeChangeUser/import"></table:importExcelChangeOffice><!-- 导出按钮 -->--%>
					<div id="importBox" class="hide">
						<input id="uploadFile" name="file" type="file" style="width:330px"/>导入文件不能超过5M，仅允许导入“xls”或“xlsx”格式文件！<br/>　　
					</div>
				</div>
				<div class="layui-item layui-col-xs12 form-table-container" >
					<table id="contentTable" class="table table-bordered table-condensed can-edit no-bottom-margin">
						<thead>
						<tr>
							<th width="200px">工号</th>
							<th width="200px">姓名</th>
							<th width="200px">部门</th>
							<th width="200px">身份证号</th>
							<th width="200px">员工状态</th>
							<th width="200px">职级</th>
							<th width="200px">新职级</th>
							<th width="100px">操作</th>
						</tr>
						</thead>
						<tbody id="workOfficeChangeUserList">
						<c:if test="${not empty workOfficeChange.workOfficeChangeUserList}">
							<c:forEach items="${workOfficeChange.workOfficeChangeUserList}" var="workOfficeChangeUser" varStatus="index">
								<tr id="workItemCollarCatalogList${index.index}">
									<td class="hide">
										<input id="workOfficeChangeUserList${index.index}_id" name="workOfficeChangeUserList[${index.index}].id" type="hidden" value="${workOfficeChangeUser.id}"/>
										<input id="workOfficeChangeUserList${index.index}_basicInfoId" name="workOfficeChangeUserList[${index.index}].basicInfoId" type="hidden" value="${workOfficeChangeUser.basicInfoId}" class="basicInfoId"/>
										<input id="workOfficeChangeUserList${index.index}_userId" name="workOfficeChangeUserList[${index.index}].userId" type="hidden" value="${workOfficeChangeUser.userId}"/>
										<input id="workOfficeChangeUserList${index.index}_before" name="workOfficeChangeUserList[${index.index}].jobGrade1.id" type="hidden" value="${workOfficeChangeUser.jobGrade1.id}"/>
										<input id="workOfficeChangeUserList${index.index}_delFlag" name="workOfficeChangeUserList[${index.index}].delFlag" type="hidden" value="0"/>
									</td>
									<td>
										<input id="workOfficeChangeUserList${index.index}_1"  readonly="true"   type="text" value="${workOfficeChangeUser.workStaffBasicInfo.no}"   class="form-control "/>
									</td>
									<td>
										<input id="workOfficeChangeUserList${index.index}_2"  readonly="true"   type="text" value="${workOfficeChangeUser.workStaffBasicInfo.name}"   class="form-control "/>
									</td>
									<td>
										<input id="workOfficeChangeUserList${index.index}_3"  readonly="true"  name="workOfficeChangeUserList[${index.index}].workStaffBasicInfo.office.name"  type="text" value="${workOfficeChangeUser.workStaffBasicInfo.office.name}"   class="form-control "/>
									</td>
									<td>
										<input id="workOfficeChangeUserList${index.index}_4"  readonly="true"    type="text" value="${workOfficeChangeUser.workStaffBasicInfo.idCard}"   class="form-control "/>
									</td>
									<td>
										<input id="workOfficeChangeUserList${index.index}_5"  readonly="true"    type="text" value="${workOfficeChangeUser.workStaffBasicInfo.status}"  class="form-control "/>
									</td>
									<td>
										<input id="workOfficeChangeUserList${index.index}_6"  readonly="true"  name="workOfficeChangeUserList[${index.index}].jobGrade1.name"  type="text" value="${workOfficeChangeUser.jobGrade1.name}"   class="form-control "/>
									</td>
									<td>
										<sys:treeselectJob id="workOfficeChangeUserList${index.index}_after" name="workOfficeChangeUserList[${index.index}].jobGrade2.id" value="${workOfficeChangeUser.jobGrade2.id}" labelName="workOfficeChangeUserList[${index.index}].jobGrade2.name" labelValue="${workOfficeChangeUser.jobGrade2.name}"
														   title="职级类型" url="/workjobgrade/workJobGrade/treeData"  cssClass="form-control layui-input " allowClear="false" notAllowSelectParent="true"/>
									</td>
									<td class="text-center op-td" >
										<span class="op-btn op-btn-delete" id="workOfficeChangeUserList${index.index}_span" onclick="delRow(this, '#workOfficeChangeUserList${index.index}')" title="删除"><i class="glyphicon glyphicon-remove"></i>&nbsp;删除</span>
									</td>
								</tr>
							</c:forEach>
						</c:if>
						</tbody>
					</table>
					<script type="text/template" id="workOfficeChangeUserListTpl">//<!--
                                    <tr id="workOfficeChangeUserList{{idx}}">
                                        <td class="hide">
                                            <input id="workOfficeChangeUserList{{idx}}_id" name="workOfficeChangeUserList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
                                            <input id="workOfficeChangeUserList{{idx}}_basicInfoId" name="workOfficeChangeUserList[{{idx}}].basicInfoId" type="hidden" value="{{row.workStaffBasicInfo.id}}" class="basicInfoId"/>
                                            <input id="workOfficeChangeUserList{{idx}}_userId" name="workOfficeChangeUserList[{{idx}}].userId" type="hidden" value="{{row.workStaffBasicInfo.userId}}"/>
                                            <input id="workOfficeChangeUserList{{idx}}_before" name="workOfficeChangeUserList[{{idx}}].jobGrade1.id" type="hidden" value="{{row.jobGrade1.id}}"/>
                                            <input id="workOfficeChangeUserList{{idx}}_delFlag" name="workOfficeChangeUserList[{{idx}}].delFlag" type="hidden" value="0"/>
                                        </td>
                                        <td>
                                            <input id="workOfficeChangeUserList{{idx}}_1"   name="workOfficeChangeUserList[{{idx}}].workStaffBasicInfo.no" type="text" value="{{row.workStaffBasicInfo.no}}"  readonly="true"   class="form-control "/>
                                        </td>
                                        <td>
                                            <input id="workOfficeChangeUserList{{idx}}_2"  name="workOfficeChangeUserList[{{idx}}].workStaffBasicInfo.name" type="text" value="{{row.workStaffBasicInfo.name}}"   readonly="true"  class="form-control "/>
                                        </td>
                                         <td>
                                            <input id="workOfficeChangeUserList{{idx}}_3"  name="workOfficeChangeUserList[{{idx}}].workStaffBasicInfo.office.name" type="text" value="{{row.workStaffBasicInfo.office.name}}"   readonly="true"  class="form-control "/>
                                        </td>
                                         <td>
                                            <input id="workOfficeChangeUserList{{idx}}_4"  name="workOfficeChangeUserList[{{idx}}].workStaffBasicInfo.idCard" type="text" value="{{row.workStaffBasicInfo.idCard}}"   readonly="true"  class="form-control "/>
                                        </td>
                                         <td>
                                            <input id="workOfficeChangeUserList{{idx}}_5"  name="workOfficeChangeUserList[{{idx}}].workStaffBasicInfo.status" type="text" value="{{row.workStaffBasicInfo.status}}"   readonly="true"  class="form-control "/>
                                        </td>
                                         <td>
                                            <input id="workOfficeChangeUserList{{idx}}_6"  name="workOfficeChangeUserList[{{idx}}].jobGrade1.name" type="text" value="{{row.jobGrade1.name}}"   readonly="true"  class="form-control "/>
                                        </td>
                                         <td>
                                            <sys:treeselectJob id="workOfficeChangeUserList{{idx}}_after" name="workOfficeChangeUserList[{{idx}}].jobGrade2.id" value="${row.jobGrade2.id}" labelName="workOfficeChangeUserList[{{idx}}].jobGrade2.name" labelValue="${row.jobGrade2.name}"
																title="职级类型" url="/workjobgrade/workJobGrade/treeData"  cssClass="form-control layui-input" allowClear="true" notAllowSelectParent="true"/>
                                        </td>
                                        <td class="text-center op-td" >
                                            {{#delBtn}}<span class="op-btn op-btn-delete" id="workOfficeChangeUserList{{idx}}_span" onclick="delRow(this, '#workOfficeChangeUserList{{idx}}')" title="删除"><i class="glyphicon glyphicon-remove"></i>&nbsp;删除</span>{{/delBtn}}
                                        </td>
                                    </tr>//-->
					</script>
					<script type="text/javascript">
                        var workOfficeChangeUserListRowIdx = ${fn:length(workOfficeChange.workOfficeChangeUserList)}, workOfficeChangeUserListTpl = $("#workOfficeChangeUserListTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
                        if($("#id").val()){
                            workOfficeChangeUserListIdx = ${fn:length(workOfficeChange.workOfficeChangeUserList)};
                        }
                        $(document).ready(function() {
                        });
					</script>
				</div>
			</div>
			<div class="form-group layui-row page-end"></div>
		</form:form>
	</div>
</div>
</body>
</html>