<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html>
<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" type="text/css" href="${ctxPlugin}/static/css/reset.css" />
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/formSelects-v4.css" media="all">
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/lib/font/iconfont.css" />
    <style>
        .perm {
            padding-right: 5px;
        }
    </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_SJBG_DSH_T" html='<a href="${ctx}/entryChanges/designInfo/waitAuditList"><li class="layui-this">待审核</li></a>'/>
                <sfTags:pagePermission authFlag="DZBG_SJBG_BGJL_T" html='<a href="${ctx}/entryChanges/designInfo/changeList"><li class="">变更记录</li></a>'/>
                <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" id="searchBtn" lay-submit lay-filter="LAY-user-back-search"><i class="layui-icon fs-12">&#xe615;</i>查询</button>
            </ul>
        </div>
        <div class="layui-card-body layuiadmin-card-header-auto" >
            <form class="layui-form layui-card" action="" 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" class="layui-input" autocomplete="off">
                    </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="stationCode" class="layui-input" autocomplete="off">
                    </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" class="layui-input" autocomplete="off">
                    </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>
            </form>
        </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">
                <div class="layui-btn-container">
                    <c:if test="${user.userType eq '6' || user.userType eq '7'}">
                    <sfTags:pagePermission authFlag="DZBG_SJBG_DSH_ADD_B" html='<button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-ok-circle"></i>新增申请</button>'/>
                    </c:if>
                    <sfTags:pagePermission authFlag="DZBG_SJBG_DSH_EXPORT_B" html='<button class="layui-btn layui-btn-sm" lay-event="export" id="exportBtn"><i class="layui-icon layui-icon-export"></i>导出列表</button>'/>
                </div>
            </script>
        </div>
    </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/lib/formSelects-v4.js"></script>
<script>
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form'], function(){
        //layui.use(['table','layer','laypage','laydate','form'], function(){
        $ = layui.$;
        tableExt = layui.tableExt;
        layer = layui.layer;
        laypage = layui.laypage;
        laydate = layui.laydate;
        form = layui.form;
        table = tableExt.getLayTable();
        var type = "${user.userType}";
        var userId = "${user.id}";

        //开始日期
        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
                });
            }
        });

        let auditPerm = '${fns:checkPagePermission(request, "DZBG_SJBG_DSH_AUDIT_B")}';
        let cancelPerm = '${fns:checkPagePermission(request, "DZBG_SJBG_DSH_CANCEL_B")}';
        let viewPerm = '${fns:checkPagePermission(request, "DZBG_SJBG_DSH_VIEW_B")}';
        let isTrader = ${user.userType eq '6' || user.userType eq '7'};

        let cols = [
            {type: 'numbers',fixed:'left',title:'序号'}
            , {field: 'id', title: '操作', minWidth: '100', sort: false, align: 'center', exportable: false
                ,templet: function (d) {
                    let html = "";
                    if (auditPerm === '0' && d.review_flag) {
                        html += "<a href=\"#\" class=\"layui-table-link layui-icon perm \" style='font-size:14px;' onclick=\"audit('" + d.id + "','"+d.partner_id+"')\">审核</a>";
                    }
                    if (cancelPerm === '0' && isTrader && userId==d.create_by) {
                        html += "<a href=\"#\" class=\"layui-table-link layui-icon perm \" style='font-size:14px;' onclick=\"cancel('" + d.id + "')\">撤回</a>";
                    }
                    return html;
                }}
            , {field: 'number', title: '变更单号', minWidth: '100', sort: false, align: 'center', exportable: true
                ,templet: function (d) {
                    if (viewPerm === '0') {
                        return "<a class=\"layui-table-link   \"  onclick=\"showDetail('" + d.id + "','"+d.partner_id+"')\">" + d.number + "</a>";
                    } else {
                        return d.number;
                    }
                }
            }
            , {field: 'num', title: '变更次数', minWidth: '100', sort: false, align: 'center', exportable: true}
            , {field: 'power_station_code', title: '电站编码', minWidth: '100', sort: false, align: 'center', exportable: true}
            , {field: 'partner_name', title: '所属资方', minWidth: '100', sort: false, align: 'center', exportable: true}
            , {field: 'tenant_name', title: '业主姓名',minWidth:'150', sort: false, align: 'center',exportable:true}
            , {field: 'id_code', title: '身份证号',minWidth: 150, sort: false, align: 'center',exportable:true}
            , {field: 'creator', title: '变更申请人',minWidth:'180', sort: false, align: 'center',exportable:true}
            , {field: 'create_time', title: '申请时间',minWidth:'100', sort: false, align: 'center',exportable:true}
        ];

        tableExt.render({
            elem: '#test'
            , title:'设计变更'
            , height: 'full-180'
            , toolbar: '#toolbarDemo'
            , defaultToolbar: false
            , limits : [ 20, 50, 100 ]
            , limit:20
            , page : true //开启分页
            , url: '${ctx}/entryChanges/designInfo/listData'
            , cols: [cols] ,done:function(res,cuss,count){
            }
            ,exportOpt:{                            //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '设计信息变更',          //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 5000,                    //当pageData为false生效
                fileName: '设计信息变更',
                where: function (){                 //当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

        table.on('toolbar(test)', function (obj) {
            console.log('current obj is:', obj);
            if (obj.event === 'add') {
                layer.open({
                    type: 2,
                    content: '${ctx}/change/common/choosePartner?type=3',
                    title: '请选择资方',
                    area: ['50%', '50%']
                });
            }
        });

        //监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;
            //执行重载
            tableExt.reload('test', {
                where: field,
                page:{
                    curr:1
                }
            });
        });
        $('input').on('keydown', function(event){
            if(event.keyCode == 13){
                //执行相关操作
                $("#searchBtn").click();
            }
        });
    })

    //审核
    function audit(id,partnerId){
        layer.open({
            type: 2
            , title: '审核'
            , content: '${ctx}/entryChanges/designInfo/toAuditPage/' + id +'/' + partnerId
            , area: ['100%', '100%']
            , yes: function (index, layero) {
            }
        });
    }

    function cancel(id) {
        let indexla = layer.confirm('确定撤回吗？', {
            btn: ['确定', '取消'] //按钮
        }, function() {
            layer.close(indexla);
            $.ajax({
                url: "${ctx}/entryChanges/designInfo/cancelAddDesign/" + id,
                type: "POST",
                success: function (data) {
                    if (data.code === "200") {
                        top.layer.msg("操作成功");
                        searchOrder();
                    } else {
                        layer.msg(data.errMsg);
                    }
                },
                error: function () {
                    layer.msg('系统忙，请稍后再试')
                }
            });
        }, function() {
        });
    }

    function searchOrder() {
        //执行重载
        var wherobj =_serializeJson($("#searchForm"));
        tableExt.reload('test', {
            where: wherobj
        });
    }

    //查看详情
    function showDetail(id,partnerId){
        layer.open({
            type: 2
            , title: '变更详情'
            , content: '${ctx}/entryChanges/designInfo/toChangeDetail/' + id+'/' + partnerId
            , area: ['100%', '100%']
            , yes: function(index, layero){
            }
        });
    }

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

    function reset(){
        layui.form.render();
        $("#searchForm").find("select").val("");
        $("#searchForm").find("input").val("");
    }
</script>
</body>
</html>

