<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>新建</title>
    <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <link rel="stylesheet" th:href="@{/lib/font-awesome-4.7.0/css/font-awesome.min.css}" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form class="layui-form" action="" lay-filter="formDemo">
    <div class="layui-form layuimini-form" style="padding-bottom: 100px">
        <div class="layui-form-item layui-inline" style="width: 100%">
            <label class="layui-form-label" style="width: 90px">报账名称</label>
            <div class="layui-input-inline" style="width: 800px">
                <input type="hidden" id="id" name="id" class="layui-input" th:value="${reimbursement.id}">
                <input type="text" id="mc" name="mc" class="layui-input" th:value="${reimbursement.mc}" readonly>
            </div>
        </div>
        <div class="layui-form-item layui-inline" style="width: 100%">
            <input type="hidden" id="fysq" name="fysq" class="layui-input" th:value="${reimbursement.fysq}">
            <label class="layui-form-label" style="width: 90px">费用类别</label>
            <div class="layui-input-inline" style="width: 380px">
                <input type="hidden" id="fylb" name="fylb" class="layui-input" th:value="${reimbursement.fylb}">
                <input type="text" id="fylbmc" name="fylbmc" class="layui-input" th:value="${reimbursement.fylbmc}"
                       readonly>
            </div>
            <label class="layui-form-label" style="width: 80px">申请金额(元)</label>
            <div class="layui-input-inline" style="width: 300px">
                <input type="number" id="sqje" name="sqje" class="layui-input" th:value="${reimbursement.sqje}"
                       readonly>
            </div>
        </div>
        <div class="layui-form-item layui-inline" style="width: 100%">
            <label class="layui-form-label" style="width: 90px">报账金额(元)</label>
            <div class="layui-input-inline" style="width: 380px">
                <input type="text" id="bzje" name="bzje" class="layui-input" autocomplete="off"
                       th:value="${reimbursement.bzje}" readonly>
            </div>
            <label class="layui-form-label" style="width: 80px">税率(%)</label>
            <div class="layui-input-inline" style="width: 300px">
                <input type="number" id="sl" name="sl" class="layui-input" th:value="${reimbursement.sl}" readonly>
            </div>
        </div>
        <div class="layui-form-item layui-inline" style="width: 100%">
            <label class="layui-form-label" style="width: 100px; margin-left: -10px">不含税金额(元)</label>
            <div class="layui-input-inline" style="width: 380px">
                <input type="number" id="bhsje" name="bhsje" class="layui-input" th:value="${reimbursement.bhsje}"
                       readonly>
            </div>
            <label class="layui-form-label" style="width: 80px">税费(元)</label>
            <div class="layui-input-inline" style="width: 300px">
                <input type="number" id="sf" name="sf" class="layui-input" th:value="${reimbursement.sf}" readonly>
            </div>
        </div>
        <div id="cl">
            <div class="layui-form-item" style="margin-bottom: -20px">
                <label class="layui-form-label" style="width: 110px">实际花费差旅费</label>
            </div>
            <div class="layui-form-item" style="margin-left: 20px; margin-right: 20px; margin-top: -20px">
                <table class="layui-hide" id="currentTableId1" name="currentTableId1" lay-filter="currentTableFilter1"
                       style="padding-top: 0px;margin-top: 0px"></table>
            </div>

        </div>
        <div class="layui-row" style="margin-bottom: -20px">
            <div class="layui-col-md6">
                <div class="layui-form-label" style="width: 70px">报销凭证</div>
            </div>
        </div>
        <div class="layui-form-item" style="margin-left: 20px; margin-right: 20px; margin-top: -20px">
            <input type="hidden" id="bxpz" name="bxpz" class="layui-input" th:value="${reimbursement.bxpz}">
            <table class="layui-hide" id="currentTableId2" name="currentTableId2" lay-filter="currentTableFilter2"
                   style="padding-top: 0px;margin-top: 0px"></table>
        </div>

        <!-- 右侧悬浮按钮 -->
        <div class="right-bottom-btn">
            <button type="button" class="layui-btn" lay-on="test-tips-photos" id="ckwj">
                <i class="layui-icon layui-icon-up">批量查看报销凭证</i>
            </button>
            <button type="button" class="layui-btn" lay-filter="viewFysqBtn">
                <i class="layui-icon layui-icon-ok"></i>查看费用申请
            </button>
            <button type="button" class="layui-btn" lay-filter="cancleBtn">
                <i class="layui-icon layui-icon-close"></i>关闭
            </button>
        </div>
    </div>
