<!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('同步解析失败详情列表')" />
    <style>
        .div_tdContent{
            white-space:nowrap;
            overflow:hidden;
            text-overflow:ellipsis;
        }
        .tooltip-inner{
            word-wrap: break-word;
        }
    </style>
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse ">
                <form id="formId" class="form-horizontal m">
                    <div class="row">
                        <input type="hidden" name="packageId" th:value="${packageId}">
                        <label class="control-label col-sm-2  ">异常：</label>
                        <div class="col-sm-4 ">
                            <select class="form-control " name="exceptionType" onchange="$.table.search()" >
                                <option value="">所有</option>
                                <option th:each="ex : ${exceptionTypeList}" th:text="${ex}" th:value="${ex}"></option>
                            </select>
                        </div>
                        <label class="control-label col-sm-2  ">类型：</label>
                        <div class="col-sm-4 ">
                            <select class="form-control " name="failLevel" th:with="type=${@dict.getType('sync_fail_level')}" onchange="$.table.search()">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </div>
                    </div>
                    <div class="row">
                        <label class="control-label col-sm-2  ">原因包含：</label>
                        <div class="col-sm-4 ">
                            <input class="form-control" type="text" name="failReason" th:value="${failReason}">
                        </div>
                        <label class="control-label col-sm-2  ">数据包含：</label>
                        <div class="col-sm-4 ">
                            <input class="form-control" type="text" name="dataJson" th:value="${dataJson}">
                        </div>

                    </div>
                    <data class="row">
                        <div class="form-group col-sm-4 row ">
                            <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>
                        </div>

                    </data>

                </form>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" style='table-layout:fixed;'></table>
            </div>
        </div>

    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var datas = [[${@dict.getType('sync_fail_level')}]];
        var prefix = ctx + "sync/synclog";
        var packageId = [[${packageId}]]
        $(function() {
            var options = {
                url: prefix + "/faildetaillist",
                updateUrl: prefix + "/edit/{id}",
                modalName: "同步解析失败详情",
                responseHandler: responseHandler,
                /*queryParams:{
                    packageId:packageId
                },*/
                columns: [
                 {
                     field : 'exceptionType',
                     title : '异常',
                     width : '30%',
                     show : true
                 },
                {
                    field : 'failLevel',
                    title : '错误等级',
                    width : '10%',
                    show : true,
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field : 'failReason', 
                    title : '失败原因',
                    width : '15%',
                    formatter: function(value, row, index) {

                        var reg = new RegExp( '"' , "g" )
                        if(value!==null&&value!=""){
                            value = value.replace(reg,'&quot;');
                            var htmlStr = '<div data-original-title="'+value+'"' +
                                'data-placement="bottom" data-toggle="tooltip" data-html="true"'+
                                'class="div_tdContent">'+value+'</div>';
                            return htmlStr;
                        }
                    }
                },
                {
                    field : 'dataJson', 
                    title : '数据json',
                    width : '15%',
                    formatter: function(value, row, index) {
                        var reg = new RegExp( '"' , "g" )
                        if(value!==null&&value!=""){
                            value = value.replace(reg,'&quot;');
                            var htmlStr = '<div data-original-title="'+value+'"' +
                                'data-placement="bottom" data-toggle="tooltip" data-html="true"'+
                                'class="div_tdContent">'+value+'</div>';
                            return htmlStr;
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    width: '30%',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="copyValue('+index+',\'failReason\')"><i class="fa fa-edit"></i>复制错误</a> ');
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="copyValue('+index+',\'dataJson\')"><i class="fa fa-edit"></i>复制json</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function responseHandler(){
            $('[data-toggle="tooltip"]').tooltip();
        }
        function copyValue(index,data){
            var rows=$('#bootstrap-table').bootstrapTable('getData')
            var value = rows[index][data];
            var oInput = document.createElement('input');
            oInput.value = value;
            document.body.appendChild(oInput);
            oInput.select(); // 选择对象
            document.execCommand("Copy"); // 执行浏览器复制命令
            oInput.className = 'oInput';
            oInput.style.display='none';
            alert('复制成功');


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