<!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">HIS支付</label>
                    <div class="layui-input-inline formWidthTwo">
                        <select id="c_zffs" class="">
                            <option value="">请选择支付方式</option>
                            <option th:each="payTypeObj : ${payTypeList}" th:value="${payTypeObj.dicvalue}"
                                    th:text="${payTypeObj.dicname}"></option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">三方支付</label>
                    <div class="layui-input-inline">
                        <select id="searchThirdPay" class="">
                            <option value="">请选择支付方式</option>
                            <option th:each="thirdPayObj : ${thirdPayList}" th:value="${thirdPayObj.dicvalue}"
                                    th:text="${thirdPayObj.dicname}"></option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">错账类型</label>
                    <div class="layui-input-inline formWidthTwo">
                        <select id="err_type" class="">
                            <option value="">请选择错账类型</option>
                            <option value="1">HIS单边账</option>
                            <option value="2">三方单边账</option>
                            <option value="3">差异账</option>
                            <option value="4">跨天差异账</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>
                <div class="layui-inline">
                    <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="search()"><i
                            class="layui-icon layui-icon-search"></i>查询
                    </button>
                    <button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="exportExcel()"><i
                            class="layui-icon">&#xe67d;</i>导出
                    </button>
                </div>
            </form>
        </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>
<div id="managerUnilateral" style="display:none;">
    <form id="updateUnilateral" class="layui-form layui-from-pane" style="margin-top:20px;">
        <input type="hidden" id="unilateralId">
        <input type="hidden" id="errType">
        <input type="hidden" id="payType">
        <input type="hidden" id="h_jyqd">
        <input type="hidden" id="i_ddh">
        <input type="hidden" id="tranID">
        <div class="layui-form-item">
            <label class="layui-form-label">错账类型:</label>
            <div class="layui-input-inline formWidthTwo">
                <input type="text" id="errTypeStr" class="layui-input formWidthTwo">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">处理方式:</label>
            <div class="layui-input-inline formWidthTwo">
                <select id="managerType" class="">

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">处理说明:</label>
            <div class="layui-input-block">
                <textarea id="remark" type="text/plain" style="width:350px;height: 200px;" placeholder="请输入说明内容"
                          class="layui-textarea "></textarea>
            </div>
        </div>
    </form>
</div>

<div id="managerDetail" style="display:none;">
    <form id="" class="layui-form layui-from-pane" style="margin-top:20px;">
        <div class="layui-form-item">
            <label class="layui-form-label">处理方式:</label>
            <div class="layui-input-inline formWidthTwo">
                <select id="managerTypeS" class="" disabled>

                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">处理说明：</label>
            <div class="layui-input-block">
                <textarea id="remarkS" type="text/plain" readonly style="width:350px;height: 200px;"
                          class="layui-textarea "></textarea>
            </div>
        </div>
    </form>
