<!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="docname"/>
                            </li>
                            <li>
                                <label>文件类型：</label>
                                <select name="doctype" th:with="type=${@dict.getType('trs_file_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label>创建时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginCreatetime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endCreatetime]"/>
                            </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="importExcel()" shiro:hasPermission="project:filejiaodui:add">
                    <i class="fa fa-plus"></i> 导入
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="project:filejiaodui:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="project:filejiaodui:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="project:filejiaodui: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">
        var editFlag = [[${@permission.hasPermi('project:filejiaodui:edit')}]];
        var removeFlag = [[${@permission.hasPermi('project:filejiaodui:remove')}]];
        var doctypeDatas = [[${@dict.getType('trs_file_type')}]];
        var prefix = ctx + "project/filejiaodui";

        $(function() {
            var options = {
                url: prefix + "/list",
                importUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                viewUrl: prefix + "/view/{id}",
                modalName: "文件校对",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'docname',
                    title: '文件名称'
                },
                {
                    field: 'doctype',
                    title: '文件类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(doctypeDatas, value);
                    }
                },
                {
                    field: 'createtime',
                    title: '创建时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="view(\'' + row.id + '\',\'' + row.docname + '\')"><i class="fa fa-eye"></i>校对</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        function view(id,docname) {
            table.set();
            $.modal.open(docname, viewUrl(id));
        }
        function viewUrl(id) {
            var url = "/404.html";
            if ($.common.isNotEmpty(id)) {
                url = table.options.viewUrl.replace("{id}", id);
            } else {
                var id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
                if (id.length == 0) {
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }
                url = table.options.viewUrl.replace("{id}", id);
            }
            return url;
        }
        // 导入数据
        function importExcel(formId, width, height) {
            table.set();
            var currentId = $.common.isEmpty(formId) ? 'importTpl' : formId;
            var _width = $.common.isEmpty(width) ? "400" : width;
            var _height = $.common.isEmpty(height) ? "230" : height;
            top.layer.open({
                type: 1,
                area: [_width + 'px', _height + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: '导入' + table.options.modalName + '数据',
                content: $('#' + currentId).html(),
                btn: ['<i class="fa fa-check"></i> 导入', '<i class="fa fa-remove"></i> 取消'],
                // 弹层外区域关闭
                shadeClose: true,
                btn1: function(index, layero){
                    var file = layero.find('#file').val();
                    if (file == '' || (!$.common.endWith(file, '.xls') && !$.common.endWith(file, '.xlsx')
                            && !$.common.endWith(file, '.doc') && !$.common.endWith(file, '.docx'))
                        && !$.common.endWith(file, '.pdf') && !$.common.endWith(file, '.txt')) {
                        $.modal.msgWarning("请检查文件。");
                        return false;
                    }
                    var index = top.layer.load(2, {shade: false});
                    $.modal.disable();
                    var formData = new FormData(layero.find('form')[0]);
                    $.ajax({
                        url: table.options.importUrl,
                        data: formData,
                        cache: false,
                        contentType: false,
                        processData: false,
                        type: 'POST',
                        success: function (result) {
                            if (result.code == web_status.SUCCESS) {
                                $.modal.close(index);
                                $.modal.closeAll();
                                $.modal.alertSuccess(result.msg);
                                $.table.refresh();
                            } else if (result.code == web_status.WARNING) {
                                $.modal.close(index);
                                $.modal.enable();
                                $.modal.alertWarning(result.msg)
                            } else {
                                $.modal.close(index);
                                $.modal.enable();
                                $.modal.alertError(result.msg);
                            }
                        },
                        complete: function () {
                            layero.find('#file').val('');
                        }
                    });
                }
            });
        }
    </script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“doc”、“docx”、“xls”、“xlsx”、“txt”、“pdf”格式文件！
            </font>
        </div>
    </form>
</script>
</html>