<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>对账记录</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" th:href="@{/css/common.css}">
    <!-- 引入组件库 -->
    <script th:src="@{/layui/jquery-3.4.1.min.js}"></script>
    <script th:src="@{/layui/layui.js}"></script>
    <script th:src="@{/layui/lay/xmSelect/xm-select.js}"></script>
    <script th:src="@{/js/common.js}"></script>

    <style>
        body{background: #f2f2f2}
        #boxDiv{background: #ffffff}
        #titleDiv{overflow: visible;}
        .content{padding:0 8px;}
        .tableTitle{height:20px;margin-top: 10px;margin-bottom: 10px;}
        .tableTitle>*{height: 20px;line-height: 20px;display: inline-block;margin-right: 5px;}
        .tableName{border-left:3px solid #0000FF;padding-left:5px;font-size: 16px;font-weight: bold;}
        .selectDate{font-size: 14px;color: rgba(0,0,0,0.65)}
    </style>
</head>
<body class="layui-layout-body">
<div id="boxDiv" style="left:8px;right: 8px;bottom:8px;top:8px;position:absolute;">
    <div class="toolbar" id="titleDiv">
        <div style="display: inline-block;">
            <form class="layui-form">
                <div class="layui-inline">
                    <label class="layui-form-label">对账结果</label>
                    <div class="layui-input-inline">
                        <select id="searchStatus">
                            <option value="">请选择对账结果</option>
                            <option value="1">完成</option>
                            <option value="0">未完成</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">日期选择</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input formWidthTwo" id="searchDate" placeholder=" ~ " th:value="${startTime+' ~ '+endTime}">
                    </div>
                </div>
            </form>
        </div>
        <div class="layui-inline">
            <button class="layui-btn layui-btn-sm layui-btn-normal" data-type="search" id="search" onclick="search()"><i class="layui-icon layui-icon-search"></i>查询</button>
            <!--<button class="layui-btn layui-btn-sm layui-btn-normal" ><i class="layui-icon layui-icon-refresh-1"></i>重新获取</button>-->
        </div>
    </div>
    <div class="content">
        <div class="tableTitle">
            <span class="tableName">对账记录日志表</span>
            <span class="selectDate">&nbsp;</span>
        </div>
        <table id="demo" lay-filter="test"></table>
    </div>

</div>
<!-- 表格操作栏 -->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="restartGet">重新对账</a>
</script>
</body>
<script th:inline="javascript">
    let layer,laydate,table,tree,form;

    layui.use(['element','table','laydate','layer','form','tree'], function() {
        layer = layui.layer;
        table = layui.table;
        laydate = layui.laydate;
        tree = layui.tree;
        form = layui.form;

        //表格加载
        table.render({
            elem: '#demo',
            height: 'full-'+($(".toolbar").height()+60),
            title: 'HIS账单日志记录',
            page: true ,//开启分页
            limit:20,
            limits:[20,30,50],
            //toolbar: '', //开启工具栏，此处显示默认图标，可以自定义模板
            defaultToolbar: [],
            id:'test',
            //skin:'line',
            even:'true',
            //size:'lg', 默认普通尺寸 sm 小 lg 大
            cols: [
                [ //表头
                    {type: 'numbers', title: '序号', width: 50},
                    {field: 'TRADE_DATE', title: '交易日期', sort: false},
                    // {field: 'MERCHANT_NAME', title: '商户名称', sort: false},
                    // {field: 'MERCHANT_ID', title: '商户编码', sort: false},
                    {field: 'MODIFY_TIME', title: '修改时间', sort: false},
                    {field: 'MANAGER_NUM', title: '对账次数', sort: false},
                    {field: 'STATUS', title: '对账状态', sort: false,templet: function(d){
                        return d.STATUS==='1'?'完成':'未完成';
                    }},
                    {field: 'USER_NAME', title: '操作人员', sort: false},
                    /*{field: 'REMARK', title: '备注', sort: false},*/
                    {title: '操作', align:'center',width:150, toolbar: '#barDemo'},
                ]
            ],
            data:[]
        });

        //时间控件
        laydate.render({
            elem: '#searchDate'
            ,type: 'date'
            ,range: '~'
        });

        search();

        table.on('tool(test)', function(obj){
            selectData=obj.data;
            let data = obj.data;

            if(obj.event === 'restartGet') {
                //如果本来就获取成功的，弹出框提示
                if(data.STATUS==='1'){

                    layer.confirm("之前数据计算正常，确认重新计算数据？",function (index){
                        restartGet(data);
                        layer.close(index);
                    });
                }else{
                    restartGet(data);
                }
            }
        });
    });

    //重新获取
    function restartGet(data){
        let url="/reconciliationLog/restartManager";
        let param={};
        param.trade_date=data.TRADE_DATE;
        let load = layer.load();
        AjaxPostJson(url,param,function (resultDate) {
            layer.close(load);
            if (resultDate.errCode==="0"){
                layer.alert("重新对账成功");
            }else{
                layer.alert(resultDate.errMsg);
            }
        });
    }

    //查询
    function search(num){
        num=num===null?1:num;
        let url="/reconciliationLog/findReconciliationLogPageList";
        let param={};

        let status=$("#searchStatus").val();
        param.status=status;

        let date=$("#searchDate").val();
        if(date!==''){
            let time = date.split("~");
            let startTime=time[0].trim();
            let endTime=time[1].trim();

            param.startTime=startTime;
            param.endTime=endTime;

            $(".selectDate").text(startTime+" ~ "+endTime);
        }



        table.reload('test', {
            method: 'get',
            url:url,
            where: param,
            page: {
                curr: num
            }
        });

    }
</script>
</html>