</form>

<script th:src="@{/lib/jquery-3.4.1/jquery-3.4.1.min.js}" charset="utf-8"></script>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/lib/coco-message/coco-message.js}" charset="utf-8"></script>
<script th:src="@{/lib/xm-select-v1.2.2/xm-select.js}" charset="utf-8"></script>
<script th:src="@{/js/lay-config.js}" charset="utf-8"></script>

<script type="text/javascript" th:inline="javascript">
    AjaxUtil.ctx = /*[[@{/}]]*/'';
    var travelExpense = [];//差旅费

    layui.use(['form', 'table', 'treeTable', 'layCascader', 'util'], function () {
        var table = layui.table,
            layer = layui.layer;
        var fysq = [[${reimbursement.fysq}]];
        var fylbmc = [[${reimbursement.fylbmc}]];
        var baozhangid = [[${reimbursement.id}]];
        // 用于存放表格数据
        var dataExpense = new Array();
        $.ajax({
            url: AjaxUtil.ctx + 'staActualexpenses/list/' + fysq,
            type: "post",
            async: false,
            dataType: "json",
            success: function (result) {
                dataExpense = result.data.rows;
            }
        });

        setTimeout(function() {
            // 在这里可以进行您的加载操作
            layer.msg('加载完成！', { icon: 1 });
            var fylbmc = document.getElementById('fylbmc').value;
            var clDiv = document.getElementById('cl'); // 获取 div
            console.log(fylbmc);
            /*            if ( fylbmc == '（1）外委研究支出费' || fylbmc == '（3）外协测试试验与加工费'){
                            hiddenDiv.style.display = 'block';
                        }else {
                            hiddenDiv.style.display = 'none';
                        }*/
            if (fylbmc == '（3）会议、差旅及国际合作交流费'){
                clDiv.style.display = 'block';
            }else {
                console.log('进来了')
                clDiv.style.display = 'none';
            }
            return  false;
            // 隐藏加载信息

        }, 100);
        //差旅费
        var currTable1 = table.render({
            elem: '#currentTableId1',
            data: dataExpense,
            cols: [
                [
                    {field: 'xh', title: '序号', width: '8%'},
                    {field: 'ccrxm', title: '出差人', width: '10%'},
                    {field: 'ccdd', title: '出差地点', width: '8%'},
                    {field: 'qsrq', title: '起始日期', width: '13%'},
                    {field: 'jsrq', title: '结束日期(含)', width: '14%'},
                    {field: 'ccts', title: '出差天数', width: '12%'},
                    {field: 'zj', title: '总计(元)', width: '12%'},
                    {field: 'rpj', title: '日平均(元)', width: '12%'},
                    {field: 'ccsy',title: '出差事由',width: '10%'}
                ]
            ],
            autoSort: false,
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'grid',
            initSort: {
                field: 'xh', //排序字段
                type: 'asc' //排序方式:desc 降序,asc 升序
            }
        });
        //双击（差旅费）
        table.on('rowDouble(currentTableFilter1)', function (obj) {
            var data = obj.data;
            travelExpense = {
                "xh": data.xh,
                "ccr": data.ccr,
                "ccrxm": data.ccrxm,
                "ccdd": data.ccdd,
                "ccts": data.ccts,
                "qsrq": data.qsrq,
                "jsrq": data.jsrq,
                "jtf": data.jtf,
                "zsf": data.zsf,
                "cb": data.cb,
                "zj": data.zj,
                "rpj": data.rpj
            };
            var index = layer.open({
                title: '浏览差旅费',
                type: 2,
                maxmin: true,
                shade: 0.2,
                area: [layerwidth + 'px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staTravelexpenses/forView',
                end: function () {
                    layer.close(index);
                }
            });
        });

        // 用于存放表格数据
        var dataBxpz = new Array();
        if ([[${reimbursement.bxpz}]] != null && [[${reimbursement.bxpz}]] != "") {
            dataBxpz = eval('(' + [[${reimbursement.bxpz}]] + ')');
        }
        //报销凭证
        var currTable2 = table.render({
            elem: '#currentTableId2',
            data: dataBxpz,
            cols: [
                [
                    {type: 'numbers', align: 'center'},
                    {field: 'wjm', title: '文件名', width: '30%'},
                    {field: 'scrq', title: '上传日期', width: '15%', align: 'center'},
                    {field: 'sm', title: '说明'}
                ]
            ],
            autoSort: false,
            limits: [10, 15, 20, 25, 50, 100],
            limit: Number.MAX_VALUE,
            page: true,
            skin: 'grid',
            done: function (res, curr, count) { // done为数据渲染完的回调
            }
        });
        //双击（报销凭证）
        table.on('rowDouble(currentTableFilter2)', function (obj) {
            /*window.open(obj.data.Url);*/

            var bzId = {
                "bzId": baozhangid
            }
            AjaxUtil.post({
                url: AjaxUtil.ctx + 'staReimbursement/viewFile',
                contentType: "application/json",
                data: JSON.stringify(bzId),
                success: function (res) {
                    console.log(res)
                    layer.tab({
                        area: ['100%', '100%'],
                        tab: res.data,
                        maxmin: true,
                        shadeClose: true,
                        success: function (index, layero) {//打开tab后的执行的内容
                            //你的代码
                            $(".layui-layer-title").attr("style", "width: 100%; height: 10%;background-color: #f0f0f0; overflow-y: scroll;  white-space: nowrap; border: 1px solid #ccc;");
                            $("div>span").attr("style", "width:10px;  display: inline-block;");
                        }
                    })
                },
                fail: function (res) {
                    layer.close(index);
                    Message.error(res.message, 1500);
                },
                error: function (error) {
                    layer.close(index);
                    Message.error("服务器异常！", 1000);
                }
            });
        });

        // 监听查看费用申请按钮
        $("button[lay-filter='viewFysqBtn']").click(function () {
            var index = parent.layer.open({
                title: '查看费用申请',
                type: 2,
                shade: 0.3,
                // maxmin: true,
                shadeClose: true,
                area: ['1030px', '700px'],
                content: AjaxUtil.ctx + 'staBudgetapproval/forApplyView/' + fysq + '?fylbmc=' + fylbmc,
                end: function () {
                    layer.close(index);
                }
            });
        });

        // 监听取消按钮
        $("button[lay-filter='cancleBtn']").click(function () {
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
        });

        $("#ckwj").click(function () {
            var bzId = {
                "bzId": baozhangid
            }
            AjaxUtil.post({
                url: AjaxUtil.ctx + 'staReimbursement/viewFile',
                contentType: "application/json",
                data: JSON.stringify(bzId),
                success: function (res) {
                    console.log(res)
                    layer.tab({
                        area: ['100%', '100%'],
                        tab: res.data,
                        maxmin: true,
                        shadeClose: true,
                        success: function (index, layero) {//打开tab后的执行的内容
                            //你的代码
                            $(".layui-layer-title").attr("style", "width: 100%; height: 10%;background-color: #f0f0f0; overflow-y: scroll;  white-space: nowrap; border: 1px solid #ccc;");
                            $("div>span").attr("style", "width:10px;  display: inline-block;");
                        }
                    })
                },
                fail: function (res) {
                    layer.close(index);
                    Message.error(res.message, 1500);
                },
                error: function (error) {
                    layer.close(index);
                    Message.error("服务器异常！", 1000);
                }
            });

        })
    });

    function setTravelExpense(expense) {
        travelExpense = expense;
    }

    function getTravelExpense() {
        return travelExpense;
    }
</script>
</body>
</html>