<!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>
                                <label>当前状态：</label>
                                <select name="status" th:with="type=${@dict.getType('status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </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-success" onclick="$.operate.addTab()" shiro:hasPermission="apply:record:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="apply:record:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="apply:record:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <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/record";

        $(function() {
            let options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                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 = [];
                        /**新建状态**/
                        if(row.status == 0){
                            actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="report(\'' + row.id + '\')"><i class="fa fa-check"></i>提交审核</a> ');
                            actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }else{
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="detail(\'' + row.id + '\')"><i class="fa fa-search"></i>查看详情</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /**提交审核**/
        function report(id) {
            $.modal.confirm("确认要提交审核吗?", function() {
                let url = ctx + "applyData/record/updateStatus";
                $.operate.post(url,{ "id": id, "status": "3" });
            });
        }

        /**查看详情**/
        function detail(id) {
            $.modal.openTab("查看详情", prefix + "/detail/"+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>