</div>
<!-- 表格操作栏 -->
<script type="text/html" id="barDemo">
    {{#  if(d.IS_MANAGER == '0'){ }}
    <a class="layui-btn layui-btn-xs" lay-event="manager">处理</a>
    {{#  }else{ }}
    <a class="layui-btn layui-btn-xs" lay-event="managerDetail">处理详情</a>
    {{#  } }}
</script>
</body>
<script th:inline="javascript">

    let payTypeList = [[${payTypeList}]];
    let thirdPayList = [[${thirdPayList}]];

    let layer, laydate, table, tree, form;
    let tableObj;

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

        //表格加载
        tableObj = table.render({
            elem: '#demo',
            height: 'full-' + ($(".toolbar").height() + 60),
            title: '交易明细',
            page: true,//开启分页
            limit: 20,
            limits: [20, 30, 50],
            //toolbar: '', //开启工具栏，此处显示默认图标，可以自定义模板
            defaultToolbar: [],
            id: 'test',
            //skin:'line',
            even: 'true',
            //size:'lg', 默认普通尺寸 sm 小 lg 大
            cols: [
                [
                    {field: 'TRADE_DATE', align: 'center', title: '交易日期', width: 120, sort: false},
                    {field: 'AMOUNT', align: 'center', title: 'HIS金额', width: 120, sort: false},
                    {
                        field: 'PAYTYPE',
                        align: 'center',
                        title: '支付方式',
                        width: 120,
                        sort: false,
                        templet: function (d) {
                            let result = "";
                            for (let i = 0; i < payTypeList.length; i++) {
                                let obj = payTypeList[i];
                                if (d.PAYTYPE === obj.dicvalue) {
                                    result = obj.dicname;
                                    break;
                                }
                            }
                            return result;
                        }
                    },
                    {field: 'I_JYJE', align: 'center', title: '三方金额', width: 120, sort: false},
                    {
                        field: 'I_JYQD',
                        align: 'center',
                        title: '支付方式',
                        width: 120,
                        sort: false,
                        templet: function (d) {
                            let result = "";
                            for (let i = 0; i < thirdPayList.length; i++) {
                                let obj = thirdPayList[i];
                                if (d.I_JYQD === obj.dicvalue) {
                                    result = obj.dicname;
                                    break;
                                }
                            }
                            return result;
                        }
                    },
                    {
                        field: 'ERR_TYPE',
                        align: 'center',
                        title: '错账类型',
                        width: 120,
                        sort: false,
                        templet: function (d) {
                            let str = "";
                            if (d.ERR_TYPE === '1') {
                                str = "HIS单边账";
                            } else if (d.ERR_TYPE === '2') {
                                str = "三方单边账";
                            } else if (d.ERR_TYPE === '3') {
                                str = "差异账";
                            } else if (d.ERR_TYPE === '4') {
                                str = "跨天差异账";
                            }
                            return str;
                        }
                    },
                    /*{field: 'LSH', align:'center',title: '流水号',width:120, sort: false},*/
                    {field: 'TRANID', align: 'center', title: 'HIS订单号', width: 240, sort: false},
                    {field: 'I_DDH', align: 'center', title: '订单号', width: 240, sort: false},
                    {field: 'HISOPERNUM', align: 'center', title: '操作员号', width: 240, sort: false},
                    {field: 'TRADETIME', align: 'center', title: '交易时间', width: 120, sort: false},
                    {
                        field: 'IS_MANAGER',
                        align: 'center',
                        title: '是否已处理',
                        width: 120,
                        sort: false,
                        templet: function (d) {
                            return d.IS_MANAGER === '1' ? '是' : '否';
                        }
                    },
                    {field: 'MANAGER_TIME', align: 'center', title: '处理时间', width: 120, sort: false},
                    {field: 'REMARK', align: 'center', title: '备注', width: 120, sort: false},
                    {title: '操作', align: 'center', width: 120, toolbar: '#barDemo', fixed: 'right'},
                ]
            ],
            data: []
        });

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

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

            if (obj.event === 'manager') {

                //H I S单边账操作：1、通过     2、不计统计 3、挂账 4、其他
                //银行单边账操作：1、原路返回 2、不计统计 3、挂账 4、其他
                let id = data.ID;
                let err_type = data.ERR_TYPE;
                let payType = data.PAYTYPE;

                $("#unilateralId").val(id);
                $("#errType").val(err_type);
                $("#payType").val(payType);
                $("#h_jyqd").val(data.I_JYQD);
                $("#i_ddh").val(data.I_DDH);
                $("#tranID").val(data.TRANID);
                $("#remark").val("");

                let str = "";
                if (err_type === '1') {
                    str = "HIS单边账";
                } else if (err_type === '2') {
                    str = "三方单边账";
                } else if (err_type === '3') {
                    str = "差异账";
                } else if (err_type === '4') {
                    str = "跨天差异账";
                }
                $("#errTypeStr").val(str);

                //判断类型 提供不同下拉框
                let htmlStr = "";
                $("#managerType").empty();
                htmlStr = htmlStr + "<option value=''>请选择处理方式</option>";

                if (err_type === '1') {
                    htmlStr = htmlStr + "<option value='" + 1 + "'>通过</option>";
                    htmlStr = htmlStr + "<option value='" + 2 + "'>不计统计</option>";
                    htmlStr = htmlStr + "<option value='" + 3 + "'>挂账</option>";
                    htmlStr = htmlStr + "<option value='" + 4 + "'>其他</option>";
                } else if (err_type === '2') {
                    htmlStr = htmlStr + "<option value='" + 1 + "'>原路返回</option>";
                    htmlStr = htmlStr + "<option value='" + 2 + "'>不计统计</option>";
                    htmlStr = htmlStr + "<option value='" + 3 + "'>挂账</option>";
                    htmlStr = htmlStr + "<option value='" + 4 + "'>其他</option>";
                } else {
                    htmlStr = htmlStr + "<option value='" + 2 + "'>不计统计</option>";
                    htmlStr = htmlStr + "<option value='" + 3 + "'>挂账</option>";
                    htmlStr = htmlStr + "<option value='" + 4 + "'>其他</option>";
                }

                $("#managerType").append(htmlStr);
                form.render('select');

                layer.open({
                    type: 1,
                    title: "处理单边账",
                    shade: 0,
                    area: ['500px', '500px'],
                    offset: 'auto',
                    content: $("#managerUnilateral"),
                    btn: ['确定', '取消'],
                    btnAlign: 'c',
                    yes: function (index, layero) {

                        let id = $("#unilateralId").val();
                        let errType = $("#errType").val();
                        let managerType = $("#managerType").val();
                        let remark = $("#remark").val();
                        let payType = $("#payType").val();
                        let c_zffs = $("#h_jyqd").val();


                        let url = "/unilateral/managerUnilateral";
                        let param = {};
                        param.id = id;
                        param.errType = errType;
                        param.managerType = managerType;
                        param.remark = remark;
                        param.payType = payType;
                        param.c_ysddh = $("#i_ddh").val();
                        param.platformTransId = $("#tranID").val();
                        param.trade_date = data.TRADE_DATE;
                        param.hisopercode = data.HISOPERCODE;
                        param.c_zffs = c_zffs;
                        param.payMethod = data.PAYMETHOD;

                        AjaxPostJson(url, param, function (result) {
                            if (result.errCode === '0') {
                                let num = tableObj.config.page.pages;
                                search(num);
                                layer.alert(result.errMsg);
                                layer.close(index);
                            } else {
                                layer.alert(result.errMsg);
                            }
                        });
                    },
                    btn2: function () {
                    }
                });
            } else if (obj.event === 'managerDetail') {
                let err_type = data.ERR_TYPE;
                let htmlStr = "";
                $("#managerTypeS").empty();
                if (err_type === '1') {
                    htmlStr = htmlStr + "<option value='" + 1 + "'>通过</option>";
                    htmlStr = htmlStr + "<option value='" + 2 + "'>不计统计</option>";
                    htmlStr = htmlStr + "<option value='" + 3 + "'>挂账</option>";
                    htmlStr = htmlStr + "<option value='" + 4 + "'>其他</option>";
                } else if (err_type === '2') {
                    htmlStr = htmlStr + "<option value='" + 1 + "'>原路返回</option>";
                    htmlStr = htmlStr + "<option value='" + 2 + "'>不计统计</option>";
                    htmlStr = htmlStr + "<option value='" + 3 + "'>挂账</option>";
                    htmlStr = htmlStr + "<option value='" + 4 + "'>其他</option>";
                } else {
                    htmlStr = htmlStr + "<option value='" + 2 + "'>不计统计</option>";
                    htmlStr = htmlStr + "<option value='" + 3 + "'>挂账</option>";
                    htmlStr = htmlStr + "<option value='" + 4 + "'>其他</option>";
                }

                $("#managerTypeS").append(htmlStr);
                $("#managerTypeS").val(data.MANAGERTYPE);
                form.render('select');

                $("#remarkS").val(data.REMARK);

                layer.open({
                    type: 1,
                    title: "处理详情",
                    shade: 0,
                    area: ['500px', '500px'],
                    offset: 'auto',
                    content: $("#managerDetail"),
                    btn: ['关闭'],
                    btnAlign: 'c',
                    yes: function (index, layero) {
                        layer.close(index);
                    },
                    btn2: function () {
                    }
                });
            }
        });

        form.on('select(searchPayType)', function (data) {
            $("#searchThirdPay").val("");
            form.render('select');
        });
        form.on('select(searchThirdPay)', function (data) {
            $("#searchPayType").val("");
            form.render('select');
        });

        search();
    });

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

        param.payType = $("#c_zffs").val();
        let thirdPay = $("#searchThirdPay").val();
        param.thirdPay = thirdPay;
        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);
        }

        param.err_type = $("#err_type").val();

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

    //导出
    function exportExcel() {
        let url = "/unilateral/exportUnilateral";
        let param = {};

        param.payType = $("#c_zffs").val();
        let thirdPay = $("#searchThirdPay").val();
        param.thirdPay = thirdPay;
        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;

        }

        param.err_type = $("#err_type").val();

        let dowloadName = "单边账明细";
        param.dowloadName = dowloadName;
        let load = layer.load();
        AjaxPostJson(url, param, function (data) {
            layer.close(load);
            if (data.errCode === "0") {
                let fileName = data.dlName;
                location.href = '/download?fileName=' + fileName + '&dowloadName=' + dowloadName;
            } else {
                layer.alert(data.errMsg);
            }
        });
    }
</script>
</html>