<%@ 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;}
    </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="DZBG_KHXXBG_DSH_T" html='<li class="layui-this sf-tab"><a href="${ctx}/entryChanges/customerInformationChange/changeWaitAuditList">待审核</a></li>'/>
                <sfTags:pagePermission authFlag="DZBG_KHXXBG_BGJL_T" html='<li class="sf-tab"><a href="${ctx}/entryChanges/customerInformationChange/changeList">变更记录</a></li>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " type="reset"  onclick="reset()" >
                    <i class="layui-icon fs-12">&#xe9aa;</i>
                    重置
                </button>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " lay-submit lay-filter="LAY-user-back-search" data-type="reload">
                    <i class="layui-icon fs-12">&#xe615;</i>
                    查询
                </button>
            </ul>
        </div>
        <div class="layui-card-body" id="searchForm">
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">变更单号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="number" id="number" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">电站编号：</label>
                    <div class="layui-input-block">
                        <input type="text" name="powerStationCode" id="powerStationCode" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm3">
                    <label class="layui-form-label">业主姓名：</label>
                    <div class="layui-input-block">
                        <input type="text" name="tenantName" id="tenantName" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-col-lg4 layui-col-sm6">
                    <label class="layui-form-label">申请时间：</label>
                    <div class="layui-input-block">
                        <div class="layui-col-xs5">
                            <input type="text" name="createTimeMin" class="layui-input" id="createEndStartTime" placeholder="开始日期" autocomplete="off">
                        </div>
                        <div class="layui-col-xs2 text-c lh-30">
                            —
                        </div>
                        <div class="layui-col-xs5">
                            <input type="text" name="createTimeMax" class="layui-input" id="createEndEndTime" placeholder="结束日期" autocomplete="off">
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class='layui-card'>
        <div class="layui-card-body">
            <table class="layui-hide" lay-skin="row" id="test" lay-filter="test"></table>
            <script type="text/html" id="toolbarDemo">
                <c:if test="${user.userType eq '6' || user.userType eq '7'}">
                    <sfTags:pagePermission authFlag="DZBG_KHXXBG_DSH_XZ_B" html='<button class="layui-btn layui-btn-sm" id="add" lay-event="add"><i class="layui-icon layui-icon-ok-circle"></i>新增申请</button>'/>
                </c:if>
                <sfTags:pagePermission authFlag="DZBG_KHXXBG_DSH_DC_B" html='<button class="layui-btn layui-btn-sm" lay-event="export" id="exportBtn"><i class="layui-icon layui-icon-export"></i>导出列表</button>'/>
            </script>
        </div>
    </div>

</div>


<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script type="text/html" id="table-toolbar">
    {{# if(d.status == '1'){ }}
    <sfTags:pagePermission authFlag="DZBG_KHXXBG_DSH_XZ_B" html='<a class="layui-table-opt-link" lay-event="edit">编辑</a>'/>
    {{# }else if(d.status == '2' && d.create_by =='${user.id}'){ }}
    <a class="layui-table-opt-link" lay-event="revokeChangeRecord">撤回</a>
    {{# }else if(d.status == '2' && d.review_flag){ }}
    <sfTags:pagePermission authFlag="DZBG_KHXXBG_DSH_SH_B" html='<a class="layui-table-opt-link" lay-event="audit">审核</a>'/>
    {{# } }}

</script>

<script type="text/javascript">
    var table;
    var $;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laydate','form'], function(){
        $ = layui.jquery;
        tableExt = layui.tableExt;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var  form = layui.form;
        table = tableExt.getLayTable();
        //开始日期
        var endStartTime = laydate.render({
            elem: '#createEndStartTime'
            ,done: function(value, date){
                //更新结束日期的最小日期
                endEndTime.config.min = lay.extend({}, date, {
                    month: date.month - 1
                });
                //自动弹出结束日期的选择器
                endEndTime.config.elem[0].focus();
            }
        });
        //结束日期
        var endEndTime = laydate.render({
            elem: '#createEndEndTime'
            ,done: function(value, date){
                //更新开始日期的最大日期
                endStartTime.config.max = lay.extend({}, date, {
                    month: date.month - 1
                });
            }
        });

        tableExt.render({
            elem: '#test'
            ,toolbar : '#toolbarDemo'
            , height: 'full-180'
            ,defaultToolbar : false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            ,url: '${ctx}/entryChanges/customerInformationChange/getListData?status=2'
            ,cols: [[
                {type: 'numbers',title:'序号'}
                ,{field:'id', title: '操作',toolbar: '#table-toolbar',align: 'center',minWidth: 150}
                ,{field:'number', title: '变更单号',align: 'center',exportable: true
                    ,templet: function (d) {
                        return "<a href=\"#\" class=\"layui-table-link \" onclick=\"lookDetail('" + d.id + "')\">" + d.number + "</a>";
                }}
                ,{field:'change_count', title: '变更次数',align: 'center',exportable: true}
                ,{field:'power_station_code', title: '电站编号',align: 'center',exportable: true}
                ,{field:'tenant_name', title: '业主姓名',align: 'center',exportable: true}
                ,{field:'create_name', title: '变更申请人',align: 'center',exportable: true}
                ,{field:'createTime', title: '申请时间',align: 'center',exportable: true}
            ]]
            ,done: function(res, curr, count){

            },exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '客户信息变更-待审核列表',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '客户信息变更-待审核',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            switch (obj.event){
                case 'add':
                    layer.open({
                        title:'新增',
                        type: 2,
                        area: ["100%", "100%"],
                        content: '${ctx}/entryChanges/customerInformationChange/savaEntryChangePage'
                    })
                    break;

            }
        })

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            if(obj.event === 'audit'){
                layer.open({
                    title:'审核',
                    type: 2,
                    area: ["100%", "100%"],
                    content: '${ctx}/entryChanges/customerInformationChange/toChangeAudit?id='+data.id
                })
            }else if(obj.event ==='edit'){
                layer.open({
                    title:'新增',
                    type: 2,
                    area: ["100%", "100%"],
                    content: '${ctx}/entryChanges/customerInformationChange/savaEntryChangePage?id='+data.id
                })
            }else if(obj.event ==='revokeChangeRecord'){
                var indexla = layer.confirm('您确定要撤回该变更申请吗？', {
                    icon: 3,
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    $.ajax({
                        type: 'post',
                        url: '${ctx}/entryChanges/customerInformationChange/revokeChangeRecord',
                        dataType: 'json',
                        data: {
                            id:data.id
                        },
                        success: function(data){
                            if (data.code == "200") {
                                top.layer.msg("操作成功");
                                reload();
                                layer.close(indexla);
                            } else {
                                layer.msg(data.errMsg);
                                layer.close(indexla);
                            }
                        },
                        complete: function(){

                        }
                    });
                }, function () {
                    layer.close(indexla);
                });
            }
        });

        //监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;
            //执行重载
            table.reload('test', {
                where: field,
                page:{
                    curr:1
                }
            });
        });



    });


    function reload(){
        table.reload('test', {
            page:{
                curr:1
            }
        });
    }

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }

    function lookDetail(id){
        layer.open({
            title:'变更详情',
            type: 2,
            area: ["100%", "100%"],
            content: '${ctx}/entryChanges/customerInformationChange/toChangeAudit?form=look&id='+id
        })
    }

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

