<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('审批记录列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>提供部门：</label>
                            <input type="text" name="provideDeptName" onclick="selectDeptTree()" id="treeName" placeholder="请选择接口提供部门"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="apply:record:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    let editFlag = [[${@permission.hasPermi('apply:record:edit')}]];
    let removeFlag = [[${@permission.hasPermi('apply:record:remove')}]];
    let status = [[${@dict.getType('status')}]];
    let prefix = ctx + "applyData/approval";

    $(function() {
        let options = {
            url: prefix + "/list",
            exportUrl: prefix + "/export",
            modalName: "申请记录",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: 'null',
                    visible: false
                },
                {
                    field: 'provideDeptName',
                    title: '接口提供部门'
                },
                {
                    field: 'applyTime',
                    title: '申请时间',
                    sortable: true
                },
                {
                    field: 'duration',
                    title: '使用时效',
                    sortable: true
                },
                {
                    field: 'frequency',
                    title: '调用频次',
                    visible: false
                },
                {
                    field: 'status',
                    title: '当前状态',
                    sortable: true,
                    formatter: function (value, item, index) {
                        return $.table.selectDictLabel(status, item.status);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        let actions = [];
                        /**政数局待审批**/
                        actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="approval(\'' + row.id + '\')"><i class="fa fa-check"></i>立即审批</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /**审批**/
    function approval(id) {
        $.modal.openTab("申请审批", prefix + "/approval/"+id);
    }

    /**选择部门树**/
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero){
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }

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