<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <!--(his和银联对账结果)-->
    <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)
        }

        .layui-table-page {
            height: 81px;
        }
    </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">
                        <select id="searchPayType" lay-filter="searchPayType" 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" lay-filter="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">
                        <select id="searchOper" lay-filter="searchOper" class="">
                            <option value="">请选择操作员</option>
                            <option th:each="oper : ${operList}" th:value="${oper.HISOPERCODE}"
                                    th:text="${oper.USER_NAME}"></option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">业务类型</label>
                    <div class="layui-input-inline">
                        <select id="searchBizType" lay-filter="searchBizType" class="">
                            <option value="">请选择业务类型</option>
                            <option th:each="bizType : ${bizTypeList}" th:value="${bizType.dicvalue}"
                                    th:text="${bizType.dicname}"></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>
</body>
<script th:inline="javascript">
    let payTypeList = [[${payTypeList}]];
    let thirdPayList = [[${thirdPayList}]];
    let operList = [[${operList}]];
    let bizTypeList = [[${bizTypeList}]];
    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: '对账明细',
            page: true,//开启分页
            limit: 20,
            limits: [20, 30, 50],
            //toolbar: '', //开启工具栏，此处显示默认图标，可以自定义模板
            defaultToolbar: [],
            id: 'test',
            //skin:'line',
            even: 'true',
            //size:'lg', 默认普通尺寸 sm 小 lg 大
            cols: [
                [
                    {
                        field: 'BIZTYPE', align: 'center', title: '业务类别', width: 100, templet: function (d) {
                            let result = "";
                            for (let i = 0; i < bizTypeList.length; i++) {
                                let obj = bizTypeList[i];
                                if (d.BIZTYPE === obj.dicvalue) {
                                    result = obj.dicname;
                                    break;
                                }
                            }
                            return result;
                        }
                    },
                    {
                        field: 'H_JYLX', align: 'center', title: '交易状态', width: 100, templet: function (d) {
                            let str = "";
                            if (d.H_JYLX !== '') {
                                str = d.H_JYLX === '1' ? '收款记录' : '退款记录';
                            }
                            return str;
                        }
                    },
                    {
                        field: 'PAYTYPE', align: 'center', title: '支付方式', width: 100, 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: 'TRANID', align: 'center', title: 'HIS订单号', width: 240, sort: false},
                    {field: 'AMOUNT', align: 'center', title: '金额', width: 100, sort: false},
                    {field: 'TRADETIME', align: 'center', title: '交易时间', width: 180, sort: false},
                    {field: 'TRADE_DATE', align: 'center', title: '交易日期', width: 180, sort: false},
                    {
                        field: 'HISOPERNUM', align: 'center', title: '操作员号', width: 100, sort: false,
                        templet: function (d) {
                            let result = "";
                            for (let i = 0; i < operList.length; i++) {
                                let obj = operList[i];
                                if (d.HISOPERNUM === obj.HISOPERCODE) {
                                    result = obj.USER_NAME;
                                    break;
                                }
                            }
                            return result;
                        }
                    },
                    {field: 'PATIENTNAME', align: 'center', title: '患者姓名', width: 100, sort: false},
                    {
                        field: 'I_JYQD',
                        align: 'center',
                        title: '支付方式',
                        width: 100,
                        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: 'I_DDH', align: 'center', title: '订单号', width: 240, sort: false},
                    {
                        field: 'I_JYLX', align: 'center', title: '交易状态', width: 100, templet: function (d) {
                            let str = "";
                            if (d.I_JYLX !== '') {
                                str = d.I_JYLX === '1' ? '收款记录' : '退款记录';
                            }
                            return str;
                        }
                    },
                    {field: 'I_JYJE', align: 'center', title: '金额', width: 100, sort: false},
                    {field: 'JYSJ', align: 'center', title: '交易时间', width: 180, sort: false},
                ]
            ],
            data: []
        });

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

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

        search();

    });


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

        let payType = $("#searchPayType").val();
        param.payType = payType;
        let thirdPay = $("#searchThirdPay").val();
        param.thirdPay = thirdPay;
        let operCode = $("#searchOper").val();
        param.operCode = operCode;
        let BizType = $("#searchBizType").val();
        param.BizType = BizType;
        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
            }
        });


        //查询总数
        let url2 = "/transactionDetail/findHisAndThirdJoinCountData";
        AjaxPostJson(url2, param, function (data) {
            if (data.errCode === '0') {
                let thirdNum = data.thirdNum;
                let thirdMoney = data.thirdMoney;
                let thirdReceiveMoney = data.thirdReceiveMoney;
                let thirdRefundMoney = data.thirdRefundMoney;
                let HISNum = data.HISNum;
                let HISMoney = data.HISMoney;
                let HISReceiveMoney = data.HISReceiveMoney;
                let HISRefundMoney = data.HISRefundMoney;
                // let refundNum = "0";
                // let refundMoney = "0";
                let htmlStr = "<div style='height: 40px;width: 100%;font-size: 14px;'>" +
                    // "第三方交易笔数共" + thirdNum + "笔,汇总金额" + thirdMoney + "元；HIS交易共" + HISNum + "笔，汇总金额" + HISMoney + "元；退费交易笔数共" + refundNum + "笔，退费汇总金额" + refundMoney + "元。"
                    "第三方交易笔数共" + thirdNum + "笔,收款总计" + thirdReceiveMoney + "元，退款总计" + thirdRefundMoney + "元，汇总金额" + thirdMoney + "元；HIS交易共" + HISNum + "笔，收款总计" + HISReceiveMoney + "元，退款总计" + HISRefundMoney + "元，汇总金额" + HISMoney + "元；"
                "</div>";
                $(".layui-table-page").prepend(htmlStr);
            } else {
                /*let htmlStr="<div style='height: 40px;width: 100%;font-size: 14px;'></div>";
                $(".layui-table-page").prepend(htmlStr);*/
            }
        });
    }

    //导出
    function exportExcel() {
        let url = "/transactionDetail/exportHisAndThirdJoinCount";
        let param = {};

        param.payType = $("#searchPayType").val();
        let thirdPay = $("#searchThirdPay").val();
        param.thirdPay = thirdPay;
        let operCode = $("#searchOper").val();
        param.operCode = operCode;
        let BizType = $("#searchBizType").val();
        param.BizType = BizType;
        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;

        }

        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>