<!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" style="display: none;">
                <form id="formId">
                    <input type="hidden" id="fieldId" name="fieldId" th:value="${fieldId}"/>
                    <div class="select-list">
                        <ul>
                            <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="toAdd()" shiro:hasPermission="spider:fieldRule:add">
                    <i class="fa fa-plus"></i> 添加规则
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="spider:fieldRule:remove">
                    <i class="fa fa-remove"></i> 删除规则
                </a>
                <a class="btn btn-warning" onclick="closeItem()">
                    <i class="fa fa-reply-all"></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('spider:fieldRule:edit')}]];
        var removeFlag = [[${@permission.hasPermi('spider:fieldRule:remove')}]];
        var processTypeDatas = [[${@dict.getType('field_value_process_type')}]];
        var prefix = ctx + "spider/fieldRule";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                modalName: "字段值处理规则",
                escape:true,
                columns: [{
                    checkbox: true
                },
                {field : 'id',title : 'ID',visible: false},
                {field : 'fieldId',title : '字段ID'},
                {field : 'processType',title : '数据处理规则',formatter: function(value, row, index) {
                       return $.table.selectDictLabel(processTypeDatas, value);
                    }
                },
                {field : 'replacereg',title : '替换正则'},
                {field : 'replacement',title : '替换内容'},
                {field : 'substrTarget',title : '截取字符串目标'},
                {field : 'sort',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="$.operate.edit(\'' + row.id + '\',\'\',400)"><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 toAdd(){
            var id=$("#fieldId").val();
            $.operate.add(id,'',400);
        }

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