<!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>
    <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>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息(<b>收起-展开</b>)</legend>
            <div id="search-div" style="margin: 5px 10px -10px 0px">
                <form class="layui-form" action="" lay-filter="search-form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 70px;">项目名称</label>
                            <div class="layui-input-inline" style="width: 140px;">
                                <input type="text" name="xmmc" id="xmmc" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 70px;">ERP编号</label>
                            <div class="layui-input-inline" style="width: 140px;">
                                <input type="text" name="erpbh" id="erpbh" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 100px;">科研编号</label>
                            <div class="layui-input-inline" style="width: 140px;">
                                <input type="text" name="bh" id="bh" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 70px;">年份</label>
                            <div class="layui-input-inline" style="width: 140px;">
                                <select name="nf" id="nf" lay-filter="status" class="layui-select">
                                    <option value="0">全部</option>
                                    <!-- Assume 'yearList' is populated with options -->
                                    <option th:each="item: ${yearList}" th:text="${item}" th:value="${item}"></option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 70px;">审批状态</label>
                            <div class="layui-input-inline" style="width: 140px;">
                                <select name="spzt" lay-filter="status" class="layui-select">
                                    <option value="">全部</option>
                                    <!-- Assume 'approveList' is populated with options -->
                                    <option th:each="item: ${approveList}" th:text="${item.name}" th:value="${item.name}"></option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 70px;">报账名称</label>
                            <div class="layui-input-inline" style="width: 140px;">
                                <input type="text" name="mc" id="mc" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 70px;">申请人</label>
                            <div class="layui-input-inline" style="width: 140px;">
                                <input type="text" name="sqr" id="sqr" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline" >
                            <label class="layui-form-label" style="width: 70px;margin-left: 30px">是否备用金</label>
                            <div class="layui-input-inline" style="width: 140px">
                                <select name="sfbyj" id="sfbyj" lay-filter="status">
                                    <option value="">全部</option>
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button type="submit" class="layui-btn" lay-submit lay-filter="data-search-btn">
                                <i class="layui-icon">&#xe615;</i> 搜索
                            </button>
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-reset-btn">
                                <i class="layui-icon layui-icon-refresh"></i> 重置
                            </button>
                        </div>
                    </div>

                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">

                <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="edit">
                    <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="view">
                    <i class="layui-icon layui-icon-file" style="font-size: 10px;"></i>查看
                </button>
             <!--   <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete">
                    <i class="layui-icon layui-icon-delete" style="font-size: 10px;"></i>删除
                </button>-->
<!--                <button class="layui-btn layui-btn-sm data-add-btn" lay-event="tjApprove">-->
<!--                    <i class="layui-icon layui-icon-ok" 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 data-add-btn" lay-event="payRequest">-->
<!--                    <i class="layui-icon layui-icon-edit" style="font-size: 10px;"></i>付款申请-->
<!--                </button>-->
                <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="nullify">
                    <i class="layui-icon layui-icon-delete" style="font-size: 10px;"></i>作废
                </button>
                <button class="layui-btn layui-btn-sm" lay-event="exportExcel" style="background-color: black">
                    <i class="layui-icon layui-icon-export" style="font-size: 10px;"></i>导出列表
                </button>
            </div>
        </script>

        <script type="text/html" id="cz">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="">
                    <i class="layui-icon layui-icon-delete" 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>
    </div>
</div>
<script>
    // 当文档加载完成后执行以下操作
    document.addEventListener('DOMContentLoaded', function() {
        // 获取下拉框元素
        var selectElement = document.getElementById('nf');
        // 获取当前年份并转换为字符串
        var currentYear = new Date().getFullYear().toString();

        // 遍历下拉框选项
        for (var i = 0; i < selectElement.options.length; i++) {
            // 如果选项的值与当前年份相匹配，则将该选项设为被选中状态并结束循环
            if (selectElement.options[i].value === currentYear) {
                selectElement.options[i].selected = true;
                break;
            }
        }
    });
</script>

<script>
    // 获取所有需要去除空格的输入框
    const inputs = [
        document.getElementById('xmmc'),
        document.getElementById('erpbh'),
        document.getElementById('fysqbh'),
        document.getElementById('mc'),
        document.getElementById('bzr')
    ];
    // 为每个输入框添加事件监听
    inputs.forEach(input => {
        input.addEventListener('input', function() {
            this.value = this.value.replace(/\s+/g, ''); // 去除空格
        });
    });
