<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
    <title>建站流程设置</title>
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
    <style>
        .layui-card {
            box-shadow: none;
        }

        .left-tree {
            height: calc(100vh - 130px);
            border-right: 1px solid #f0f0f0;
            margin-right: 15px;
            padding-left: 6px
        }

        .left-tree dt {
            font-size: 14px;
            font-weight: 600;
            padding: 5px 0;
        }

        .left-tree dd {
            padding: 5px 10px
        }

        .left-tree dd a.actived {
            color: #0a6597
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-form layui-card">
        <div class="layui-tab  layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="XTSZ_JZLCSZ_JZLCSZ_T"
                                       html='<a href="${ctx}/set/buildProcess/setting"><li class="layui-this">建站流程设置</li></a>'/>
            </ul>
        </div>
    </div>

    <div class='layui-card'>
        <div class="layui-card-body" style="display: flex;">
            <div style="width: 15%">
                <div class="left-tree" id="table1">
                    <dl>
                        <dt>电站资方名称</dt>
                        <c:forEach items="${partnerStep}" var="step">
                            <dl>
                                <dd><a rel="${step.id}" onclick="searchList(this)">${step.name}</a></dd>
                            </dl>
                        </c:forEach>
                    </dl>
                </div>
            </div>
            <div style="width: 85%;">
                <table class="layui-hide" lay-skin="row" id="test-table-reload" lay-filter="table-toolbar"></table>
            </div>
        </div>
    </div>

</div>


<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>

<script type="text/javascript">
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer', 'laydate'], function () {
        tableExt = layui.tableExt;
        var layer = layui.layer;
        $ = layui.jquery;
        form = layui.form;
        tableExt.render({
            elem: '#test-table-reload'
            , toolbar: false
            , defaultToolbar: false
            , height: 'full-90'
            , url: '${ctx}/set/buildProcess/processSetData'
            , cols: [[
                {type: 'numbers', title: '序号'}
                , {
                    field: 'stage', title: '阶段', align: 'center', templet: function (d) {
                        //01.信息登记 02.踏勘设计 03.电站安装 04.电站并网
                        if (d.stage == '01') {
                            return '信息登记';
                        } else if (d.stage == '02') {
                            return '踏勘设计';
                        } else if (d.stage == '03') {
                            return '电站安装';
                        } else if (d.stage == '04') {
                            return '电站并网';
                        }
                    }
                }
                , {field: 'name', title: '审核节点', align: 'center'}
                , {
                    field: 'must_flag', title: '是否必要节点', align: 'center'
                    , templet: function (d) {
                        //是否必要节点：0.否 1.是
                        if (d.must_flag == '0') {
                            return '否';
                        } else if (d.must_flag == '1') {
                            return '是';
                        }
                    }
                }
                , {
                    field: 'way', title: '审核方式', align: 'center'
                    , templet: function (d) {
                        //审核方式: 1.接口审核 2.系统审核
                        if (d.way == '1') {
                            return '接口审核';
                        } else if (d.way == '2') {
                            return '系统审核';
                        }
                    }
                }
                , {field: 'operate_name', title: '系统操作名称', align: 'center'}
                , {
                    field: 'status', title: '是否启用', align: 'center'
                    , templet: function (d) {
                        //是否启用：0.否 1.是
                        if(d.must_flag=='1'){
                            return '<input type="checkbox" data-id="' + d.id + '"  lay-text="是|否" lay-filter="status" name="status" lay-skin="switch" checked disabled>';
                        }else{
                            if (d.status == '0') {
                                return '<input type="checkbox" data-id="' + d.id + '" lay-text="是|否" lay-filter="status" name="status" lay-skin="switch">';
                            } else {
                                return '<input type="checkbox" data-id="' + d.id + '"  lay-text="是|否" lay-filter="status" name="status" lay-skin="switch" checked>';
                            }
                        }

                    }
                }
            ]]
            , done: function (res, curr, count) {
            }
        });

        form.on("switch(status)", function (obj) {
            //是否启用：0.否 1.是
            var status = "0";
            if ($(this).is(':checked')) {
                status = "1";
            }
            let processSetId = $(this).attr("data-id");
            var partnerId = $("#table1").find(".actived").attr("rel");
            var data = {"processSetId": processSetId, "partnerId": partnerId, "status": status};
            console.log(data);
            $.ajax({
                url: '${ctx}/set/buildProcess/editPartnerProcessSet',
                method: 'post',
                data: JSON.stringify(data),
                dataType: 'JSON',
                contentType: "application/json",
                success: function (res) {
                    if (res.code == "200") {
                        layer.msg("操作成功", {time: 2000});
                    } else {
                        layer.msg(res.errMsg, {time: 1000});
                    }
                },
                error: function (data) {
                }
            });

        });
    });

    function searchList(that) {
        $("#table1").find("a").each(function () {
            $(this).removeClass("actived");
        })
        $(that).addClass("actived");
        var partnerId = $(that).attr("rel");
        tableExt.reload('test-table-reload', {
            where: {"partnerId": partnerId}
        });
    }

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