<!DOCTYPE html>
<html lang="en" 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</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">

</head>
<body>
<h1> 你好 世界</h1>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container" style="display: flex;">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="view">
            <i class="layui-icon layui-icon-file" style="font-size: 10px;"></i>查看
        </button>
        <button class="layui-btn layui-btn-sm data-add-btn" lay-event="tjrevokeApprove">
            <i class="layui-icon layui-icon-edit" style="font-size: 10px;"></i>撤销审批
        </button>
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="spOption">
            <i class="layui-icon layui-icon-edit" style="font-size: 10px;"></i>审核
        </button>
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="spList">
            <i class="layui-icon layui-icon-list" style="font-size: 10px;"></i>审批列表
        </button>
        <button class="layui-btn layui-btn-sm" lay-event="export" style="background-color: black">
            <i class="layui-icon layui-icon-export" style="font-size: 10px;"></i>导出列表
        </button>
        <button class="layui-btn layui-btn-sm layui-btn-checked" lay-event="xmzy" id="zy" style="display: none">
            <i class="layui-icon layui-icon-edit" style="font-size: 10px;"></i>项目转移
        </button>
    </div>
</script>
<input type="hidden" id="userId" name="userId" class="layui-input" th:value="${userId}">
<table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

<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="@{/js/lay-config.js}" charset="utf-8"></script>
<script th:src="@{/lib/xm-select-v1.2.2/xm-select.js}" charset="utf-8"></script>
<script th:inline="javascript" type="text/javascript">
    var updateflag = 0;
    var fyApproval = {};

    layui.use(['form', 'table', 'tableSelect', 'laydate', 'layCascader'], function () {
        var form = layui.form,
            tableSelect = layui.tableSelect,
            laydate = layui.laydate,
            table = layui.table;
        layCascader = layui.layCascader;
        var userId = $("#userId").val();
        var cascader;
        var sqsj1 = '',
            sqsj2 = '';
        //申请时间
        laydate.render({
            elem: '#sqsj1',
            done: function (value, date, endDate) {
                sqsj1 = $("#sqsj1").val();
                sqsj2 = $("#sqsj2").val();
                if (sqsj1 != "" && sqsj2 != "") {
                    if (sqsj1 > sqsj2) {
                        Message.warning("起始时间不能晚于终止时间！", 1500);
                        $("#sqsj1").val("");
                    }
                }
            }
        });
        laydate.render({
            elem: '#sqsj2',
            done: function (value, date, endDate) {
                sqsj1 = $("#sqsj1").val();
                sqsj2 = $("#sqsj2").val();
                if (sqsj1 != "" && sqsj2 != "") {
                    if (sqsj1 > sqsj2) {
                        Message.warning("终止时间不能早于开始时间！", 1500);
                        $("#sqsj2").val("");
                    }
                }
            }
        });
        var index2 = layer.load(0, {shade: 0.1});
        AjaxUtil.get({
            url: AjaxUtil.ctx + 'userinfo/listDeptForSelect',
            success: function (res) {
                layer.close(index2);
                var datalist = [];
                // 添加“全部”选项
                datalist.push({
                    value: '', // 空值
                    label: '全部', // 显示文本
                    children: [] // 需要子项以保持一致性
                });

                for (let item of res.data) {
                    item.value = item.deptName;
                    item.label = item.deptName;
                    // 确保每个部门也有一个 children 属性
                    item.children = [];
                    datalist.push(item);
                }

                // 扁平数据转树
                var options = arrayToTree(datalist, "50");
                // var options = arrayToTree(datalist, "0");

                // 初始化cascader实例
                cascader = layCascader({
                    elem: '#ssbmmc',
                    clearable: true,
                    showAllLevels: false, // 配置仅显示最后一级
                    props: {
                        checkStrictly: true, // 配置选择任意一级选项
                    },
                    options: options
                });

                // 监听cascader变化
                cascader.changeEvent(function (value, node) {
                    // 主动关闭面板
                    cascader.close();
                    $("#deptId").val(value);
                });
            },
            error: function (error) {
                layer.close(index2);
                Message.error('获取部门信息失败！', 1000);
            }
        });

        //电科院负责人
        tableSelect.render({
            elem: '#dkyfzrxm',
            checkedKey: 'id',
            searchKey: 'xm',
            searchPlaceholder: '搜索姓名',
            table: {
                url: AjaxUtil.ctx + 'basePerson/rylist',
                cols: [
                    [
                        {type: "checkbox", fixed: 'left',title: '😊'},
                        {type: 'numbers', align: 'center',title: '序号'},
                        {field: 'xm', width: '15%', title: '姓名', align: 'left'},
                        {field: 'dwmc', title: '公司/单位', align: 'left'}
                    ]
                ]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                var NEWJSON1 = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.xm);
                    NEWJSON1.push(item.id);
                })
                elem.val(NEWJSON.join(","));
                $("#dkyfzr").val(NEWJSON1.join(","));
            }
        });
        var getYear = document.getElementById('nf').value;
        var currTable = table.render({
            elem: '#currentTableId',
            url: AjaxUtil.ctx + 'staBudgetapproval/list_allApply/?nf='+getYear,
            method: 'post',
            toolbar: '#toolbarDemo',
            // defaultToolbar: ['filter', 'print'],
            cols: [
                [
                    {type: "radio", title: '😊'},
                    {type: 'numbers',title: '序号'},
                    {field: 'xmmc', width: '15%', title: '项目名称'},
                    {field: 'erpbh', width: '9%', title: 'ERP编号'},
                    {field: 'sfbyj', width: '8%', title: '是否备用金', align: 'center', templet: function (d) {
                            if (1 == d.sfbyj) {
                                return '<span class="layui-badge layui-bg-blue">是</span>';
                            } else {
                                return '<span class="layui-badge layui-bg-orange">否</span>';
                            }
                        }
                    },
                    {field: 'sqje', width: '7%', title: '申请金额(元)'},
                    {field: 'bzje', width: '7%', title: '报账金额(元)'},
                    {field: 'bhsje', width: '7%', title: '不含税金额(元)'},
                    {field: 'fylbmc', width: '15%', title: '费用类别'},
                    {field: 'xmlxmc', width: '10%', title: '项目类型'},
                    {field: 'spzt', width: '9%', title: '审批状态'},
                    {field: 'sqrxm', width: '5%', title: '申请人'},
                    {field: 'bh', width: '8%', title: '科研费号'},
                    {field: 'dkyfzrxm', width: '8%', title: '电科院负责人'},
                    {field: 'ssbmmc', width: '8%', title: '所属部门'},
                    {field: 'nf', width: '4%', title: '年份'},
                    {field: 'sqsj', width: '8%', title: '申请时间', align: 'center'},
                    {field: 'sqmc', width: '25%', title: '申请名称'}
                ]
            ],
            autoSort: false,
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'grid',
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.rows //解析数据列表
                };
            },
            done: function (res, curr, count) { // done为数据渲染完的回调

                if (res.data && Array.isArray(res.data)) {
                    for (let i = 0; i < res.data.length; i++) {
                        console.log(res.data[i]);
                        if (res.data[i].sfth==1){
                            const Index = i ;
                            $(`.layui-table tr[data-index="${Index}"]`).css('background-color', '#ADD8E6');
                        }
                    }
                }
                console.log(userId);
                if(userId == 1 || userId == 42){/*
                    $('#zy').css('display', 'block');*/
                }
            }
        });
        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            // 执行搜索重载
            currTable.reload({
                page: {
                    curr: 1 // 页码从1开始
                },
                where: form.val("search-form")
            });
            return false;
        });

        // 监听重置操作
        form.on('submit(data-reset-btn)', function (data) {
            form.val("search-form", {
                "bh": '',
                "erpbh": '',
                "xmlx": '',
                "sfbyj": '',
                "xmmc": '',
                "ssbmmc": '',
                "nf": '0',
                "spzt": '',
                "sfbz": '',
                "dkyfzr": '',
                "sqsj1": '',
                "sqsj2": ''
            });
            cascader.reload();
            // 执行搜索重载
            currTable.reload({
                page: {
                    curr: 1
                },
                where: form.val("search-form")
            });
            return false;
        });


        // 监听工具栏事件
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                layer.open({
                    title: '新建费用申请',
                    type: 2,
                    shade: 0.3,
                    maxmin: true,
                    area: ['1020px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'staBudgetapproval/forApplyAdd',
                    end: function (index) {
                        // 重载表格
                        if (updateflag == 1)
                            currTable.reload();
                        updateflag = 0;
                    }
                });
            } else if (obj.event == 'edit') {
                var dataApproval = table.cache["currentTableId"];
                if (dataApproval.length == 0)
                    return;

                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                if (data == null || data.length === 0) {
                    Message.warning("请选择要编辑的费用申请！", 1500);
                } else if (data.length > 1) {
                    Message.warning("请选择一条记录进行编辑！", 1500);
                } else if (data[0].spzt == "作废") {
                    Message.warning("该费用申请已作废！", 1500);
                } else if (data[0].spzt == "审批结束") {
                    Message.warning("该费用申请已审批结束，不能修改！", 1500);
                } else if (data[0].spzt != null && data[0].spzt.indexOf("未提交") < 0) {
                    Message.warning("该费用申请审批中，不能修改！", 1500);
                    ;
                } else if (data[0].sqr != userId) {
                    Message.error("您不是该费用的申请人，不能修改！", 1500);
                } else {
                    layer.open({
                        title: '编辑费用申请',
                        type: 2,
                        shade: 0.3,
                        maxmin: true,
                        shadeClose: true,
                        area: ['1020px', layerheight + 'px'],
                        content: AjaxUtil.ctx + 'staBudgetapproval/forApplyUpdate/' + data[0].id+'?fylbmc='+data[0].fylbmc,
                        end: function (index) {
                            if (updateflag == 1)
                                currTable.reload();
                            updateflag = 0;
                        }
                    });
                    // layer.full(index);
                }
            } else if (obj.event == 'view') {
                var dataApproval = table.cache["currentTableId"];
                if (dataApproval.length == 0)
                    return;

                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                if (data == null || data.length === 0) {
                    Message.warning("请选择要查看的费用申请！", 1500);
                } else if (data.length > 1) {
                    Message.warning("请选择一条记录进行查看！", 1500);
                } else {
                    var title = '浏览费用申请';
                    var width = '1020px';
                    var content = AjaxUtil.ctx + 'staBudgetapproval/forApplyView/' + data[0].id+'?fylbmc='+data[0].fylbmc;
                    if (data[0].sfbyj == 1) {
                        title = '浏览备用金申请';
                        if (data[0].fylbmc == null) {
                            width = layerwidth + 'px';
                            content = AjaxUtil.ctx + 'staBudgetapproval/forImprestView/' + data[0].id;
                        }
                    }
                    layer.open({
                        title: title,
                        type: 2,
                        shade: 0.3,
                        maxmin: true,
                        shadeClose: true,
                        area: [width, layerheight + 'px'],
                        content: content,
                        end: function (index) {
                            layer.close(index);
                        }
                    });
                    // layer.full(index);
                }
            } else if (obj.event === 'delete') {  // 监听删除操作
                var dataApproval = table.cache["currentTableId"];
                if (dataApproval.length == 0)
                    return;

                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                if (data == null || data.length === 0) {
                    Message.warning("请选择要删除的费用申请！", 1500);
                    return;
                } else {
                    for (let item of data) {
                        if (item.sqr != userId) {
                            Message.error("存在您不是申请人的费用，不能直接删除！", 2000);
                            return;
                        }
                        if (item.spzt != "未提交") {
                            if (item.spzt == "审批结束")
                                Message.warning("存在已审批结束的费用申请，不能直接删除！", 2000);
                            else if (data[0].spzt != null)
                                Message.warning("存在审批中的费用申请，不能直接删除！", 2000);
                            return;
                        }
                    }
                }
                layer.confirm('确定批量删除费用申请吗？', function (index) {
                    layer.close(index);
                    AjaxUtil.post({
                        url: AjaxUtil.ctx + "staBudgetapproval/batchDelete",
                        contentType: "application/json",
                        data: JSON.stringify(data),
                        success: function (res) {
                            if (res.code === 0) {
                                Message.success(1500, res.message, function () {
                                    // 重载表格
                                    currTable.reload();
                                });
                            } else {
                                Message.error(res.message, 1000);
                            }
                        },
                        error: function (error) {
                        }
                    });
                });
            } else if (obj.event === 'tjApprove') {
                var projects = table.cache["currentTableId"];
                if (projects.length == 0)
                    return;

                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                if (data == null || data.length === 0) {
                    Message.warning("请选择要提交审批的费用申请！", 2000);
                } else if (data.length > 1) {
                    Message.warning("请选择一条记录进行提交！", 1500);
                } else if (data[0].spzt == "审批结束") {
                    Message.warning("该费用申请已审批结束！", 1500);
                } else if (data[0].spzt == "作废") {
                    Message.warning("该费用申请已作废！", 1500);
                } else if (data[0].spzt != null && data[0].spzt.indexOf("未提交") < 0) {
                    Message.warning("该费用申请正在审批中……", 1500);
                } else if (data[0].sqr != userId) {
                    Message.error("您不是该费用的申请人！", 1500);
                } else {
                    xmApproval = {
                        "xmid": data[0].id,
                        "xm": data[0].sqmc,
                        "zt": data[0].spzt,
                        "sqje": data[0].sqje
                    };
                    if (data[0].spzt == null) {
                        xmApproval.zt = "未提交";
                        data[0].spzt = "未提交";
                    }

                    var content = AjaxUtil.ctx + 'staBudgetapproval/forApproveAdd';
                    if (data[0].spzt != "未提交")
                        content = AjaxUtil.ctx + 'staBudgetapproval/forApproveUpdate/' + data[0].id + '/' + data[0].sqje + '?spzt=' + data[0].spzt;

                    var index = layer.open({
                        title: '提交审批',
                        type: 2,
                        shade: 0.3,
                        maxmin: true,
                        shadeClose: true,
                        area: ['1025px', layerheight + 'px'],
                        content: content,
                        end: function () {
                            if (updateflag == 1)
                                currTable.reload();
                            updateflag = 0;
                            layer.close(index);
                        }
                    });
                }
            } else if (obj.event === 'spOption') {
                var projects = table.cache["currentTableId"];
                if (projects.length == 0)
                    return;
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                if (data == null || data.length === 0) {
                    Message.warning("请选择要审批的费用申请！", 2000);
                } else if (data.length > 1) {
                    Message.warning("请选择一条记录进行审批！", 1500);
                } else if (data[0].spzt == null || data[0].spzt.indexOf("未提交") >= 0) {
                    Message.warning("该费用申请尚未提交审批！", 1500);
                } else if (data[0].spzt == "审批结束") {
                    Message.warning("该费用申请已审批结束！", 2000);
                } else if (data[0].spzt == "作废") {
                    Message.warning("该费用申请已作废！", 1500);
                } else {
                    xmApproval = {
                        "xmid": data[0].id,
                        "xm": data[0].sqmc,
                        "zt": data[0].spzt,
                        "sqje": data[0].sqje
                    };

                    var content = AjaxUtil.ctx + 'staBudgetapproval/forApproveAdd';
                    if (data[0].spzt != "未提交")
                        content = AjaxUtil.ctx + 'staBudgetapproval/forApproveUpdate/' + data[0].id + '/' + data[0].sqje + '?spzt=' + data[0].spzt;

                    layer.open({
                        title: '审批意见',
                        type: 2,
                        shade: 0.3,
                        maxmin: true,
                        shadeClose: true,
                        area: ['1025px', layerheight + 'px'],
                        content: content,
                        end: function (index) {
                            if (updateflag == 1)
                                currTable.reload();
                            updateflag = 0;
                        }
                    });
                }
            } else if (obj.event === 'spList') {
                var projects = table.cache["currentTableId"];
                if (projects.length == 0)
                    return;

                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                if (data == null || data.length === 0) {
                    Message.warning("请选择要查看审批列表的费用申请！", 1500);
                } else if (data.length > 1) {
                    Message.warning("请选择一条记录进行查看！", 1500);
                } else if (data[0].spzt == null || data[0].spzt == "未提交") {
                    Message.warning("该备费用申请尚未提交审批！", 1500);
                } else {
                    xmApproval = {
                        "xmid": data[0].id,
                        "xm": data[0].sqmc,
                        "zt": data[0].spzt,
                        "sqje": data[0].sqje
                    };

                    var content = AjaxUtil.ctx + 'staBudgetapproval/forApproveList';
                    if (data[0].sfbyj == 1)
                        content = AjaxUtil.ctx + 'staBudgetapproval/forApproveList1';

                    var index = layer.open({
                        title: '审批列表',
                        type: 2,
                        shade: 0.3,
                        maxmin: true,
                        shadeClose: true,
                        area: ['1300px', layerheight + 'px'],
                        content: content,
                        end: function () {
                            layer.close(index);
                        }
                    });
                }
            } else if (obj.event === 'reimburse') {
                var projects = table.cache["currentTableId"];
                if (projects.length == 0)
                    return;

                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                if (data == null || data.length === 0) {
                    Message.warning("请选择要报账的费用申请！", 1500);
                } else if (data.length > 1) {
                    Message.warning("请选择一条记录进行报账！", 1500);
                } else if (data[0].spzt == "作废") {
                    Message.warning("该费用申请已作废！", 1500);
                } else if (data[0].spzt.indexOf("未提交") >= 0) {
                    Message.warning("该费用申请尚未提交审批！", 1500);
                } else if (data[0].spzt != "审批结束") {
                    Message.warning("该费用申请正在审批中……", 1500);
                } else if (data[0].sfbz == 1) {
                    Message.warning("该费用申请已报账", 1500);
                } else {
                    var index = layer.open({
                        title: '新建报账',
                        type: 2,
                        shade: 0.3,
                        maxmin: true,
                        shadeClose: true,
                        area: ['970px', '750px'],
                        content: AjaxUtil.ctx + "staReimbursement/forAdd/" + data[0].id,
                        end: function () {
                            if (updateflag == 1)
                                currTable.reload();
                            updateflag = 0;
                            layer.close(index);
                        }
                    });
                }
            } else if (obj.event === 'nullify') {  // 监听作废操作
                var projects = table.cache["currentTableId"];
                if (projects.length == 0)
                    return;

                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                if (data == null || data.length === 0)
                    Message.warning("请选择要作废的费用申请！", 1000);
                else {
                    layer.confirm('确定批量作废费用申请吗？', function (index) {
                        layer.close(index);
                        AjaxUtil.post({
                            url: AjaxUtil.ctx + "staBudgetapproval/batchNullify",
                            contentType: "application/json",
                            data: JSON.stringify(data),
                            success: function (res) {
                                if (res.code === 0) {
                                    Message.success(1500, res.message, function () {
                                        // 重载表格
                                        currTable.reload();
                                    });
                                } else {
                                    Message.error(res.message, 1000);
                                }
                            },
                            error: function (error) {
                            }
                        });
                    });
                }
            } else if (obj.event === 'tjrevokeApprove') {
                var projects = table.cache["currentTableId"];
                if (projects.length == 0)
                    return;
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                if (data == null || data.length === 0) {
                    Message.warning("请选择要撤销的费用申请！", 1500);
                } else if (data.length > 1) {
                    Message.warning("请选择一条记录进行撤销！", 1500);
                } else if (data[0].spzt == "审批结束") {
                    Message.warning("该费用申请已审批结束！", 1500);
                }else if(data[0].spzt == "未提交"|| data[0].spzt == "未提交(返回)"){
                    Message.warning("该费用申请还未提交审批！", 1500);
                }
                    // else if (data[0].cjr != userId) {
                // Message.error("您不是该任务书的创建人！", 1500);}
                else {
                    xmApproval = {
                        "xmid": data[0].id,
                        "xm": data[0].zwmc,
                        "zt": "未提交"
                    };
                    if (data[0].spzt == null) {
                        xmApproval.zt = "未提交";
                        data[0].spzt = "未提交";
                    }
                    var project = {
                        "id": xmApproval.xmid,
                        "spzt": data[0].spzt
                    }
                    layer.confirm('确定撤销费用申请吗？', function (index) {
                        layer.close(index);
                        AjaxUtil.post({
                            url: AjaxUtil.ctx + "staBudgetapproval/TJrevokeApprove",
                            contentType: "application/json",
                            data: JSON.stringify(project),
                            success: function (res) {
                                if (res.code === 0) {
                                    Message.success(1500, res.message, function () {
                                        // 重载表格
                                        currTable.reload();
                                    });
                                } else {
                                    Message.error(res.message, 1000);
                                }
                            },
                            error: function (error) {
                            }
                        });
                    });
                }
            }else if (obj.event === 'export'){

                var formData = form.val('search-form');
                // 获取form 表单代码
                console.log(formData);
                var formDataString = JSON.stringify(formData);
                AjaxUtil.post({
                    url:AjaxUtil.ctx +'staBudgetapproval/getAll/'+formDataString,
                    contentType: "application/json",
                    timeout: 15000, //大批量导出时会出现超时问题
                    success: function(res){
                        console.log(res);
                        table.exportFile('currentTableId',res.data,'xlsx');
                    },
                    error:function (error) {
                        Message.error(error,2000)

                    }
                });


            }else if (obj.event === 'xmzy'){
                var project = table.cache['currentTableId'];//  绑定表格元素 cache 表示缓存的意思
                // 判断缓存是否为空
                if(project.length == 0){
                    return;
                }
                // 获取table 中 缓存的数据
                var checkStatus =  table.checkStatus('currentTableId')
                    ,data = checkStatus.data;
                if (data == null || data.length === 0){
                    layer.msg('请选择要转移的项目',{icon: 3});
                }else if (data.length > 1){
                    layer.msg('请选择一条项目进项转移',{icon:3});
                }else if (data[0].spzt != '审批结束'){
                    layer.msg('"'+data[0].sqmc+'"未审批结束，不能转移',{icon:3});
                }else {
                    layer.open({
                        title: '项目转移',
                        type: 2,
                        shade: 0.3,
                        maxmin: true,
                        shadeClose: true,
                        area: ['1090px', layerheight + 'px'],
                        content: AjaxUtil.ctx + 'staBudgetapproval/updateSsbm/' + data[0].id,
                        success: function (layero, index) {
                        },
                        end: function (index) {
                            // 刷新表格
                            if (updateflag == 1)
                                currTable.reload();
                            updateflag = 0;
                        }
                    });
                }
            }
        });

        //双击
        table.on('rowDouble(currentTableFilter)', function (obj) {
            var data = obj.data;
            var title = '浏览费用申请';
            var width = '1020px';
            var content = AjaxUtil.ctx + 'staBudgetapproval/forApplyView/' + data.id;
            if (data.sfbyj == 1) {
                title = '浏览备用金申请';
                if (data.fylbmc == null) {
                    width = layerwidth + 'px';
                    content = AjaxUtil.ctx + 'staBudgetapproval/forImprestView/' + data.id;
                }
            }
            layer.open({
                title: title,
                type: 2,
                shade: 0.3,
                maxmin: true,
                shadeClose: true,
                area: [width, layerheight + 'px'],
                content: content,
                end: function (index) {
                    layer.close(index);
                }
            });
        });
    });

    function setUpdateFlag() {
        updateflag = 1;
    }

    function getXmApproval() {
        return xmApproval;
    }

    function arrayToTree(data, firstPid) {
        const result = [];
        getChildren(data, result, firstPid)
        return result;
    }

    function getChildren(data, result, parentId) {
        for (const item of data) {
            if (item.parentId === parentId) {
                const newItem = {...item, children: []};
                result.push(newItem);
                getChildren(data, newItem.children, item.deptId);
            }
        }
    }
</script>
</body>
</html>