<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <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/dist/viewer.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/formSelects-v4.css" media="all">
    <style>
        .memberDiv{
            margin-left: 20px;
        }
        .layui-col-sm10 {
            width: 86.333333%;
        }
    </style>
</head>
<body>
<div class="aaa" id="LAY_app">
    <div class="layui-form layui-card">
        <div class="layui-card-body" action="" id="detailSet">
            <div class="layui-row">
                <div class="layui-card">
                    <div class="layui-row layui-col-space12 layui-form-item">
                        <div class="layui-col-lg10 layui-col-sm10">
                            <label class="layui-form-label"><i class="mark">*</i>代理商：</label>
                            <div class="layui-input-block">
                                <select class="traderId" id="traderId" name="traderId" lay-verify="traderId" lay-filter="traderId" lay-search>
                                    <option value="">请选择</option>
                                    <c:forEach items="${traderList}" var="trader">
                                        <option value="${trader.columns.id}" <c:if test="${reviewSetting.traderId == trader.columns.id}">selected</c:if>>${trader.columns.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-lg12 layui-col-sm12">
                            <label class="layui-form-label"><i class="mark">*</i>设计审核：</label>
                        </div>
                        <div class="layui-col-lg5 layui-col-sm5 memberDiv">
                            <label class="layui-form-label">审核人员：</label>
                            <div class="layui-input-block">
                                <select name="sjEmp" id="sjEmp" lay-filter="sjEmp" lay-verify="required">
                                    <option value="">请选择</option>
                                    <c:forEach items="${empSj}" var="item">
                                        <option value="${item.columns.id}" title="${item.columns.name}" <c:if test="${sjMainStr == item.columns.id}">selected</c:if>>${item.columns.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-lg5 layui-col-sm5 memberDiv">
                            <label class="layui-form-label">备选人员：</label>
                            <div class="layui-input-block">
                                <select  id="sjbxEmp" name="sjbxEmp"  lay-filter="sjbxEmp" lay-verify="required" xm-select="sjbxEmp"  xm-select-type="1" xm-select-height="40px" xm-select-show-count="6" xm-select-search>
                                    <option value="">请选择</option>
                                    <c:forEach items="${empSj}" var="item">
                                        <option value="${item.columns.id}" <c:if test="${sjSpareStr == item.columns.id}">selected</c:if>>${item.columns.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-lg12 layui-col-sm12 ">
                            <label class="layui-form-label"><i class="mark">*</i>档案审核：</label>
                        </div>
                        <div class="layui-col-lg5 layui-col-sm5 memberDiv">
                            <label class="layui-form-label">审核人员：</label>
                            <div class="layui-input-block">
                                <select  id="daEmp" name="daEmp"  lay-filter="daEmp" lay-verify="required">
                                    <option value="">请选择</option>
                                    <c:forEach items="${empDa}" var="item">
                                        <option value="${item.columns.id}" <c:if test="${daMainStr == item.columns.id}">selected</c:if>>${item.columns.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-lg5 layui-col-sm5 memberDiv">
                            <label class="layui-form-label">备选人员：</label>
                            <div class="layui-input-block">
                                <select  id="dabxEmp" name="dabxEmp"  lay-filter="dabxEmp" lay-verify="required" xm-select="dabxEmp"  xm-select-type="1" xm-select-height="40px" xm-select-show-count="6" xm-select-search>
                                    <option value="">请选择</option>
                                    <c:forEach items="${empDa}" var="item">
                                        <option value="${item.columns.id}" <c:if test="${daSpareStr == item.columns.id}">selected</c:if>>${item.columns.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-lg12 layui-col-sm12">
                            <label class="layui-form-label"><i class="mark">*</i>安装审核：</label>
                        </div>
                        <div class="layui-col-lg5 layui-col-sm5 memberDiv">
                            <label class="layui-form-label">审核人员：</label>
                            <div class="layui-input-block">
                                <select  id="azEmp" name="azEmp"  lay-filter="azEmp" lay-verify="required">
                                    <option value="">请选择</option>
                                    <c:forEach items="${empAz}" var="item">
                                        <option value="${item.columns.id}" <c:if test="${azMainStr == item.columns.id}">selected</c:if>>${item.columns.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-lg5 layui-col-sm5 memberDiv">
                            <label class="layui-form-label">备选人员：</label>
                            <div class="layui-input-block">
                                <select  id="azbxEmp" name="azbxEmp"  lay-filter="azbxEmp" lay-verify="required" xm-select="azbxEmp"  xm-select-type="1" xm-select-height="40px" xm-select-show-count="6" xm-select-search>
                                    <option value="">请选择</option>
                                    <c:forEach items="${empAz}" var="item">
                                        <option value="${item.columns.id}" <c:if test="${azSpareStr == item.columns.id}">selected</c:if>>${item.columns.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-lg12 layui-col-sm12">
                            <label class="layui-form-label"><i class="mark">*</i>并网审核：</label>
                        </div>
                        <div class="layui-col-lg5 layui-col-sm5 memberDiv">
                            <label class="layui-form-label">审核人员：</label>
                            <div class="layui-input-block">
                                <select  id="bwEmp" name="bwEmp"  lay-filter="bwEmp" lay-verify="required">
                                    <option value="">请选择</option>
                                    <c:forEach items="${empBw}" var="item">
                                        <option value="${item.columns.id}" <c:if test="${bwMainStr == item.columns.id}">selected</c:if>>${item.columns.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="layui-col-lg5 layui-col-sm5 memberDiv">
                            <label class="layui-form-label">备选人员：</label>
                            <div class="layui-input-block">
                                <select  id="bwbxEmp" name="bwbxEmp"  lay-filter="bwbxEmp" lay-verify="required" xm-select="bwbxEmp"  xm-select-type="1" xm-select-height="40px" xm-select-show-count="6" xm-select-search>
                                    <option value="">请选择</option>
                                    <c:forEach items="${empBw}" var="item">
                                        <option value="${item.columns.id}" <c:if test="${bwSpareStr == item.columns.id}">selected</c:if>>${item.columns.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item operate-footer" style="text-align: center;">
            <input type="button" lay-submit lay-filter="confirm" id="confirm" class="layui-btn " value="确认">
            <input type="button"   value="取消" class="layui-btn layui-btn-primary " onclick="closeDiv();" >
        </div>
    </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/data.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/dist/viewer.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/lib/formSelects-v4.js"></script>
<script type="text/javascript">
    var viewer = new Viewer(document.getElementById('LAY_app'));
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    var imgs='';
    var myreg=/^[1][3,4,5,6,7,8,9][0-9]{9}$/;
    var reg = /^(\d{2})(\d{4})(\d{4})(\d{2})(\d{2})\d{2}(\d)(\d|X)$/;
    var shuzi = /^\d+(\.\d+)?$/;
    var icReg=/^((-?)(([1-9][0-9]*)|(([0]\.\d{1,2}|[1-9][0-9]*\.\d{1,2}))|0))$/;
    var icReg2=/^[/]$/;
    layui.use(['form', 'table', 'upload', 'jquery','formSelects'], function () {
        $ = layui.jquery;
        form = layui.form;
        formSelects = layui.formSelects;
        upload = layui.upload;
        $form = $('form');
        var table = layui.table;

        var sjSpareStr = "${sjSpareStr}";
        formSelects.value('sjbxEmp', sjSpareStr.split(","), true);
        var daSpareStr = "${daSpareStr}";
        formSelects.value('dabxEmp', daSpareStr.split(","), true);
        var azSpareStr = "${azSpareStr}";
        formSelects.value('azbxEmp', azSpareStr.split(","), true);
        var bwSpareStr = "${bwSpareStr}";
        formSelects.value('bwbxEmp', bwSpareStr.split(","), true);

        table.init('parse-table-demo',{
            height: 75
        })

        form.on('submit(confirm)', function(data){
            var examine = {};
            var arr = [];
            var traderId = $("#traderId").find("option:selected").val();
            //设计审核
            var empsj = {};
            var sjEmp = $("#sjEmp").find("option:selected").val();
            var sjbxEmp =  formSelects.value('sjbxEmp', 'valStr');
            empsj.groupName = '设计审核';
            empsj.employeeId = sjEmp;
            empsj.flag = '1';
            var empsj1 = {};
            var empsj2 = {};
            var sjbxEmpArr = sjbxEmp.split(",");
            empsj1.groupName = '设计审核';
            empsj1.employeeId = sjbxEmpArr[0];
            empsj1.flag = '2';
            if(sjbxEmpArr.length == 2){
                empsj2.groupName = '设计审核';
                empsj2.employeeId = sjbxEmpArr[1];
                empsj2.flag = '3';
                arr.push(empsj2);
            }
            arr.push(empsj);
            arr.push(empsj1);
            //档案审核
            var empda = {};
            var daEmp = $("#daEmp").find("option:selected").val();
            var dabxEmp =  formSelects.value('dabxEmp', 'valStr');
            empda.groupName = '档案审核';
            empda.employeeId = daEmp;
            empda.flag = '1';
            var empda1 = {};
            var empda2 = {};
            var dabxEmpArr = dabxEmp.split(",");
            empda1.groupName = '档案审核';
            empda1.employeeId = dabxEmpArr[0];
            empda1.flag = '2';
            if(dabxEmpArr.length == 2) {
                empda2.groupName = '档案审核';
                empda2.employeeId = dabxEmpArr[1];
                empda2.flag = '3';
                arr.push(empda2);
            }
            arr.push(empda);
            arr.push(empda1);

            //安装审核
            var empaz = {};
            var azEmp = $("#azEmp").find("option:selected").val();
            var azbxEmp =  formSelects.value('azbxEmp', 'valStr');
            empaz.groupName = '安装审核';
            empaz.employeeId = azEmp;
            empaz.flag = '1';
            var empaz1 = {};
            var empaz2 = {};
            var azbxEmpArr = azbxEmp.split(",");
            empaz1.groupName = '安装审核';
            empaz1.employeeId = azbxEmpArr[0];
            empaz1.flag = '2';
            if(azbxEmpArr.length == 2) {
                empaz2.groupName = '安装审核';
                empaz2.employeeId = azbxEmpArr[1];
                empaz2.flag = '3';
                arr.push(empaz2);
            }
            arr.push(empaz);
            arr.push(empaz1);

            //并网审核
            var empbw = {};
            var bwEmp = $("#bwEmp").find("option:selected").val();
            var bwbxEmp =  formSelects.value('bwbxEmp', 'valStr');
            empbw.groupName = '并网审核';
            empbw.employeeId = bwEmp;
            empbw.flag = '1';
            var empbw1 = {};
            var empbw2 = {};
            var bwbxEmpArr = bwbxEmp.split(",");
            empbw1.groupName = '并网审核';
            empbw1.employeeId = bwbxEmpArr[0];
            empbw1.flag = '2';
            if(bwbxEmpArr.length == 2) {
                empbw2.groupName = '并网审核';
                empbw2.employeeId = bwbxEmpArr[1];
                empbw2.flag = '3';
                arr.push(empbw2);
            }
            arr.push(empbw);
            arr.push(empbw1);
            examine = {
                id:'${reviewSetting.id}',
                traderId:traderId,
                memberList:arr
            }
            console.log("======="+JSON.stringify(examine));
            if (isBlank(traderId)) {
                layer.msg("代理商不能为空!")
                return;
            }
            if (isBlank(sjEmp)) {
                layer.msg("设计审核人员不能为空!")
                return;
            }
            if (isBlank(daEmp)) {
                layer.msg("档案审核人员不能为空!")
                return;
            }
            if (isBlank(azbxEmp)) {
                layer.msg("安装审核人员不能为空!")
                return;
            }
            if (isBlank(bwEmp)) {
                layer.msg("并网审核人员不能为空!")
                return;
            }
            if(sjbxEmpArr.length == 0 || sjbxEmpArr.length > 2){
                layer.msg("设计备选人员不能为空并且不能最多可选择两人！")
                return;
            }
            if(dabxEmpArr.length == 0 || dabxEmpArr.length > 2){
                layer.msg("档案备选人员不能为空并且不能最多可选择两人！")
                return;
            }
            if(azbxEmpArr.length == 0 || azbxEmpArr.length > 2){
                layer.msg("安装备选人员不能为空并且不能最多可选择两人！")
                return;
            }
            if(bwbxEmpArr.length == 0 || bwbxEmpArr.length > 2){
                layer.msg("并网备选人员不能为空并且不能最多可选择两人！")
                return;
            }

            $.ajax({
                url:'${ctx}/priorReviewSetting/editPriorReviewSetting',
                method:'post',
                contentType : "application/json;charsetset=UTF-8",
                data:JSON.stringify(examine),
                dataType:'JSON',
                success:function(res){
                    if(res.code=="200"){
                        parent.layer.msg("保存成功",{time:1000});
                        closeDiv();
                        parent.table.reload('test');
                    } else if(res.code=="501") {
                        layer.msg(res.errMsg,{time:1500});
                    } else if(res.code == '422'){
                        layer.msg(res.msg,{time:1500});
                    } else{
                        layer.msg("保存失败",{time:1000});
                    }
                },
                error:function (data) {
                }
            })
        });

    })

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

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

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