<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>备件信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/formSelects-v4.css" media="all">
    <style>
        .layui-form-selected dl {
            height: 200px;
        }
        html {
            background-color: #fff;
        }
        .steps-box{display: flex; padding: 15px 0 0 15px;}
        .steps-box .warning{flex-shrink: 0;margin-top: 26px;}
        .steps {
            display: flex;
            flex-wrap: wrap;
        }
        .large-steps{
            justify-content: flex-end;
        }
        .startStep{
            height:60px;
            width:60px;
            text-align: center;
            background: #f2f2f2;
            border-radius: 10px;
            line-height:20px;
            padding-top:15px;
            margin-bottom:20px;
        }
        .startStep>img{
            display: block;
            margin: 0 auto;
        }
        .step{
            width:110px;
            height:52px;
            border-radius: 4px;
            text-align: center;
            border:4px solid #f2f2f2;
            line-height:26px;
            box-sizing: content-box;
            cursor: pointer;
            margin-left:20px;
            margin-bottom:30px;
            font-size: 12px;
        }
        .stepTitle{
            background: #f2f2f2;
            color: #333333;
        }
        .describe{
            /*color: #2897f0;*/
            background: #fff;
            -webkit-border-radius: 5px;
            -moz-border-radius: 5px;
            border-radius: 5px;
            height:26px;
        }
        .step.activeStep,.activeStep .stepTitle{
            background: #D9B589;
            color: #fff;
        }
        .step.activeStep{
            border:4px solid #D9B589;
        }
        .activeStep .describe{
            color: #D9B589;
        }
        .stepLine{
            position: relative;
        }
        .stepLine span{
            display: block;
            width:20px;
            height:6px;
            background: #f2f2f2;
            position: absolute;
            right:-20px;
            top:27px;
        }

        .step span{
            right:-24px;
            top:22px;
        }
        .step1 span{
            left: -24px;
        }
        .endStep{
            margin-left:20px;
        }
        .icon-close1{
            background: #f00;
            color: #fff;
            position: absolute;
            top: -10px;
            right: -10px;
            width: 20px;
            height: 20px;
            -webkit-border-radius: 50%;
            -moz-border-radius: 50%;
            border-radius: 50%;
            display: none;
            text-align: center;
            line-height: 20px;
        }
        .step:hover .icon-close1{
            display: block;
        }
        .layui-relative{position: relative}
        .layui-relative button{position: absolute; top: 3px; right: 5px}
        .contentDiv{
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
<div class="layui-card md-0 layui-form" lay-filter="layuiadmin-form-admin">
    <div class="layui-card-body">
        <div class="layui-card">
            <blockquote class="layui-elem-quote">基本信息</blockquote>
            <div class="layui-card-body">
                <input hidden id="processId" value="${map.processDef.columns.processId}">

                <div class="layui-row layui-col-space12 layui-form-item">
                    <div class="layui-col-lg6 layui-col-sm6">
                        <label class="layui-form-label"><i class="mark">*</i>流程名称：</label>
                        <div class="layui-input-block">
                            <input type="text"  id="name" name="name" value="${map.processDef.columns.name}" lay-verify="required" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-lg6 layui-col-sm6">
                        <label class="layui-form-label"><i class="mark">*</i>操作表单：</label>
                        <div class="layui-input-block">
                            <input value="${map.processDef.columns.formId}" id="formId" name="formId" hidden>
                                <input type="text"  id="formName" name="formName" value="${map.processDef.columns.formName}" disabled class="layui-input layui-bg-gray">
                        </div>
                    </div>
                    <div class="layui-col-lg12 layui-col-sm12">
                        <label class="layui-form-label"><i class="mark">*</i>流程描述：</label>
                        <div class="layui-input-block">
                            <input type="text"   class="layui-input" id="description" name="description" value="${map.processDef.columns.description}" lay-verify="required">
                        </div>
                    </div>
                </div>

            </div>
        </div>

        <div class="layui-card">
            <blockquote class="layui-elem-quote layui-relative">流程设置 <button class="layui-btn" onclick="addPress()">新增节点</button></blockquote>
            <div class="layui-card-body" >
                <div class="steps-box">
                    <div class="steps">
                        <div class="startStep stepLine">
                            <img src="${ctxPlugin}/static/img1/start.png"/> 开始 <span class="line"></span>
                        </div>
                        <div class="step stepLine activeStep" data-index="0">
                            <div class="stepTitle">提交人</div>
                            <div class="describe">提交角色</div><span></span>
                        </div>
                        <c:forEach items="${map.stepList}" var="step" varStatus="vs">
                            <div class="step stepLine stepDiv" data-index="${vs.count}">
                                <div class="stepTitle">${step.columns.item_name}</div>
                                <div class="describe">审批人</div>
                                <span></span>
                                <b class="icon-close1" onclick="delDiv(this)">x</b>
                            </div>
                        </c:forEach>
                        <div class="startStep endStep" id="endStep"><img src="${ctxPlugin}/static/img1/end.png"/> 结束 </div>
                    </div>
                </div>
            </div>
            <div class="layui-card-body contentDiv">
                    <div class="itex" data-index="0">
                        <div class="layui-form-item layui-col-xs12 ">
                            <div class="layui-col-xs3 mb-5" >
                                <label class="layui-form-label">节点类型：</label>
                                <div class="layui-input-block">
                                    <input type="text" id="itemType" name="itemType" class="layui-input layui-disabled layui-bg-gray " disabled  value="提交">
                                </div>
                            </div>
                            <div class="layui-col-xs3 mb-5" >
                                <label class="layui-form-label">节点名称：</label>
                                <div class="layui-input-block">
                                    <input type="text" id="itemName" name="itemName" class="layui-input layui-disabled layui-bg-gray "  disabled value="提交节点" onkeyup="changeName(this)">
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 mb-10 layui-form-item roleP ">
                            <label class="layui-form-label"><i class="red">*</i>提交角色：</label>
                            <div class="layui-input-block ml-130">
                                <div class="layui-col-xs2 pr-20">
                                    <select class="submitType" id="submitType" name="submitType" lay-filter="submitType"  lay-verify="required">
                                        <option value="">请选择</option>
                                        <c:if test="${!(map.processDef.columns.formId eq '13') && !(map.processDef.columns.formId eq '08') && !(map.processDef.columns.formId eq '17')}">
                                            <option value="1" <c:if test="${map.submitStep.columns.submit_type eq '1'}">selected</c:if>>平台角色</option>
                                            <option value="2" <c:if test="${map.submitStep.columns.submit_type eq '2'}">selected</c:if>>平台员工</option>
                                        </c:if>
                                        <c:if test="${map.processDef.columns.formId eq '13' || map.processDef.columns.formId eq '08' || map.processDef.columns.formId eq '17'}">
                                            <option value="3" <c:if test="${map.submitStep.columns.submit_type eq '3'}">selected</c:if>>代理商</option>
                                        </c:if>
                                    </select>
                                </div>

                                <div class="layui-col-xs4 pr-20 <c:if test="${map.submitStep.columns.submit_type ne '1'}">hide</c:if> submitSet"  >
                                    <select class="roleId" name="roleId"  id="roleId" lay-search >
                                        <option value="">请选择</option>
                                        <c:forEach items="${roles}" var="role">
                                            <option value="${role.columns.id}" <c:if test="${map.submitStep.columns.roleId eq role.columns.id}">selected</c:if>>${role.columns.name}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                                <div class="layui-col-xs8 pr-20 <c:if test="${map.submitStep.columns.submit_type ne '2'}">hide</c:if> submitSet2">
                                    <select name="empName" xm-select="empName" xm-select-search xm-select-type="1" xm-select-height="25px" xm-select-show-count="6">
                                        <option value="">请选择</option>
                                        <c:forEach items="${emps}" var="emp">
                                            <option value="${emp.columns.user_id}" <c:if test="${fn:contains(map.submitStep.columns.emp_user_id,emp.columns.user_id)}">selected</c:if>>${emp.columns.name}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>

                <c:forEach items="${map.stepList}" var="step" varStatus="vs">
                    <div class="layui-hide itex" data-index="${vs.count}">
                        <div class="layui-form-item layui-col-xs12" >
                            <div class="layui-col-xs3 mb-5" >
                                <label class="layui-form-label"><i class="red">*</i>节点类型：</label>
                                <div class="layui-input-block">
                                    <input type="text" name="itemType" class="layui-input layui-disabled layui-bg-gray" disabled  value="审批">
                                </div>
                            </div>
                            <div class="layui-col-xs3 mb-5" >
                                <label class="layui-form-label"><i class="red">*</i>节点名称：</label>
                                <div class="layui-input-block">
                                    <input type="text"  name="itemName" class="layui-input"  value="${step.columns.item_name}" onkeyup="changeName(this)">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-xs12" >
                            <div class="layui-col-xs3 mb-5" >
                                <label class="layui-form-label"><i class="red">*</i>驳回设置：</label>
                                <div class="layui-input-block">
                                    <select name="rejectStep" lay-verify="required">
                                        <option value="">请选择</option>
                                        <option value="提交节点" <c:if test="${step.columns.rejectStepName == '提交节点'}">selected</c:if>>提交节点</option>
                                        <c:if test="${vs.count>1}">
                                            <c:forEach items="${map.stepList}" var="step2" varStatus="vs2">
                                                <c:if test="${vs2.count<vs.count}">
                                                    <option value="${step2.columns.item_name}" <c:if test="${step.columns.rejectStepName == step2.columns.item_name}">selected</c:if>>${step2.columns.item_name}</option>
                                                </c:if>

                                            </c:forEach>
                                        </c:if>

                                    </select>
                                </div>
                            </div>
                            <div class="layui-col-xs3 mb-5" >
                                <label class="layui-form-label"><i class="red">*</i>审批方式：</label>
                                <div class="layui-input-block">
                                    <select name="auditMethod" lay-verify="required">
                                        <option value="1" <c:if test="${step.columns.audit_method eq '1'}">selected</c:if>>或签</option>
                                        <option value="2" <c:if test="${step.columns.audit_method eq '2'}">selected</c:if>>会签</option>
                                        <option value="3" <c:if test="${step.columns.audit_method eq '3'}">selected</c:if>>依次审批</option>
                                        <option value="4" <c:if test="${step.columns.audit_method eq '4'}">selected</c:if>>任意人</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 mb-5 roleP"  >
                            <label class="layui-form-label"><i class="red">*</i>审批人：</label>
                            <div class="layui-input-block ml-130">
                                <div class="layui-col-xs2 pr-20">
                                    <select class="submitType" name="auditType" lay-filter="submitType"  lay-verify="required">
                                        <option value="">请选择</option>
                                        <option value="1" <c:if test="${step.columns.audit_type eq '1'}">selected</c:if>>平台角色</option>
                                        <option value="2" <c:if test="${step.columns.audit_type eq '2'}">selected</c:if>>平台员工</option>
                                    </select>
                                </div>
                                <div class="layui-col-xs4 pr-20 <c:if test="${step.columns.audit_type ne '1'}">hide</c:if>  submitSet">
                                    <select class="roleId" name="auditRoleId"  lay-search>
                                        <option value="">请选择</option>
                                        <c:forEach items="${roles}" var="role">
                                            <option value="${role.columns.id}" <c:if test="${step.columns.roleId eq role.columns.id}">selected</c:if>>${role.columns.name}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                                <div class="layui-col-xs8 pr-20 <c:if test="${step.columns.audit_type ne '2'}">hide</c:if>  submitSet2" data-value="${vs.count}">
                                    <select name="empName" xm-select="empName${vs.count}" xm-select-search xm-select-type="1" xm-select-height="25px" xm-select-show-count="6">
                                        <option value="">请选择</option>
                                        <c:forEach items="${emps}" var="emp">
                                            <option value="${emp.columns.user_id}" <c:if test="${fn:contains(step.columns.emp_user_id,emp.columns.user_id)}">selected</c:if>>${emp.columns.name}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="layui-col-xs12 mb-5 csdiv"  >
                            <label class="layui-form-label">抄送：</label>
                            <div class="layui-input-block ml-130">
                                <div class="layui-col-xs8 pr-20">
                                    <select name="copeFor" xm-select="copeFor${vs.count}" xm-select-search xm-select-type="1" xm-select-height="25px" xm-select-show-count="6">
                                        <option value="">请选择</option>
                                        <c:forEach items="${emps}" var="emp">
                                            <option value="${emp.columns.user_id}" <c:if test="${fn:contains(step.columns.cc_user_id,emp.columns.user_id)}">selected</c:if>>${emp.columns.name}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </c:forEach>

            </div>
        </div>
    </div>
    <div class="operate-footer" style="z-index: 100">
        <button class="layui-btn" type="button" lay-submit="" lay-filter="component-form-demo1" id="tijiaoBtn">保存</button>
        <button class="layui-btn layui-btn-primary" type="button" onclick="cancels()">取消</button>
    </div>

    <div class="layui-hide itex  clonDiv">
        <div class="layui-form-item layui-col-xs12" >
            <div class="layui-col-xs3 mb-5" >
                <label class="layui-form-label"><i class="red">*</i>节点类型：</label>
                <div class="layui-input-block">
                    <input type="text" name="itemType" class="layui-input layui-disabled layui-bg-gray" disabled  value="审批">
                </div>
            </div>
            <div class="layui-col-xs3 mb-5" >
                <label class="layui-form-label"><i class="red">*</i>节点名称：</label>
                <div class="layui-input-block">
                    <input type="text"  name="itemName" class="layui-input"  value="" onkeyup="changeName(this)">
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-col-xs12" >
            <div class="layui-col-xs3 mb-5" >
                <label class="layui-form-label"><i class="red">*</i>驳回设置：</label>
                <div class="layui-input-block">
                    <select name="rejectStep" >
                        <option value="">请选择</option>
                        <option value="提交节点">提交节点</option>
                    </select>
                </div>
            </div>
            <div class="layui-col-xs3 mb-5" >
                <label class="layui-form-label"><i class="red">*</i>审批方式：</label>
                <div class="layui-input-block">
                    <select name="auditMethod">
                        <option value="1">或签</option>
                        <option value="2">会签</option>
                        <option value="3">依次审批</option>
                        <option value="4">任意人</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 mb-5 roleP"  >
            <label class="layui-form-label"><i class="red">*</i>审批人：</label>
            <div class="layui-input-block ml-130">
                <div class="layui-col-xs2 pr-20">
                    <select class="submitType"  name="auditType" lay-filter="submitType" >
                        <option value="">请选择</option>
                        <option value="1">平台角色</option>
                        <option value="2">平台员工</option>
                    </select>
                </div>
                <div class="layui-col-xs4 pr-20 submitSet">
                    <select class="roleId" name="auditRoleId"  lay-search >
                        <option value="">请选择</option>
                        <c:forEach items="${roles}" var="role">
                            <option value="${role.columns.id}">${role.columns.name}</option>
                        </c:forEach>
                    </select>
                </div>
                <div class="layui-col-xs8 pr-20 hide submitSet2">
                    <select name="empName"  xm-select-search xm-select-type="1" xm-select-height="25px" xm-select-show-count="6">
                        <option value="">请选择</option>
                        <c:forEach items="${emps}" var="emp">
                            <option value="${emp.columns.user_id}" >${emp.columns.name}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12 mb-5 csdiv">
            <label class="layui-form-label">抄送：</label>
            <div class="layui-input-block ml-130">
                <div class="layui-col-xs8 pr-20">
                    <select name="copeFor"  xm-select-search xm-select-type="1" xm-select-height="25px" xm-select-show-count="6">
                        <option value="">请选择</option>
                        <c:forEach items="${emps}" var="emp">
                            <option value="${emp.columns.user_id}" >${emp.columns.name}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
        </div>
    </div>
</div>


<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/javascript" src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/lib/formSelects-v4.js"></script>
<script>
    var imgsCount;
    var traderHtml = "";
    var supperHtml = "";
    var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
    var form;
    var $;
    var formSelects;
    var stepCount=${map.stepCount};
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form','formSelects'],  function () {
        $ = layui.$
            , element = layui.element
            , form = layui.form
            , laydate = layui.laydate
            , formSelects = layui.formSelects;

        swichPress();

        var ckeckFi = false;
        form.on('submit(component-form-demo1)', function (data) {
            $("#tijiaoBtn").attr("disabled", "true"); //改变提交按钮上的文字并将按钮设置为不可点击
            if (ckeckFi) {
                return
            }
            var processId=$("#processId").val();
            var name=$("#name").val();
            var formId=$("#formId").val();
            var description=$("#description").val();

            var def={
                name:name,
                formId:formId,
                description:description
            }

            var itemName=$("#itemName").val();
            var submitType=$("#submitType").val();
            var roleId="";
            var roleName="";
            var empUserId="";
            if("1"==submitType){
                roleId=$("#roleId").val();
                roleName=$("#roleId").find("option:selected").text();
                if(isBlank(roleId)){
                    $("#tijiaoBtn").removeAttr("disabled");
                    layer.msg("提交人的角色不能为空!");
                    return;
                }
            }else if("2"==submitType){
                empUserId=formSelects.value('empName','valStr');
                if(isBlank(empUserId)){
                    $("#tijiaoBtn").removeAttr("disabled");
                    layer.msg("提交人员不能为空!");
                    return;
                }
            }
            var submitStep={
                itemName:itemName,
                submitType:submitType,
                roleId:roleId,
                roleName:roleName,
                empUserId:empUserId
            };
            console.log(submitStep);

            var stepS=[];
            var lis2=$('.contentDiv .itex:gt(0)');
            console.log(lis2.length+'&&&&');
            var fgg=false;
            $.each(lis2,function(index,obj){  //index:索引obj:循环的每个元素
                var itemName=$(obj).find("input[name='itemName']").val();
                var auditRoleId=$(obj).find("select[name='auditRoleId']").val();
                var auditRoleName=$(obj).find("select[name='auditRoleId']").find("option:selected").text();
                var rejectStep= $(obj).find("select[name='rejectStep']").val();
                var auditMethod=$(obj).find("select[name=auditMethod]").val();
                var auditType=$(obj).find("select[name='auditType']").val();
                var cou=$(obj).find(".submitSet2").attr("data-value");
                var empUserId=formSelects.value('empName'+cou,'valStr');
                var ccUserId=formSelects.value('copeFor'+cou,'valStr');
                if(isBlank(ccUserId)){
                    ccUserId='';
                }
                if('1'==auditType){
                    if(isBlank(auditRoleId)){
                        layer.msg("审批人的角色不能为空!");
                        fgg=true;
                    }
                    empUserId="";
                }else if("2"==auditType){
                    if(isBlank(empUserId)){
                        layer.msg("审批人员不能为空!");
                        fgg=true;
                    }
                    auditRoleId="";
                    auditRoleName="";
                }
                var vo={
                    sort:index+1,
                    name:itemName,
                    roleId:auditRoleId,
                    roleName:auditRoleName,
                    rejectStepName:rejectStep
                    ,itemName:itemName
                    ,auditMethod:auditMethod
                    ,auditType:auditType
                    ,empUserId:empUserId
                    ,ccUserId:ccUserId
                };
                stepS.push(vo);
            });
            if(fgg){
                $("#tijiaoBtn").removeAttr("disabled");
                return;
            }
            var date={
                def:def,
                submitStep:submitStep,
                steps:stepS,
                processId:processId,

            }

            console.log(date);

            ckeckFi = true;

            $.ajax({
                url:'${ctx}/set/process/updateProcessDef',
                method:'post',
                contentType : "application/json;charsetset=UTF-8",
                data:JSON.stringify(date),
                success:function(res){
                    console.log(res);
                    if(res.code=="200"){
                        parent.layer.msg("保存成功",{time:2000});
                        cancels();
                        parent.table.reload('test');
                    }else{
                        layer.msg(res.errMsg,{time:2500},function(){
                            ckeckFi=false;
                            $("#tijiaoBtn").removeAttr("disabled"); //改变提交按钮上的文字并将按钮设置为不可点击
                        });
                    }
                },
                complete:function (data) {
                }
            }) ;

        })


        form.on('select(submitType)', function (data) {
            var submitType = $(data.elem).find("option:selected").val();
            var $elem = $(data.elem);
            if('1'==submitType){   //平台角色
                $elem.parents(".roleP").find(".submitSet").removeClass("hide");
                $elem.parents(".roleP").find(".submitSet2").addClass("hide");
            }else if('2'==submitType){ //平台员工
                $elem.parents(".roleP").find(".submitSet2").removeClass("hide");
                $elem.parents(".roleP").find(".submitSet").addClass("hide");
            }else if('3'==submitType){
                $elem.parents(".roleP").find(".submitSet").addClass("hide");
                $elem.parents(".roleP").find(".submitSet2").addClass("hide");
            }
            form.render('select');
        })

    });


    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

    function cancels(){
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    }


    function delDiv(that){
        var count =$('.steps .stepDiv').length;
        var vae=$(that).parent().attr("data-index");
        if(count>1){
            $(that).parent().remove();

            $('.contentDiv').find('div[data-index='+vae+']').remove();
            var lis=$('.steps .stepDiv');
            $.each(lis,function(index,obj){  //index:索引obj:循环的每个元素
               /* $(obj).children('.stepTitle').text((index+1)+'级节点');*/
                $(obj).attr("data-index",index+1);
            });
            var lis2=$('.contentDiv .itex:gt(0)');
            $.each(lis2,function(index,obj){  //index:索引obj:循环的每个元素
                $(obj).attr("data-index",index+1);
                if(index>=(vae-1)){
                    var htm='<option value="">请选择</option><option value="提交节点">提交节点</option>';
                    $.each($('.stepTitle:gt(0)'),function(index2,obj){
                        if(index2<index){
                            htm+='<option value="'+$(obj).html()+'">'+$(obj).html()+'</option>';
                        }
                    })
                    $(obj).find("select[name='rejectStep']").html(htm);
                    form.render('select');
                }
            });
        }


    }

    //切换流程
    function  swichPress(){
        $(".steps").children(".step").on('click',function(){
            $(this).addClass('activeStep')
            $(this).siblings().removeClass('activeStep');

            var vae=$(this).attr("data-index");
            $('.contentDiv .itex').addClass("layui-hide");
            $('.contentDiv').find('div[data-index='+vae+']').removeClass("layui-hide");
        });
    }
    //添加流程
    function  addPress(){
        var count =$('.steps .stepDiv').length+1;
        var html='<div class="step stepLine stepDiv" data-index="'+count+'">'+
            '<div class="stepTitle">'+count+'级审批</div>'+
            '<div class="describe">审批人</div>'+
            '<span></span>'+
            '<b class="icon-close1" onclick="delDiv(this)">x</b>'+
            '</div>';
        $('.endStep').before(html);
        this.swichPress();

        var itemS='<option value="">请选择</option><option value="提交节点">提交节点</option>';
        var lis=$('.steps .stepDiv').not(':last');
        $.each(lis,function(index,obj){  //index:索引obj:循环的每个元素
            var teName= $(obj).children('.stepTitle').text();
            itemS+='<option value="'+teName+'">'+teName+'</option>';
        });
        $(".clonDiv").find("select[name='rejectStep']").html(itemS);
        $(".clonDiv").find("input[name='itemName']").val(count+'级审批');
        $(".contentDiv").append($(".clonDiv").clone(true));
        $(".contentDiv").find(".itex").addClass("layui-hide");
        $(".contentDiv").find(".clonDiv").removeClass("layui-hide");
        $(".contentDiv").find(".clonDiv").attr("data-index",count);
        $(".contentDiv").find(".clonDiv .submitSet2").attr("data-value",stepCount+1);
        $(".contentDiv").find(".clonDiv").removeClass("clonDiv");
        form.render('select');
        $(".contentDiv").find("select[name='empName']").attr("xm-select",'empName'+(stepCount+1));
        $(".contentDiv").find("select[name='copeFor']").attr("xm-select",'copeFor'+(stepCount+1));
        formSelects.render('empName'+(stepCount+1));
        formSelects.render('copeFor'+(stepCount+1));
        stepCount++;
    }

    function changeName(that){
        var itemName=$(that).val();
        var idx=$(that).parents(".itex").attr("data-index");
        var oldName= $('.steps .step').eq(idx).find(".stepTitle").text();
        $('.steps .step').eq(idx).find(".stepTitle").text(itemName);
        var list= $("select[name='rejectStep']").find("option");
        $.each(list,function(index,obj){
            if($(obj).text() == oldName){
                $(obj).val(itemName).text(itemName);
            }
        })
        form.render('select');
    }

</script>
</body>
</html>