</script>
<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">
    AjaxUtil.ctx = /*[[@{/}]]*/'';
    var updateflag = 0;
    var xmApproval = {};
    layui.use(['form', 'table', 'tableSelect', 'laydate'], function () {
        var form = layui.form
            table = layui.table;
        var userId = $("#userId").val();
        var year = document.getElementById('nf').value;
        var currTable = table.render({
            elem: '#currentTableId',
            url: AjaxUtil.ctx + 'staReimbursement/list/?nf='+year,
            method: 'post',
            toolbar: '#toolbarDemo',
            // defaultToolbar: ['filter', 'print'],
            cols: [
                [
                    {type: "radio", fixed: 'left',title: '😊'},
                    {type: 'numbers', fixed: 'left',title: '序号'},
                    {field: 'spzt', width: '10%',title: '审批状态',fixed: 'left'},
                    {field: 'xmmc', width: '20%', title: '项目名称', fixed: 'left'},
                    {field: 'bh', width: '10%',title: '科研编号'},
                    {field: 'erpbh', width: '10%',title: 'ERP编号'},
                    {field: 'sqje', width: '7%', title: '申请金额(元)',align: 'right',templet:function (row) {
                        if (row.sqje != null){
                            return row.sqje.toLocaleString(undefined,{maximumFractionDigits:2,minimumFractionDigits:2});
                        }
                        return '0.00';
                        }},
                    {field: 'bzje', width: '8%', title: '报账金额(元)',align: 'right',templet:function (row) {
                        if (row.bzje != null){
                            return row.bzje.toLocaleString(undefined,{maximumFractionDigits: 2,minimumFractionDigits: 2});
                        }
                            return '0.00';
                        }},
                    {field: 'bhsje', width: '8%', title: '不含税金额(元)',align: 'right',templet:function (row) {
                        if (row.bhsje != null){
                            return row.bhsje.toLocaleString(undefined,{maximumFractionDigits:2,minimumFractionDigits:2});
                        }
                        return  '0.00';
                        }},
                    {field: 'sf', width: '6%', title: '税费(元)',align:'right',templet:function (row) {
                        if (row.sf != null){
                            return row.sf.toLocaleString(undefined,{maximumFractionDigits:2,minimumFractionDigits:2});
                        }
                        return '0.00';

                        }},
                    {field: 'sqrxm', width: '7%', title: '申请人'},
                    {field: 'sfbyjs', width: '8%', title: '是否备用金', align: 'center', templet: function (d) {
                            if (1 == d.sfbyjs) {
                                return '<span class="layui-badge layui-bg-blue">是</span>';
                            } else {
                                return '<span class="layui-badge layui-bg-orange">否</span>';
                            }
                        }
                    },
                    {field: 'cjsj', width: '8%', title: '创建时间', align: 'center'},
                    {field: 'fysqmc', title: '费用申请',width: '25%'},
                    {field: 'nf',title: '年份',width: '5%'},
                    // {field: 'mc', width: '20%', title: '报账名称', fixed: 'left'},
                    /* {title: '操作',width: '7%',toolbar:'#cz',align: 'center',fixed: 'right'}*/
                ]
            ],
            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为数据渲染完的回调
                // 测试打印出后端返回的权限列表
                // let permissionSet = [[${permissionSet}]];
                // console.log(JSON.stringify(permissionSet));
            }
        });

        // 监听搜索操作
        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", {
                "erpbh": '',
                "xmmc": '',
                "bh": '',
                "nf": '0',
                "spzt": '',
                "cjr": '',
                "cjsj1":'',
                "cjsj2":'',
                "mc":'',
                "bzr":'',
                "sqr":'',
                "sfbyj":''
            });
            // 执行搜索重载
            currTable.reload({
                page: {
                    curr: 1
                },
                where: form.val("search-form")
            });
            return false;
        });

        // 监听工具栏事件
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event == 'edit') {
                var dataBudget = table.cache["currentTableId"];
                if(dataBudget.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("该报账已审批结束，不能修改！", 2000);
                } else if (data[0].spzt != null && data[0].spzt.indexOf("未提交") < 0) {
                        Message.warning("该报账审批中，不能修改！", 2000);
                } else {
                    var index = layer.open({
                        title: '编辑报账',
                        type: 2,
                        shade: 0.3,
                        maxmin: true,
                        shadeClose: true,
                        area: ['1250px', '750px'],
                        content: AjaxUtil.ctx + "staReimbursement/forUpdate/" +data[0].id,
                        end: function () {
                            if (updateflag == 1)
                                currTable.reload();
                            updateflag = 0;
                            layer.close(index);
                        }
                    });
                }
            }
            else if (obj.event == 'view') {
                var dataBudget = table.cache["currentTableId"];
                if(dataBudget.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 index = layer.open({
                        title: '查看报账',
                        type: 2,
                        shade: 0.3,
                        maxmin: true,
                        shadeClose: true,
                        area: ['1250px', '750px'],
                        content: AjaxUtil.ctx + "staReimbursement/forView/" +data[0].id,
                        end: function () {
                            layer.close(index);
                        }
                    });
                }
            }
            else if (obj.event === 'delete') {  // 监听删除操作
                var dataBudget = table.cache["currentTableId"];
                if(dataBudget.length == 0)
                    return;

                var checkStatus = table.checkStatus('currentTableId')
                    ,data = checkStatus.data;
                if (data == null || data.length === 0) {
                    Message.warning("请选择要删除的报账！", 1000);
                    return;
                }
                else {
                    for(let item of data) {
                        if(item.spzt != "未提交") {
                            if(item.spzt == "审批结束")
                                Message.warning("存在已审批结束的报账，不能直接删除！", 2000);
                            else if (data[0].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 + "staReimbursement/batchDelete",
                        contentType: "application/json",
                        data: JSON.stringify(data),
                        success: function (res) {
                            if (res.code === 0) {
                                Message.success(1000, res.message, function () {
                                    // 重载表格
                                    currTable.reload();
                                });
                            } else {
                                Message.error(res.message, 1000);
                            }
                        },
                        error: function (error) {
                        }
                    });
                });
            }
            else if (obj.event === 'tjApprove') {
                var dataBudget = table.cache["currentTableId"];
                if (dataBudget.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 {
                    xmApproval = {
                        "xmid": data[0].id,
                        "xm": data[0].mc,
                        "zt": data[0].spzt,
                        "bzje": data[0].bzje
                    };
                    if(data[0].spzt == null) {
                        xmApproval.zt = "未提交";
                        data[0].spzt = "未提交";
                    }

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

                    var index = layer.open({
                        title: '提交审批',
                        type: 2,
                        shade: 0.3,
                        maxmin: true,
                        shadeClose: true,
                        area: ['1015px', layerheight + 'px'],
                        content: content,
                        end: function () {
                            if (updateflag == 1)
                                currTable.reload();
                            updateflag = 0;
                            layer.close(index);
                        }
                    });
                }
            }
            else if (obj.event === 'spOption') {
                var dataBudget = table.cache["currentTableId"];
                if (dataBudget.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.indexOf("未提交") >= 0) {
                    Message.warning("该报账尚未提交审批！", 1500);
                } else if (data[0].spzt == "审批结束") {
                    Message.warning("该报账已审批结束！", 1500);
                } else if (data[0].spzt == "作废") {
                    Message.warning("该报账已作废！", 1500);
                } else {
                    // 判断当前人员是否是审核人
                    AjaxUtil.get({
                        url: AjaxUtil.ctx + "prjAnnualbudget/getshr?xmid="+data[0].id+'&spzt='+data[0].spzt,
                        contentType: "application/json",
                        success: function (res) {
                            if (res.code === -1) {
                                layer.msg(res.message,{icon:2});
                                return;
                            } else if (res.code === -2){
                                layer.msg(res.message,{icon:2});
                                return;
                            }else {
                                xmApproval = {
                                    "xmid": data[0].id,
                                    "xm": data[0].mc,
                                    "zt": data[0].spzt,
                                    "bzje": data[0].bzje
                                };
                                var index = layer.open({
                                    title: '审批意见',
                                    type: 2,
                                    shade: 0.3,
                                    maxmin: true,
                                    shadeClose: true,
                                    area: ['1020px', layerheight + 'px'],
                                    content: AjaxUtil.ctx + 'staReimbursement/forApproveUpdate/' + data[0].id + '/' + data[0].bzje + '?spzt=' + data[0].spzt,
                                    end: function () {
                                        if (updateflag == 1)
                                            currTable.reload();
                                        updateflag = 0;
                                        layer.close(index);
                                    }
                                });
                            }
                        },
                        error: function (error) {
                        }
                    });
                }
            }
            else if (obj.event === 'spList') {
                var dataBudget = table.cache["currentTableId"];
                if (dataBudget.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].mc
                    };
                    var index = layer.open({
                        title: '审批列表',
                        type: 2,
                        shade: 0.3,
                        maxmin: true,
                        shadeClose: true,
                        area: ['1300px', layerheight + 'px'],
                        content: AjaxUtil.ctx + 'staReimbursement/forApproveList',
                        end: function () {
                            layer.close(index);
                        }
                    });
                }
            }
            else if (obj.event === 'payRequest') {
                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 {
                    xmApproval = {
                        "fysq": data[0].fysq,
                        "fysqmc": data[0].fysqmc,
                        "rws": data[0].xmid,
                        "rwsmc": data[0].xmmc
                    };

                    var index = layer.open({
                        title: '新建付款申请',
                        type: 2,
                        shade: 0.3,
                        maxmin: true,
                        shadeClose: true,
                        area: ['950px', '750px'],
                        content: AjaxUtil.ctx + "staPayapproval/forAdd/" + data[0].xmid,
                        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) {
                    layer.msg("请选择要作废的报账！", {icon:2});
                } else if (data.length > 1) {
                    layer.msg("请选择一条记录进行操作！", {icon:2});
                } else if (data[0].spzt == "作废") {
                    layer.msg("该报账已作废！", {icon:2});
                } else if (userId != 42){
                    layer.msg("你无权限作废，请联系科技项目管理专责！",{icon:2});
                    return false;
                }else {
                    layer.confirm('该报账作废后与之相关的付款记录也会随之作废，请确认是否要作废该报账吗？', function (index) {
                        layer.close(index);
                        //更新审批状态
                        var project = {
                            "id": data[0].id,
                            "spzt": '作废'
                        }
                        AjaxUtil.post({
                            url: AjaxUtil.ctx + "staReimbursement/updateSpzt?Id="+data[0].fysq,
                            contentType: "application/json",
                            data: JSON.stringify(project),
                            success: function (res) {
                                if (res.code === 0) {
                                    Message.success(1000, res.message, function () {
                                        // 重载表格
                                        currTable.reload();
                                    });
                                } else {
                                    Message.error(res.message, 1000);
                                }
                            },
                            error: function (error) {
                            }
                        });
                    });
                }
                /*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 == "作废") {
                    Message.warning("该报账已作废！", 1500);
                } else {
                    layer.confirm('确定要作废该报账吗？', function (index) {
                        layer.close(index);

                        //更新审批状态
                        var project = {
                            "id": data[0].id,
                            "spzt": '作废'
                        }
                        AjaxUtil.post({
                            url: AjaxUtil.ctx + "staReimbursement/updateSpzt",
                            contentType: "application/json",
                            data: JSON.stringify(project),
                            success: function (res) {
                                if (res.code === 0) {
                                    Message.success(1000, res.message, function () {
                                        // 重载表格
                                        currTable.reload();
                                    });
                                } else {
                                    Message.error(res.message, 1000);
                                }
                            },
                            error: function (error) {
                            }
                        });
                    });
                }*/
            } else if (obj.event === 'exportExcel') {
                var projects = table.cache["currentTableId"];
                if (projects.length == 0)
                    return;

                var formData = form.val('search-form');
                console.log(formData);
                var formDataString = JSON.stringify(formData);

                let a = document.createElement('a');
                a.href = AjaxUtil.ctx + 'staReimbursement/exportExcel/'+formDataString;
                a.click();
                a.parentNode.removeChild(a);
            }

    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].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 + "staReimbursement/TJrevokeApprove1",
                        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) {
                        }
                    });
                });
            }
        }
    });

        //双击
        table.on('rowDouble(currentTableFilter)', function (obj) {
            var index = layer.open({
                title: '查看报账',
                type: 2,
                shade: 0.3,
                maxmin: true,
                shadeClose: true,
                area: ['1250px', '750px'],
                content: AjaxUtil.ctx + "staReimbursement/forView/" + obj.data.id,
                end: function () {
                    layer.close(index);
                }
            });
        });
    });
    function getXmApproval() {
        return xmApproval;
    }

    function setUpdateFlag() {
        updateflag = 1;
    }
</script>
</body>
</html>