<!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-tab layui-tab-card">
        <ul class="layui-tab-title">
            <li class="layui-this">常规</li>
            <li>其它信息</li>
        </ul>
        <div class="layui-tab-content">
            <!--常规开始-->
            <div class="layui-tab-item layui-show" style="min-height: 550px">
                <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">
                            <label class="layui-form-label" style="width: 75px">申请名称</label>
                            <div class="layui-input-inline" style="width: 855px">
                                <input type="hidden" id="id" name="id" th:value="${budgetapproval.id}"
                                       class="layui-input">
                                <input type="text" id="sqmc" name="sqmc" th:value="${budgetapproval.sqmc}"
                                       class="layui-input" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label required" style="width: 75px">项目名称</label>
                            <div class="layui-input-inline" style="width: 855px">
                                <input type="hidden" id="xmid" name="xmid" class="layui-input">
                                <input type="hidden" id="xmmc" name="xmmc" class="layui-input">
                                <select name="ysrws" id="ysrws" lay-filter="ysrws">
                                    <option value="">[无]</option>
                                    <option value="-1">[浏览]</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label" style="width: 75px">编号</label>
                            <div class="layui-input-inline" style="width: 380px">
                                <input type="text" id="bh" name="bh" class="layui-input" th:value="${budgetapproval.bh}"
                                       readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label" style="width: 75px">年份</label>
                            <div class="layui-input-inline" style="width: 380px">
                                <input type="number" id="nf" name="nf" class="layui-input"
                                       th:value="${budgetapproval.nf}" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline"
                             style="width: 453px; margin-left: 10px; position: absolute; z-index: 2">
                            <table class="layui-hide" id="currentTableId_tj" name="currentTableId_tj"
                                   lay-filter="currentTableFilter_tj" style="padding-top: 0px;margin-top: 0px"></table>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label" style="width: 80px; margin-left: -5px">申请金额(元)</label>
                            <div class="layui-input-inline" style="width: 380px">
                                <input type="number" id="sqje" name="sqje" class="layui-input"
                                       th:value="${budgetapproval.sqje}" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline">
                            <label class="layui-form-label required" style="width: 75px">费用类别</label>
                            <div class="layui-input-inline" style="width: 380px">
                                <input type="hidden" id="fjmc" name="fjmc" class="layui-input">
                                <input type="hidden" id="fylb" name="fylb" class="layui-input">
                                <input type="text" id="fylbmc" name="fylbmc" lay-verify="required"
                                       lay-reqtext="费用类别不能为空" class="layui-input" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="display: none" id="fyxxDiv">
                            <label class="layui-form-label" style="width: 75px">费用小项</label>
                            <input type="hidden" id="bz" name="bz" class="layui-input">
                            <div class="layui-input-inline" style="width: 380px; display: none" id="zlysDiv">
                                <select name="bz1" id="bz1" lay-filter="bz1">
                                    <option value="资料费">资料费</option>
                                    <option value="印刷费">印刷费</option>
                                    <option value="知识产权费">知识产权费</option>
                                </select>
                            </div>
                            <div class="layui-input-inline" style="width: 380px; display: none" id="hyclDiv">
                                <select name="bz2" id="bz2" lay-filter="bz2">
                                    <option value="会议费">会议费</option>
                                    <option value="差旅费">差旅费</option>
                                    <option value="国际合作交流费">国际合作交流费</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%; display: none" id="clfDiv">
                            <label class="layui-form-label" style="width: 75px">差旅费</label>
                            <div class="layuimini-container" style="width: 853px; margin-left: 105px">
                                <div class="layui-btn-group" style="margin-bottom: -8px">
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subAdd"><i class="layui-icon"></i>新建
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subEdit"><i class="layui-icon"></i>编辑
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subView"><i class="layui-icon">&#xe63c;</i>查看
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subDelete"><i class="layui-icon"></i>删除
                                    </button>
                                </div>
                                <table class="layui-hide" id="currentTableId1" name="currentTableId1"
                                       lay-filter="currentTableFilter1"
                                       style="padding-top: 0px;margin-top: 0px"></table>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%; display: none" id="lsryDiv">
                            <label class="layui-form-label" style="width: 75px">临时人员</label>
                            <div class="layuimini-container" style="width: 853px; margin-left: 105px">
                                <div class="layui-btn-group" style="margin-bottom: -8px">
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subAdd3"><i class="layui-icon"></i>新建
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subEdit3"><i class="layui-icon"></i>编辑
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subView3"><i class="layui-icon">&#xe63c;</i>查看
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subDelete3"><i class="layui-icon"></i>删除
                                    </button>
                                </div>
                                <table class="layui-hide" id="currentTableId3" name="currentTableId3"
                                       lay-filter="currentTableFilter3"
                                       style="padding-top: 0px;margin-top: 0px"></table>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%; display: none" id="sbsyfDiv">
                            <label class="layui-form-label" style="width: 75px">仪器设备<br>使用费</label>
                            <div class="layuimini-container" style="width: 853px; margin-left: 105px">
                                <div class="layui-btn-group" style="margin-bottom: -8px">
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subAdd_Dev"><i class="layui-icon"></i>新建
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subEdit_Dev"><i class="layui-icon"></i>编辑
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subView_Dev"><i class="layui-icon">&#xe63c;</i>查看
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subDelete_Dev"><i class="layui-icon"></i>删除
                                    </button>
                                </div>
                                <table class="layui-hide" id="currentTableId_Dev" name="currentTableId_Dev"
                                       lay-filter="currentTableFilter_Dev"
                                       style="padding-top: 0px;margin-top: 0px"></table>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%; display: none" id="rjsyfDiv">
                            <label class="layui-form-label" style="width: 75px">软件使用费</label>
                            <div class="layuimini-container" style="width: 853px; margin-left: 105px">
                                <div class="layui-btn-group" style="margin-bottom: -8px">
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subAdd_Sw"><i class="layui-icon"></i>新建
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subEdit_Sw"><i class="layui-icon"></i>编辑
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subView_Sw"><i class="layui-icon">&#xe63c;</i>查看
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subDelete_Sw"><i class="layui-icon"></i>删除
                                    </button>
                                </div>
                                <table class="layui-hide" id="currentTableId_Sw" name="currentTableId_Sw"
                                       lay-filter="currentTableFilter_Sw"
                                       style="padding-top: 0px;margin-top: 0px"></table>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%; display: none" id="clfyDiv">
                            <label class="layui-form-label" style="width: 75px">材料费</label>
                            <div class="layuimini-container" style="width: 853px; margin-left: 105px">
                                <div class="layui-btn-group" style="margin-bottom: -8px">
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subAdd_Clf"><i class="layui-icon"></i>新建
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subEdit_Clf"><i class="layui-icon"></i>编辑
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subView_Clf"><i class="layui-icon">&#xe63c;</i>查看
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subDelete_Clf"><i class="layui-icon"></i>删除
                                    </button>
                                </div>
                                <table class="layui-hide" id="currentTableId_Clf" name="currentTableId_Clf"
                                       lay-filter="currentTableFilter_Clf"
                                       style="padding-top: 0px;margin-top: 0px"></table>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%; display: none" id="wwyjzcDiv">
                            <label class="layui-form-label" style="width: 75px">外委研究<br>支出费</label>
                            <div class="layuimini-container" style="width: 853px; margin-left: 105px">
                                <div class="layui-btn-group" style="margin-bottom: -8px">
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subAdd_Ww"><i class="layui-icon"></i>新建
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subEdit_Ww"><i class="layui-icon"></i>编辑
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subView_Ww"><i class="layui-icon">&#xe63c;</i>查看
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subDelete_Ww"><i class="layui-icon"></i>删除
                                    </button>
                                </div>
                                <table class="layui-hide" id="currentTableId_Ww" name="currentTableId_Ww"
                                       lay-filter="currentTableFilter_Ww"
                                       style="padding-top: 0px;margin-top: 0px"></table>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%; display: none" id="syyjgfDiv">
                            <label class="layui-form-label" style="width: 75px">外协测试试<br>验与加工费</label>
                            <div class="layuimini-container" style="width: 853px; margin-left: 105px">
                                <div class="layui-btn-group" style="margin-bottom: -8px">
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subAdd_Wx"><i class="layui-icon"></i>新建
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subEdit_Wx"><i class="layui-icon"></i>编辑
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subView_Wx"><i class="layui-icon">&#xe63c;</i>查看
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subDelete_Wx"><i class="layui-icon"></i>删除
                                    </button>
                                </div>
                                <table class="layui-hide" id="currentTableId_Wx" name="currentTableId_Wx"
                                       lay-filter="currentTableFilter_Wx"
                                       style="padding-top: 0px;margin-top: 0px"></table>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 75px">附件</label>
                            <div class="layuimini-container" style="width: 855px; margin-left: 103px">
                                <input type="hidden" id="fj" name="fj" class="layui-input"
                                       th:value="${budgetapproval.fj}">
                                <div class="layui-btn-group" style="margin-bottom: -8px">
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm upload"
                                            lay-filter="upLoad" lay-data="{fileType:'budget'}"><i
                                            class="layui-icon"></i>上传
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="deleteFile"><i class="layui-icon"></i>删除
                                    </button>
                                </div>
                                <table class="layui-hide" id="currentTableId2" name="currentTableId2"
                                       lay-filter="currentTableFilter1"
                                       style="padding-top: 0px;margin-top: 0px"></table>
                            </div>
                        </div>

                        <!-- 右侧悬浮按钮 -->
                        <div class="right-bottom-btn" id="btnContainer">
                            <button type="button" class="layui-btn" lay-filter="viewRwsBtn">
                                <i class="layui-icon layui-icon-file"></i>查看任务书
                            </button>
                            <button type="button" class="layui-btn" lay-filter="viewNdysBtn">
                                <i class="layui-icon layui-icon-file-b"></i>查看年度预算
                            </button>
                            <button type="button" class="layui-btn" lay-submit lay-filter="saveBtn">
                                <i class="layui-icon layui-icon-ok"></i>保存
                            </button>
                            <button class="layui-btn" lay-filter="cancleBtn">
                                <i class="layui-icon layui-icon-close"></i>取消
                            </button>
                        </div>
                    </div>
                </form>
            </div>
            <!--常规结束-->
            <!--其它信息开始-->
            <div class="layui-tab-item" style="height: 550px">
                <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: 85px">ERP编号</label>
                            <div class="layui-input-inline" style="width: 845px">
                                <input type="text" id="erpbh" name="erpbh" class="layui-input" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 85px">项目类型</label>
                            <div class="layui-input-inline" style="width: 845px">
                                <input type="hidden" id="xmlx" name="xmlx" class="layui-input">
                                <input type="text" id="xmlxmc" name="xmlxmc" class="layui-input" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 85px">项目负责人</label>
                            <div class="layui-input-inline" style="width: 845px">
                                <input type="hidden" id="xmfzr" name="xmfzr" class="layui-input">
                                <input type="text" id="xmfzrxm" name="xmfzrxm" class="layui-input" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 85px">电科院负责人</label>
                            <div class="layui-input-inline" style="width: 845px">
                                <input type="hidden" id="dkyfzr" name="dkyfzr" class="layui-input">
                                <input type="text" id="dkyfzrxm" name="dkyfzrxm" class="layui-input" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 85px">所属部门</label>
                            <div class="layui-input-inline" style="width: 845px">
                                <input type="hidden" id="ssbm" name="ssbm" class="layui-input">
                                <input type="text" id="ssbmmc" name="ssbmmc" class="layui-input" readonly>
                            </div>
                        </div>

                        <!-- 右侧悬浮按钮 -->
                        <div class="right-bottom-btn">
                            <button class="layui-btn" lay-filter="cancleBtn">
                                <i class="layui-icon layui-icon-close"></i>关闭
                            </button>
                        </div>
                    </div>
                </form>
            </div>
            <!--其它信息结束-->
        </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 = [];//差旅费
    var updateflag = 0;//更新标志
    var tempMember = [];//临时人员
    var devExpense = [];//仪器、设备使用费
    var softExpense = [];//软件使用费
    var materialCost = [];//材料费
    var outExpense = [];//外委研究支出
    var outTesting = [];//外协测试试验与加工费

    layui.use(['form', 'table', 'treeTable', 'layCascader', 'tableSelect', 'upload', 'element'], function () {
        var form = layui.form,
            table = layui.table,
            layer = layui.layer,
            tableSelect = layui.tableSelect,
            upload = layui.upload,
            element = layui.element;

        var ysId = -1;
        var fyId = $("#id").val();
        var xmId = -1;

        var xmFyInfo = [[#{xmFyInfo}]];
        // 用于存放表格数据
        var dataTj = new Array();

        function initTjInfo() {
            dataTj = [
                {
                    "km": "此科目年度预算",
                    "ysje": '',
                    "ysqje": '',
                    "ybzje": ''
                },
                {
                    "km": "项目年度经费",
                    "ysje": '',
                    "ysqje": '',
                    "ybzje": ''
                }
            ];
        }

        initTjInfo();

        //统计信息
        var currTable_tj = table.render({
            elem: '#currentTableId_tj',
            data: dataTj,
            cols: [
                [
                    {field: 'km', title: '', width: '30%'},
                    {field: 'ysje', title: '预算(万元)', width: '23%'},
                    {field: 'ysqje', title: '已申请(元)', width: '23%'},
                    {field: 'ybzje', title: '已报账(元)'}
                ]
            ]
        });

        //任务书
        form.on('select(ysrws)', function (data) {
            var len = $("#ysrws")[0].length;
            while (len > 2)
                $("#ysrws")[0].options[--len].remove();
            if (data.value == "") {
                $("#ysrws").val(0);
                $("#xmid").val('');
                $("#xmmc").val('');
                $("#erpbh").val('');
                $("#xmlx").val('');
                $("#xmlxmc").val('');
                $("#xmfzr").val('');
                $("#xmfzrxm").val('');
                $("#dkyfzr").val('');
                $("#dkyfzrxm").val('');
                $("#ssbm").val('');
                $("#ssbmmc").val('');

                xmId = -1;
                ysId = -1;
                initTjInfo();
                form.render();
            }

            if (data.value == "-1") {
                parent.layer.open({
                    title: '浏览任务书',
                    type: 2,
                    shade: 0.3,
                    maxmin: true,
                    area: ['1200px', '750px'],
                    content: AjaxUtil.ctx + 'staBudgetapproval/init_project/' + $("#nf").val(),
                    end: function (obj) {
                        xmId = parseInt(localStorage.getItem("rws"));
                        var updateflag = localStorage.getItem("updateflag");
                        if (updateflag == "1") {
                            var rwsmc = localStorage.getItem("rwsmc");
                            $("#ysrws").append("<option value=" + xmId + " selected>" + rwsmc + "</option>");
                            $("#xmid").val(xmId);
                            $("#xmmc").val(rwsmc);
                            $("#erpbh").val(localStorage.getItem("erpbh"));
                            $("#xmlx").val(localStorage.getItem("xmlx"));
                            $("#xmlxmc").val(localStorage.getItem("xmlxmc"));
                            $("#xmfzr").val(localStorage.getItem("xmfzr"));
                            $("#xmfzrxm").val(localStorage.getItem("xmfzrxm"));
                            $("#dkyfzr").val(localStorage.getItem("dkyfzr"));
                            $("#dkyfzrxm").val(localStorage.getItem("dkyfzrxm"));
                            $("#ssbm").val(localStorage.getItem("ssbm"));
                            $("#ssbmmc").val(localStorage.getItem("ssbmmc"));

                            $.ajax({
                                url: AjaxUtil.ctx + 'staBudgetapproval/getXmFyInfo/' + xmId + '/' + $("#nf").val(),
                                type: "post",
                                async: false,
                                dataType: "json",
                                success: function (result) {
                                    ysId = result.nys;

                                    dataTj[1].ysje = result.ysje;
                                    dataTj[1].ysqje = result.sqje;
                                    dataTj[1].ybzje = result.bzje;
                                    currTable_tj.reload();

                                    freshFylb();
                                }
                            });
                        } else {
                            $("#ysrws").val(0);
                            $("#xmid").val('');
                            $("#xmmc").val('');
                            $("#erpbh").val('');
                            $("#xmlx").val('');
                            $("#xmlxmc").val('');
                            $("#xmfzr").val('');
                            $("#xmfzrxm").val('');
                            $("#dkyfzr").val('');
                            $("#dkyfzrxm").val('');
                            $("#ssbm").val('');
                            $("#ssbmmc").val('');

                            ysId = -1;
                            initTjInfo();
                        }
                        form.render();
                    }
                });
            }

            return false;
        });

        //费用类别
        element.render('checkbox');

        function freshFylb() {
            tableSelect.render({
                elem: '#fylbmc',
                checkedKey: 'id',
                searchKey: 'mc',
                searchPlaceholder: '搜索费用名称',
                table: {
                    url: AjaxUtil.ctx + 'staBudgetapproval/getSubNode/' + ysId,
                    method: 'get',
                    cols: [
                        [
                            {type: "radio", fixed: 'left'},
                            {type: 'numbers', align: 'center'},
                            {field: 'fymc', width: '50%', title: '费用名称'},
                            {field: 'ysje', title: '预算金额(万元)'}
                        ]
                    ]
                },
                done: function (elem, data) {
                    var NEWJSON = [];
                    var NEWJSON1 = [];
                    var NEWJSON2 = [];
                    var NEWJSON3 = [];
                    layui.each(data.data, function (index, item) {
                        NEWJSON.push(item.fymc);
                        NEWJSON1.push(item.id);
                        NEWJSON2.push(item.fjmc);
                        NEWJSON3.push(item.ysje);
                    })
                    elem.val(NEWJSON.join(","));
                    $("#fylb").val(NEWJSON1.join(","));
                    $("#fjmc").val(NEWJSON2.join(","));
                    dataTj[0].ysje = NEWJSON3.join(",");

                    if ($("#fylbmc").val().indexOf("临时") > -1 && $("#fjmc").val().indexOf("人工费") > -1)
                        document.getElementById('lsryDiv').style.display = 'block';
                    else
                        document.getElementById('lsryDiv').style.display = 'none';

                    if ($("#fylbmc").val().indexOf("设备使用费") > -1)
                        document.getElementById('sbsyfDiv').style.display = 'block';
                    else
                        document.getElementById('sbsyfDiv').style.display = 'none';

                    if ($("#fylbmc").val().indexOf("软件使用费") > -1)
                        document.getElementById('rjsyfDiv').style.display = 'block';
                    else
                        document.getElementById('rjsyfDiv').style.display = 'none';

                    if ($("#fylbmc").val().indexOf("材料费") > -1)
                        document.getElementById('clfyDiv').style.display = 'block';
                    else
                        document.getElementById('clfyDiv').style.display = 'none';

                    if ($("#fylbmc").val().indexOf("外委研究支出费") > -1)
                        document.getElementById('wwyjzcDiv').style.display = 'block';
                    else
                        document.getElementById('wwyjzcDiv').style.display = 'none';

                    if ($("#fylbmc").val().indexOf("外协测试试验与加工费") > -1)
                        document.getElementById('syyjgfDiv').style.display = 'block';
                    else
                        document.getElementById('syyjgfDiv').style.display = 'none';

                    if ($("#fylbmc").val().indexOf("印刷及知识产权费") > -1 || $("#fylbmc").val().indexOf("差旅及国际合作交流费") > -1) {
                        document.getElementById('fyxxDiv').style.display = 'block';
                        if ($("#fylbmc").val().indexOf("印刷及知识产权费") > -1) {
                            $("#bz").val($("#bz1").val());
                            document.getElementById('zlysDiv').style.display = 'block';
                            document.getElementById('hyclDiv').style.display = 'none';
                        } else {
                            $("#bz").val($("#bz2").val());
                            document.getElementById('zlysDiv').style.display = 'none';
                            document.getElementById('hyclDiv').style.display = 'block';

                            if ($("#bz2").val().indexOf("差旅费") > -1)
                                document.getElementById('clfDiv').style.display = 'block';
                            else
                                document.getElementById('clfDiv').style.display = 'none';

                        }
                    } else {
                        document.getElementById('fyxxDiv').style.display = 'none';
                    }

                    $.ajax({
                        url: AjaxUtil.ctx + 'staBudgetapproval/getKmFyInfo/' + ysId + '/' + $("#fylb").val(),
                        type: "post",
                        async: false,
                        dataType: "json",
                        success: function (result) {
                            dataTj[0].ysqje = result.sqje;
                            dataTj[0].ybzje = result.bzje;
                            currTable_tj.reload();
                        }
                    });
                }
            });
        }

        // 用于存放表格数据
        var dataExpense = new Array();
        //差旅费
        var currTable1 = table.render({
            elem: '#currentTableId1',
            data: dataExpense,
            cols: [
                [
                    {type: 'numbers', align: 'center'},
                    {type: "checkbox", align: 'center'},
                    {field: 'ccrxm', title: '出差人', width: '10%'},
                    {field: 'ccdd', title: '出差地点', width: '20%'},
                    {field: 'qsrq', title: '起始日期', width: '13%'},
                    {field: 'jsrq', title: '结束日期(含)', width: '14%'},
                    {field: 'ccts', title: '出差天数', width: '11%'},
                    {field: 'zj', title: '总计(元)', width: '10%'},
                    {field: 'rpj', title: '日平均(元)', width: '12%'}
                ]
            ]
        });
        // 监听新建按钮（差旅费）
        $("button[lay-filter='subAdd']").click(function () {
            layer.open({
                title: '新建差旅费',
                type: 2,
                maxmin: true,
                shade: 0.2,
                area: [layerwidth + 'px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staTravelexpenses/forAdd',
                end: function (index) {
                    if (updateflag == 1) {
                        updateflag = 0;

                        //刷新表格
                        var oldData = table.cache["currentTableId1"];
                        oldData.push(travelExpense);
                        table.reload('currentTableId1', {
                            data: oldData
                        });
                    }
                }
            });
        });
        // 监听编辑按钮（差旅费）
        $("button[lay-filter='subEdit']").click(function () {
            var oldData = table.cache["currentTableId1"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId1')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要编辑的差旅费！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行编辑操作！", 1500);
            } else {
                travelExpense = {
                    "xh": data[0].xh,
                    "ccr": data[0].ccr,
                    "ccrxm": data[0].ccrxm,
                    "ccdd": data[0].ccdd,
                    "ccts": data[0].ccts,
                    "qsrq": data[0].qsrq,
                    "jsrq": data[0].jsrq,
                    "jtf": data[0].jtf,
                    "zsf": data[0].zsf,
                    "cb": data[0].cb,
                    "zj": data[0].zj,
                    "rpj": data[0].rpj
                };
                layer.open({
                    title: '编辑差旅费',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'staTravelexpenses/forUpdate',
                    end: function (index) {

                        if (updateflag == 1) {
                            updateflag = 0;

                            for (var i = 0; i < oldData.length; i++) {
                                var item = oldData[i];
                                if (item.LAY_CHECKED) {//条件：选中
                                    oldData[i] = travelExpense;
                                    break;
                                }
                            }
                            //刷新表格
                            var currData = oldData;
                            table.reload('currentTableId1', {
                                data: currData
                            });
                        }
                    }
                });
            }
        });
        // 监听查看按钮（差旅费）
        $("button[lay-filter='subView']").click(function () {
            var oldData = table.cache["currentTableId1"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId1')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要浏览的差旅费！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行浏览！", 1500);
            } else {
                travelExpense = {
                    "xh": data[0].xh,
                    "ccr": data[0].ccr,
                    "ccrxm": data[0].ccrxm,
                    "ccdd": data[0].ccdd,
                    "ccts": data[0].ccts,
                    "qsrq": data[0].qsrq,
                    "jsrq": data[0].jsrq,
                    "jtf": data[0].jtf,
                    "zsf": data[0].zsf,
                    "cb": data[0].cb,
                    "zj": data[0].zj,
                    "rpj": data[0].rpj
                };
                layer.open({
                    title: '浏览差旅费',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'staTravelexpenses/forView',
                    end: function (index) {
                        layer.close(index);
                    }
                });
            }
        });
        // 监听删除按钮（差旅费）
        $("button[lay-filter='subDelete']").click(function () {
            var oldData = table.cache["currentTableId1"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId1')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要删除的差旅费！", 1000);
                return;
            }
            for (var i = 0; i < oldData.length; i++) {
                var item = oldData[i];
                if (item.LAY_CHECKED) {//条件：选中
                    oldData.splice(i, 1);//移除后后造成数组下标索引发生变化，所以下面需要i--
                    i--;
                }
            }
            //刷新表格
            var currData = oldData;
            table.reload('currentTableId1', {
                data: currData
            });
        });
        //双击（差旅费）
        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
            };
            layer.open({
                title: '浏览差旅费',
                type: 2,
                maxmin: true,
                shade: 0.2,
                area: [layerwidth + 'px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staTravelexpenses/forView',
                end: function (index) {
                    layer.close(index);
                }
            });
        });

        // 用于存放表格数据
        var dataMember = new Array();
        //临时人员
        var currTable3 = table.render({
            elem: '#currentTableId3',
            data: dataMember,
            cols: [
                [
                    {type: "checkbox", align: 'center'},
                    {type: 'numbers', align: 'center'},
                    {field: 'xm', title: '姓名', width: '13%'},
                    {field: 'xlmc', title: '学历', width: '13%'},
                    {field: 'gznr', title: '工作内容', width: '36%'},
                    {field: 'qsrq', title: '起始日期', width: '13%'},
                    {field: 'jsrq', title: '结束日期', width: '13%'}
                ]
            ]
        });
        // 监听新建按钮（临时人员）
        $("button[lay-filter='subAdd3']").click(function () {
            layer.open({
                title: '新建临时人员',
                type: 2,
                maxmin: true,
                shade: 0.2,
                area: [layerwidth + 'px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staTempmember/forAdd',
                end: function (index) {
                    if (updateflag == 1) {
                        updateflag = 0;

                        for (let item of dataMember) {
                            if (item.xm === tempMember.xm) {
                                Message.error("该人员已在列表中！", 1000);
                                return false;
                            }
                        }

                        $.ajax({
                            url: AjaxUtil.ctx + 'staTempmember/memberExist?xm=' + tempMember.xm + '&qsrq=' + tempMember.qsrq + '&jsrq=' + tempMember.jsrq,
                            type: "post",
                            async: false,
                            dataType: "json",
                            success: function (result) {
                                if (result) {
                                    Message.error("该人员已在其它项目！", 2000);
                                    return false;
                                } else {
                                    //刷新表格
                                    var oldData = table.cache["currentTableId3"];
                                    oldData.push(tempMember);
                                    table.reload('currentTableId3', {
                                        data: oldData
                                    });
                                }
                            }
                        });
                    }
                    layer.close(index);
                }
            });
        });
        // 监听编辑按钮（临时人员）
        $("button[lay-filter='subEdit3']").click(function () {
            var oldData = table.cache["currentTableId3"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId3')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要编辑的临时人员！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行编辑操作！", 1500);
            } else {
                tempMember = {
                    "xm": data[0].xm,
                    "xlmc": data[0].xlmc,
                    "gznr": data[0].gznr,
                    "qsrq": data[0].qsrq,
                    "jsrq": data[0].jsrq
                };
                layer.open({
                    title: '编辑临时人员',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'staTempmember/forUpdate',
                    end: function (index) {

                        if (updateflag == 1) {
                            updateflag = 0;

                            for (var i = 0; i < oldData.length; i++) {
                                var item = oldData[i];
                                if (item.LAY_CHECKED) {//条件：选中
                                    oldData[i] = tempMember;
                                    break;
                                }
                            }
                            //刷新表格
                            var currData = oldData;
                            table.reload('currentTableId3', {
                                data: currData
                            });
                        }
                        layer.close(index);
                    }
                });
            }
        });
        // 监听查看按钮（临时人员）
        $("button[lay-filter='subView3']").click(function () {
            var oldData = table.cache["currentTableId3"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId3')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要浏览的临时人员！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行浏览！", 1500);
            } else {
                tempMember = {
                    "xm": data[0].xm,
                    "xlmc": data[0].xlmc,
                    "gznr": data[0].gznr,
                    "qsrq": data[0].qsrq,
                    "jsrq": data[0].jsrq
                };
                layer.open({
                    title: '浏览临时人员',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'staTempmember/forView',
                    end: function (index) {
                        layer.close(index);
                    }
                });
            }
        });
        // 监听删除按钮（临时人员）
        $("button[lay-filter='subDelete3']").click(function () {
            var oldData = table.cache["currentTableId3"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId3')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要删除的临时人员！", 1000);
                return;
            }
            for (var i = 0; i < oldData.length; i++) {
                var item = oldData[i];
                if (item.LAY_CHECKED) {//条件：选中
                    oldData.splice(i, 1);//移除后后造成数组下标索引发生变化，所以下面需要i--
                    i--;
                }
            }
            //刷新表格
            var currData = oldData;
            table.reload('currentTableId3', {
                data: currData
            });
        });
        //双击（临时人员）
        table.on('rowDouble(currentTableFilter3)', function (obj) {
            var data = obj.data;
            tempMember = {
                "xm": data.xm,
                "xlmc": data.xlmc,
                "gznr": data.gznr,
                "qsrq": data.qsrq,
                "jsrq": data.jsrq
            };
            layer.open({
                title: '浏览临时人员',
                type: 2,
                maxmin: true,
                shade: 0.2,
                area: [layerwidth + 'px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staTempmember/forView',
                end: function (index) {
                    layer.close(index);
                }
            });
        });

        // 用于存放表格数据
        var dataFj = new Array();
        //附件
        var currTable2 = table.render({
            elem: '#currentTableId2',
            data: dataFj,
            cols: [
                [
                    {type: "checkbox", align: 'center'},
                    {type: 'numbers', align: 'center'},
                    {field: 'wjm', title: '文件名', width: '30%'},
                    {field: 'scrq', title: '上传日期', width: '20%'},
                    {field: 'sm', title: '说明', edit: 'text'}
                ]
            ],
            autoSort: false,
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: false,
            skin: 'grid',
            done: function (res, curr, count) { // done为数据渲染完的回调
            }
        });

        //文件上传
        upload.render({
            elem: '.upload' //绑定元素
            , url: AjaxUtil.ctx + 'fileupload/upload'
            , methd: 'post'
            , accept: 'file'
            , data: {}
            , done: function (res) {
                if (0 === res.code) {
                    var curData = {
                        "wjm": res.data.fileName,
                        "scrq": res.data.fileDate,
                        "Url": res.data.fileUrl,
                        "sm": res.data.sm
                    };
                    dataFj.push(curData);
                    currTable2.reload();
                } else
                    layer.alert("上传文件出现错误！");

            }
            , error: function () {
                layer.alert("上传文件出现错误！");
            }
            , before: function (res) {
                let fileType = this.fileType;
                this.data.fileType = fileType;
            }
        });
        $("button[lay-filter='deleteFile']").click(function () {
            if (dataFj.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId2')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要删除的附件！", 1000);
                return;
            }
            var oldData = table.cache["currentTableId2"];
            for (var i = 0; i < oldData.length; i++) {
                var item = oldData[i];
                if (item.LAY_CHECKED) {//条件：选中
                    oldData.splice(i, 1);//移除后后造成数组下标索引发生变化，所以下面需要i--
                    i--;
                }
            }
            //刷新表格
            var currData = oldData;
            table.reload('currentTableId2', {
                data: currData
            });
        });
        //双击（附件）
        table.on('rowDouble(currentTableFilter2)', function (obj) {
            window.open(obj.data.Url);
        });

        // 用于存放表格数据
        var dataDevice = new Array();
        //设备使用费
        var tabDevice = table.render({
            elem: '#currentTableId_Dev',
            data: dataDevice,
            cols: [
                [
                    {type: "checkbox", align: 'center'},
                    {field: 'xh', title: '序号', width: '7%'},
                    {field: 'sbmc', title: '设备名称', width: '30%'},
                    {field: 'sbxh', title: '设备型号', width: '20%'},
                    {field: 'sl', title: '数量(台件)', width: '13%'},
                    {field: 'zj', title: '总价(万元)', width: '13%'},
                    {field: 'gzsj', title: '购置时间', width: '13%'}
                ]
            ],
            autoSort: true,
            initSort: {
                field: 'xh', //排序字段
                type: 'asc' //排序方式:desc 降序,asc 升序
            }
        });
        // 监听新建按钮（设备使用费）
        $("button[lay-filter='subAdd_Dev']").click(function () {
            layer.open({
                title: '新建仪器设备使用费',
                type: 2,
                // maxmin: true,
                shade: 0.2,
                area: [layerwidth + 'px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staDeviceexpenses/forAdd',
                end: function (index) {
                    if (updateflag == 1) {
                        updateflag = 0;

                        //刷新表格
                        var oldData = table.cache["currentTableId_Dev"];
                        oldData.push(devExpense);
                        table.reload('currentTableId_Dev', {
                            data: oldData
                        });
                    }
                }
            });
        });
        // 监听编辑按钮（设备使用费）
        $("button[lay-filter='subEdit_Dev']").click(function () {
            var oldData = table.cache["currentTableId_Dev"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId_Dev')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要编辑的仪器设备使用费！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行编辑操作！", 1500);
            } else {
                devExpense = {
                    "xh": data[0].xh,
                    "sbmc": data[0].sbmc,
                    "sbxh": data[0].sbxh,
                    "dj": data[0].dj,
                    "sl": data[0].sl,
                    "zj": data[0].zj,
                    "gzsj": data[0].gzsj,
                    "syfjqdj": data[0].syfjqdj,
                    "scgbydq": data[0].scgbydq,
                    "lsdw": data[0].lsdw,
                    "sbzkjzyxnzb": data[0].sbzkjzyxnzb
                };
                layer.open({
                    title: '编辑仪器设备使用费',
                    type: 2,
                    // maxmin: true,
                    shade: 0.2,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'staDeviceexpenses/forUpdate',
                    end: function (index) {

                        if (updateflag == 1) {
                            updateflag = 0;

                            for (var i = 0; i < oldData.length; i++) {
                                var item = oldData[i];
                                if (item.LAY_CHECKED) {//条件：选中
                                    oldData[i] = devExpense;
                                    break;
                                }
                            }
                            //刷新表格
                            var currData = oldData;
                            table.reload('currentTableId_Dev', {
                                data: currData
                            });
                        }
                    }
                });
            }
        });
        // 监听查看按钮（设备使用费）
        $("button[lay-filter='subView_Dev']").click(function () {
            var oldData = table.cache["currentTableId_Dev"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId_Dev')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要浏览的仪器设备使用费！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行浏览！", 1500);
            } else {
                devExpense = {
                    "xh": data[0].xh,
                    "sbmc": data[0].sbmc,
                    "sbxh": data[0].sbxh,
                    "dj": data[0].dj,
                    "sl": data[0].sl,
                    "zj": data[0].zj,
                    "gzsj": data[0].gzsj,
                    "syfjqdj": data[0].syfjqdj,
                    "scgbydq": data[0].scgbydq,
                    "lsdw": data[0].lsdw,
                    "sbzkjzyxnzb": data[0].sbzkjzyxnzb
                };
                layer.open({
                    title: '浏览仪器设备使用费',
                    type: 2,
                    // maxmin: true,
                    shade: 0.2,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'staDeviceexpenses/forView',
                    end: function (index) {
                        layer.close(index);
                    }
                });
            }
        });
        // 监听删除按钮（设备使用费）
        $("button[lay-filter='subDelete_Dev']").click(function () {
            var oldData = table.cache["currentTableId_Dev"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId_Dev')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要删除的仪器设备使用费！", 1000);
                return;
            }

            for (var i = 0; i < oldData.length; i++) {
                var item = oldData[i];
                if (item.LAY_CHECKED) {//条件：选中
                    oldData.splice(i, 1);//移除后后造成数组下标索引发生变化，所以下面需要i--
                    i--;
                }
            }
            //刷新表格
            var currData = oldData;
            table.reload('currentTableId_Dev', {
                data: currData
            });
        });
        //双击（设备使用费）
        table.on('rowDouble(currentTableFilter_Dev)', function (obj) {
            var data = obj.data;
            devExpense = {
                "xh": data.xh,
                "sbmc": data.sbmc,
                "sbxh": data.sbxh,
                "dj": data.dj,
                "sl": data.sl,
                "zj": data.zj,
                "gzsj": data.gzsj,
                "syfjqdj": data.syfjqdj,
                "scgbydq": data.scgbydq,
                "lsdw": data.lsdw,
                "sbzkjzyxnzb": data.sbzkjzyxnzb
            };
            layer.open({
                title: '浏览仪器设备使用费',
                type: 2,
                // maxmin: true,
                shade: 0.2,
                area: [layerwidth + 'px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staDeviceexpenses/forView',
                end: function (index) {
                    layer.close(index);
                }
            });
        });

        // 用于存放表格数据
        var dataSoftW = new Array();
        //软件使用费
        var tabSoftW = table.render({
            elem: '#currentTableId_Sw',
            data: dataSoftW,
            cols: [
                [
                    {type: "checkbox", align: 'center'},
                    {field: 'xh', title: '序号', align: 'center', width: '7%'},
                    {field: 'rjmc', title: '软件名称', width: '30%'},
                    {field: 'rjxh', title: '软件型号', width: '20%'},
                    {field: 'sl', title: '数量(套)', width: '13%'},
                    {field: 'zj', title: '总价(万元)', width: '13%'},
                    {field: 'gzsj', title: '购置时间', width: '13%'}
                ]
            ],
            autoSort: true,
            initSort: {
                field: 'xh', //排序字段
                type: 'asc' //排序方式:desc 降序,asc 升序
            }
        });
        // 监听新建按钮（软件使用费）
        $("button[lay-filter='subAdd_Sw']").click(function () {
            layer.open({
                title: '新建软件使用费',
                type: 2,
                // maxmin: true,
                shade: 0.2,
                area: [layerwidth + 'px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staSoftwareexpenses/forAdd',
                end: function (index) {
                    if (updateflag == 1) {
                        updateflag = 0;

                        //刷新表格
                        var oldData = table.cache["currentTableId_Sw"];
                        oldData.push(softExpense);
                        table.reload('currentTableId_Sw', {
                            data: oldData
                        });
                    }
                }
            });
        });
        // 监听编辑按钮（软件使用费）
        $("button[lay-filter='subEdit_Sw']").click(function () {
            var oldData = table.cache["currentTableId_Sw"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId_Sw')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要编辑的软件使用费！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行编辑操作！", 1500);
            } else {
                softExpense = {
                    "xh": data[0].xh,
                    "rjmc": data[0].rjmc,
                    "rjxh": data[0].rjxh,
                    "dj": data[0].dj,
                    "sl": data[0].sl,
                    "zj": data[0].zj,
                    "gzsj": data[0].gzsj,
                    "syfjqdj": data[0].syfjqdj,
                    "scgbydq": data[0].scgbydq,
                    "lsdw": data[0].lsdw,
                    "rjzyjsxnzb": data[0].rjzyjsxnzb
                };
                layer.open({
                    title: '编辑软件使用费',
                    type: 2,
                    // maxmin: true,
                    shade: 0.2,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'staSoftwareexpenses/forUpdate',
                    end: function (index) {

                        if (updateflag == 1) {
                            updateflag = 0;

                            for (var i = 0; i < oldData.length; i++) {
                                var item = oldData[i];
                                if (item.LAY_CHECKED) {//条件：选中
                                    oldData[i] = softExpense;
                                    break;
                                }
                            }
                            //刷新表格
                            var currData = oldData;
                            table.reload('currentTableId_Sw', {
                                data: currData
                            });
                        }
                    }
                });
            }
        });
        // 监听查看按钮（软件使用费）
        $("button[lay-filter='subView_Sw']").click(function () {
            var oldData = table.cache["currentTableId_Sw"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId_Sw')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要浏览的软件使用费！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行浏览！", 1500);
            } else {
                softExpense = {
                    "xh": data[0].xh,
                    "rjmc": data[0].rjmc,
                    "rjxh": data[0].rjxh,
                    "dj": data[0].dj,
                    "sl": data[0].sl,
                    "zj": data[0].zj,
                    "gzsj": data[0].gzsj,
                    "syfjqdj": data[0].syfjqdj,
                    "scgbydq": data[0].scgbydq,
                    "lsdw": data[0].lsdw,
                    "rjzyjsxnzb": data[0].rjzyjsxnzb
                };
                layer.open({
                    title: '浏览软件使用费',
                    type: 2,
                    // maxmin: true,
                    shade: 0.2,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'staSoftwareexpenses/forView',
                    end: function (index) {
                        layer.close(index);
                    }
                });
            }
        });
        // 监听删除按钮（软件使用费）
        $("button[lay-filter='subDelete_Sw']").click(function () {
            var oldData = table.cache["currentTableId_Sw"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId_Sw')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要删除的软件使用费！", 1000);
                return;
            }

            for (var i = 0; i < oldData.length; i++) {
                var item = oldData[i];
                if (item.LAY_CHECKED) {//条件：选中
                    oldData.splice(i, 1);//移除后后造成数组下标索引发生变化，所以下面需要i--
                    i--;
                }
            }
            //刷新表格
            var currData = oldData;
            table.reload('currentTableId_Sw', {
                data: currData
            });
        });
        //双击（软件使用费）
        table.on('rowDouble(currentTableFilter_Sw)', function (obj) {
            var data = obj.data;
            softExpense = {
                "xh": data.xh,
                "rjmc": data.rjmc,
                "rjxh": data.rjxh,
                "dj": data.dj,
                "sl": data.sl,
                "zj": data.zj,
                "gzsj": data.gzsj,
                "syfjqdj": data.syfjqdj,
                "scgbydq": data.scgbydq,
                "lsdw": data.lsdw,
                "rjzyjsxnzb": data.rjzyjsxnzb
            };
            layer.open({
                title: '浏览软件使用费',
                type: 2,
                // maxmin: true,
                shade: 0.2,
                area: [layerwidth + 'px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staSoftwareexpenses/forView',
                end: function (index) {
                    layer.close(index);
                }
            });
        });

        // 用于存放表格数据
        var dataMaterial = new Array();
        //材料费
        var tabMaterial = table.render({
            elem: '#currentTableId_Clf',
            data: dataMaterial,
            cols: [
                [
                    {type: "checkbox", align: 'center'},
                    {field: 'xh', title: '序号', align: 'center', width: '7%'},
                    {field: 'clmc', title: '材料名称', width: '30%'},
                    {field: 'gghxh', title: '规格或型号', width: '20%'},
                    {field: 'jldw', title: '计量单位', width: '11%'},
                    {field: 'dj', title: '单价(万元)', width: '13%'},
                    {field: 'clfy', title: '材料费用', width: '15%'}
                ]
            ],
            autoSort: true,
            initSort: {
                field: 'xh', //排序字段
                type: 'asc' //排序方式:desc 降序,asc 升序
            }
        });
        // 监听新建按钮（材料费）
        $("button[lay-filter='subAdd_Clf']").click(function () {
            layer.open({
                title: '新建材料费',
                type: 2,
                // maxmin: true,
                shade: 0.2,
                area: [layerwidth + 'px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staMaterialcost/forAdd',
                end: function (index) {
                    if (updateflag == 1) {
                        updateflag = 0;

                        //刷新表格
                        var oldData = table.cache["currentTableId_Clf"];
                        oldData.push(materialCost);
                        table.reload('currentTableId_Clf', {
                            data: oldData
                        });
                    }
                }
            });
        });
        // 监听编辑按钮（材料费）
        $("button[lay-filter='subEdit_Clf']").click(function () {
            var oldData = table.cache["currentTableId_Clf"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId_Clf')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要编辑的材料费！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行编辑操作！", 1500);
            } else {
                materialCost = {
                    "xh": data[0].xh,
                    "clmc": data[0].clmc,
                    "gghxh": data[0].gghxh,
                    "jldw": data[0].jldw,
                    "dj": data[0].dj,
                    "clfy": data[0].clfy,
                    "jflz": data[0].jflz
                };
                layer.open({
                    title: '编辑材料费',
                    type: 2,
                    // maxmin: true,
                    shade: 0.2,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'staMaterialcost/forUpdate',
                    end: function (index) {

                        if (updateflag == 1) {
                            updateflag = 0;

                            for (var i = 0; i < oldData.length; i++) {
                                var item = oldData[i];
                                if (item.LAY_CHECKED) {//条件：选中
                                    oldData[i] = materialCost;
                                    break;
                                }
                            }
                            //刷新表格
                            var currData = oldData;
                            table.reload('currentTableId_Clf', {
                                data: currData
                            });
                        }
                    }
                });
            }
        });
        // 监听查看按钮（材料费）
        $("button[lay-filter='subView_Clf']").click(function () {
            var oldData = table.cache["currentTableId_Clf"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId_Clf')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要浏览的材料费！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行浏览！", 1500);
            } else {
                materialCost = {
                    "xh": data[0].xh,
                    "clmc": data[0].clmc,
                    "gghxh": data[0].gghxh,
                    "jldw": data[0].jldw,
                    "dj": data[0].dj,
                    "clfy": data[0].clfy,
                    "jflz": data[0].jflz
                };
                layer.open({
                    title: '浏览材料费',
                    type: 2,
                    // maxmin: true,
                    shade: 0.2,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'staMaterialcost/forView',
                    end: function (index) {
                        layer.close(index);
                    }
                });
            }
        });
        // 监听删除按钮（材料费）
        $("button[lay-filter='subDelete_Clf']").click(function () {
            var oldData = table.cache["currentTableId_Clf"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId_Clf')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要删除的材料费！", 1000);
                return;
            }
            for (var i = 0; i < oldData.length; i++) {
                var item = oldData[i];
                if (item.LAY_CHECKED) {//条件：选中
                    oldData.splice(i, 1);//移除后后造成数组下标索引发生变化，所以下面需要i--
                    i--;
                }
            }
            //刷新表格
            var currData = oldData;
            table.reload('currentTableId_Clf', {
                data: currData
            });
        });
        //双击（材料费）
        table.on('rowDouble(currentTableFilter_Clf)', function (obj) {
            var data = obj.data;
            materialCost = {
                "xh": data.xh,
                "clmc": data.clmc,
                "gghxh": data.gghxh,
                "jldw": data.jldw,
                "dj": data.dj,
                "clfy": data.clfy,
                "jflz": data.jflz
            };
            layer.open({
                title: '浏览材料费',
                type: 2,
                // maxmin: true,
                shade: 0.2,
                area: [layerwidth + 'px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staMaterialcost/forView',
                end: function (index) {
                    layer.close(index);
                }
            });
        });

        // 用于存放表格数据
        var dataOut = new Array();
        //外委研究支出
        var tabOut = table.render({
            elem: '#currentTableId_Ww',
            data: dataOut,
            cols: [
                [
                    {type: "checkbox", align: 'center'},
                    {field: 'xh', title: '序号', align: 'center', width: '7%'},
                    {field: 'xzyjrwmc', title: '协作研究任务名称', width: '25%'},
                    {field: 'xzyjrwnr', title: '协作研究任务内容', width: '25%'},
                    {field: 'xzyjrwcddw', title: '协作研究任务承担单位', width: '25%'},
                    {field: 'jflz', title: '经费列支', width: '15%'}
                ]
            ],
            autoSort: true,
            initSort: {
                field: 'xh', //排序字段
                type: 'asc' //排序方式:desc 降序,asc 升序
            }
        });
        // 监听新建按钮（外委研究支出）
        $("button[lay-filter='subAdd_Ww']").click(function () {
            layer.open({
                title: '新建外委研究支出',
                type: 2,
                // maxmin: true,
                shade: 0.2,
                area: [layerwidth + 'px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staOutexpense/forAdd',
                end: function (index) {
                    if (updateflag == 1) {
                        updateflag = 0;

                        //刷新表格
                        var oldData = table.cache["currentTableId_Ww"];
                        oldData.push(outExpense);
                        table.reload('currentTableId_Ww', {
                            data: oldData
                        });
                    }
                }
            });
        });
        // 监听编辑按钮（外委研究支出）
        $("button[lay-filter='subEdit_Ww']").click(function () {
            var oldData = table.cache["currentTableId_Ww"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId_Ww')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要编辑的外委研究支出！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行编辑操作！", 1500);
            } else {
                outExpense = {
                    "xh": data[0].xh,
                    "xzyjrwmc": data[0].xzyjrwmc,
                    "xzyjrwnr": data[0].xzyjrwnr,
                    "xzyjrwcddw": data[0].xzyjrwcddw,
                    "jflz": data[0].jflz
                };
                layer.open({
                    title: '编辑外委研究支出',
                    type: 2,
                    // maxmin: true,
                    shade: 0.2,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'staOutexpense/forUpdate',
                    end: function (index) {

                        if (updateflag == 1) {
                            updateflag = 0;

                            for (var i = 0; i < oldData.length; i++) {
                                var item = oldData[i];
                                if (item.LAY_CHECKED) {//条件：选中
                                    oldData[i] = outExpense;
                                    break;
                                }
                            }
                            //刷新表格
                            var currData = oldData;
                            table.reload('currentTableId_Ww', {
                                data: currData
                            });
                        }
                    }
                });
            }
        });
        // 监听查看按钮（外委研究支出）
        $("button[lay-filter='subView_Ww']").click(function () {
            var oldData = table.cache["currentTableId_Ww"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId_Ww')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要浏览的外委研究支出！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行浏览！", 1500);
            } else {
                outExpense = {
                    "xh": data[0].xh,
                    "xzyjrwmc": data[0].xzyjrwmc,
                    "xzyjrwnr": data[0].xzyjrwnr,
                    "xzyjrwcddw": data[0].xzyjrwcddw,
                    "jflz": data[0].jflz
                };
                layer.open({
                    title: '浏览外委研究支出',
                    type: 2,
                    // maxmin: true,
                    shade: 0.2,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'staOutexpense/forView',
                    end: function (index) {
                        layer.close(index);
                    }
                });
            }
        });
        // 监听删除按钮（外委研究支出）
        $("button[lay-filter='subDelete_Ww']").click(function () {
            var oldData = table.cache["currentTableId_Ww"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId_Ww')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要删除的外委研究支出！", 1000);
                return;
            }
            for (var i = 0; i < oldData.length; i++) {
                var item = oldData[i];
                if (item.LAY_CHECKED) {//条件：选中
                    oldData.splice(i, 1);//移除后后造成数组下标索引发生变化，所以下面需要i--
                    i--;
                }
            }
            //刷新表格
            var currData = oldData;
            table.reload('currentTableId_Ww', {
                data: currData
            });
        });
        //双击（外委研究支出）
        table.on('rowDouble(currentTableFilter_Ww)', function (obj) {
            var data = obj.data;
            outExpense = {
                "xh": data.xh,
                "xzyjrwmc": data.xzyjrwmc,
                "xzyjrwnr": data.xzyjrwnr,
                "xzyjrwcddw": data.xzyjrwcddw,
                "jflz": data.jflz
            };
            layer.open({
                title: '浏览外委研究支出',
                type: 2,
                // maxmin: true,
                shade: 0.2,
                area: [layerwidth + 'px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staOutexpense/forView',
                end: function (index) {
                    layer.close(index);
                }
            });
        });

        // 用于存放表格数据
        var dataTest = new Array();
        //外协测试试验
        var tabTest = table.render({
            elem: '#currentTableId_Wx',
            data: dataTest,
            cols: [
                [
                    {type: "checkbox", align: 'center'},
                    {field: 'xh', title: '序号', align: 'center', width: '7%'},
                    {field: 'wxcssyyjgnr', title: '外协测试试验与加工的内容', width: '30%'},
                    {field: 'wxcshyyjgdw', title: '外协测试化验与加工单位', width: '28%'},
                    {field: 'wxcshyyjgfy', title: '外协测试化验与加工费用(万元)'}
                ]
            ],
            autoSort: true,
            initSort: {
                field: 'xh', //排序字段
                type: 'asc' //排序方式:desc 降序,asc 升序
            }
        });
        // 监听新建按钮（外协测试试验）
        $("button[lay-filter='subAdd_Wx']").click(function () {
            layer.open({
                title: '新建外协测试试验与加工费',
                type: 2,
                // maxmin: true,
                shade: 0.2,
                area: [layerwidth + 'px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staOutttesting/forAdd',
                end: function (index) {
                    if (updateflag == 1) {
                        updateflag = 0;

                        //刷新表格
                        var oldData = table.cache["currentTableId_Wx"];
                        oldData.push(outTesting);
                        table.reload('currentTableId_Wx', {
                            data: oldData
                        });
                    }
                }
            });
        });
        // 监听编辑按钮（外协测试试验）
        $("button[lay-filter='subEdit_Wx']").click(function () {
            var oldData = table.cache["currentTableId_Wx"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId_Wx')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要编辑的外协测试试验与加工费！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行编辑操作！", 1500);
            } else {
                outTesting = {
                    "xh": data[0].xh,
                    "wxcssyyjgnr": data[0].wxcssyyjgnr,
                    "wxcshyyjgdw": data[0].wxcshyyjgdw,
                    "jldw": data[0].jldw,
                    "dj": data[0].dj,
                    "wxcshyyjgfy": data[0].wxcshyyjgfy,
                    "jflz": data[0].jflz
                };
                layer.open({
                    title: '编辑外协测试试验与加工费',
                    type: 2,
                    // maxmin: true,
                    shade: 0.2,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'staOutttesting/forUpdate',
                    end: function (index) {

                        if (updateflag == 1) {
                            updateflag = 0;

                            for (var i = 0; i < oldData.length; i++) {
                                var item = oldData[i];
                                if (item.LAY_CHECKED) {//条件：选中
                                    oldData[i] = outTesting;
                                    break;
                                }
                            }
                            //刷新表格
                            var currData = oldData;
                            table.reload('currentTableId_Wx', {
                                data: currData
                            });
                        }
                    }
                });
            }
        });
        // 监听查看按钮（外协测试试验）
        $("button[lay-filter='subView_Wx']").click(function () {
            var oldData = table.cache["currentTableId_Wx"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId_Wx')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要浏览的外协测试试验与加工费！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行浏览！", 1500);
            } else {
                outTesting = {
                    "xh": data[0].xh,
                    "wxcssyyjgnr": data[0].wxcssyyjgnr,
                    "wxcshyyjgdw": data[0].wxcshyyjgdw,
                    "jldw": data[0].jldw,
                    "dj": data[0].dj,
                    "wxcshyyjgfy": data[0].wxcshyyjgfy,
                    "jflz": data[0].jflz
                };
                layer.open({
                    title: '浏览外协测试试验与加工费',
                    type: 2,
                    // maxmin: true,
                    shade: 0.2,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'staOutttesting/forView',
                    end: function (index) {
                        layer.close(index);
                    }
                });
            }
        });
        // 监听删除按钮（外协测试试验）
        $("button[lay-filter='subDelete_Wx']").click(function () {
            var oldData = table.cache["currentTableId_Wx"];
            if (oldData.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId_Wx')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要删除的外协测试试验与加工费！", 1000);
                return;
            }
            for (var i = 0; i < oldData.length; i++) {
                var item = oldData[i];
                if (item.LAY_CHECKED) {//条件：选中
                    oldData.splice(i, 1);//移除后后造成数组下标索引发生变化，所以下面需要i--
                    i--;
                }
            }
            //刷新表格
            var currData = oldData;
            table.reload('currentTableId_Wx', {
                data: currData
            });
        });
        //双击（外协测试试验）
        table.on('rowDouble(currentTableFilter_Wx)', function (obj) {
            var data = obj.data;
            outTesting = {
                "xh": data.xh,
                "wxcssyyjgnr": data.wxcssyyjgnr,
                "wxcshyyjgdw": data.wxcshyyjgdw,
                "jldw": data.jldw,
                "dj": data.dj,
                "wxcshyyjgfy": data.wxcshyyjgfy,
                "jflz": data.jflz
            };
            layer.open({
                title: '浏览外协测试试验与加工费',
                type: 2,
                // maxmin: true,
                shade: 0.2,
                area: [layerwidth + 'px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staOutttesting/forView',
                end: function (index) {
                    layer.close(index);
                }
            });
        });

        // 监听查看任务书按钮
        $("button[lay-filter='viewRwsBtn']").click(function () {
            if (xmId == -1)
                Message.error("请选择费用申请的项目，然后再查看任务书", 2000);
            else {
                var index = parent.layer.open({
                    title: '查看项目任务书',
                    type: 2,
                    shade: 0.3,
                    // maxmin: true,
                    shadeClose: true,
                    area: ['1100px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjProject/forView/' + xmId,
                    end: function () {
                        layer.close(index);
                    }
                });
            }
        });

        // 监听查看年度预算按钮
        $("button[lay-filter='viewNdysBtn']").click(function () {
            if (xmId == -1)
                Message.error("请选择费用申请的项目，然后再查看任务书", 2000);
            else {
                var index = parent.layer.open({
                    title: '查看年度预算',
                    type: 2,
                    shade: 0.3,
                    // maxmin: true,
                    shadeClose: true,
                    area: ['1010px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjAnnualbudget/forNdysView/' + xmId,
                    end: function () {
                        layer.close(index);
                    }
                });
            }
        });

        // 监听确认按钮
        form.on('submit(saveBtn)', function (data) {
            //附件
            var dataWB = [];
            for (const item of dataFj) {
                var dfWb = {
                    "id": item.id,
                    "wjm": item.wjm,
                    "Url": item.Url,
                    "scrq": item.scrq,
                    "sm": item.sm
                };
                dataWB.push(dfWb);
            }
            $("#fj").val(JSON.stringify(dataWB));
            data.field.fj = JSON.stringify(dataWB);
            data.field.nys = ysId;

            //基本信息
            var index = layer.load(0, {shade: 0.1});
            AjaxUtil.post({
                url: AjaxUtil.ctx + "staBudgetapproval/ImprestConnect",
                data: data.field,
                success: function (res) {
                    layer.close(index);
                    if (res.code === 0) {
                        Message.success(1000, res.message, function () {
                            parent.setUpdateFlag();

                            //差旅费
                            if ($("#fylbmc").val().indexOf("差旅及国际合作交流费") > -1 && $("#bz2").val().indexOf("差旅费") > -1) {
                                var travleExpenses = [];
                                var curData = table.cache["currentTableId1"];
                                for (const item of curData) {
                                    var expense = {
                                        "zb": fyId,
                                        "xh": item.xh,
                                        "ccr": item.ccr,
                                        "ccdd": item.ccdd,
                                        "qsrq": item.qsrq,
                                        "jtf": item.jtf,
                                        "zsf": item.zsf,
                                        "cb": item.cb,
                                        "jsrq": item.jsrq,
                                        "ccts": item.ccts,
                                        "zj": item.zj,
                                        "rpj": item.rpj
                                    };
                                    travleExpenses.push(expense);
                                }
                                //保存差旅费
                                AjaxUtil.post({
                                    url: AjaxUtil.ctx + "staTravelexpenses/batchInsert/" + fyId,
                                    contentType: "application/json",
                                    data: JSON.stringify(travleExpenses),
                                    success: function (res) {
                                        if (res.code === 0) {
                                            // Message.success(1000, res.message, function () {
                                            //
                                            // });
                                        } else {
                                            // Message.error(res.message, 1000);
                                        }
                                    },
                                    error: function (error) {
                                    }
                                });
                            }//临时人员
                            else if ($("#fylbmc").val().indexOf("临时") > -1 && $("#fjmc").val().indexOf("人工费") > -1) {
                                var tempMembers = [];
                                var curData = table.cache["currentTableId3"];
                                for (const item of curData) {
                                    var member = {
                                        "xm": item.xm,
                                        "xl": item.xl,
                                        "gznr": item.gznr,
                                        "qsrq": item.qsrq,
                                        "jsrq": item.jsrq,
                                        "fysq": fyId
                                    };
                                    tempMembers.push(member);
                                }
                                AjaxUtil.post({
                                    url: AjaxUtil.ctx + "staTempmember/batchInsert/" + fyId,
                                    contentType: "application/json",
                                    data: JSON.stringify(tempMembers),
                                    success: function (res) {
                                        if (res.code === 0) {
                                            // Message.success(1000, res.message, function () {
                                            //
                                            // });
                                        } else {
                                            // Message.error(res.message, 1000);
                                        }
                                    },
                                    error: function (error) {
                                    }
                                });
                            }//设备使用费
                            else if ($("#fylbmc").val().indexOf("设备使用费") > -1) {
                                var devExpenses = [];
                                var curData = table.cache["currentTableId_Dev"];
                                for (const item of curData) {
                                    var expense = {
                                        "zb": fyId,
                                        "xh": item.xh,
                                        "sbmc": item.sbmc,
                                        "sbxh": item.sbxh,
                                        "dj": item.dj,
                                        "sl": item.sl,
                                        "zj": item.zj,
                                        "gzsj": item.gzsj,
                                        "syfjqdj": item.syfjqdj,
                                        "scgbydq": item.scgbydq,
                                        "lsdw": item.lsdw,
                                        "sbzkjzyxnzb": item.sbzkjzyxnzb
                                    };
                                    devExpenses.push(expense);
                                }
                                //保存设备使用费
                                AjaxUtil.post({
                                    url: AjaxUtil.ctx + "staDeviceexpenses/batchInsert/" + fyId,
                                    contentType: "application/json",
                                    data: JSON.stringify(devExpenses),
                                    success: function (res) {
                                    },
                                    error: function (error) {
                                    }
                                });
                            }//软件使用费
                            else if ($("#fylbmc").val().indexOf("软件使用费") > -1) {
                                var softwExpenses = [];
                                var curData = table.cache["currentTableId_Sw"];
                                for (const item of curData) {
                                    var expense = {
                                        "zb": fyId,
                                        "xh": item.xh,
                                        "rjmc": item.rjmc,
                                        "rjxh": item.rjxh,
                                        "dj": item.dj,
                                        "sl": item.sl,
                                        "zj": item.zj,
                                        "gzsj": item.gzsj,
                                        "syfjqdj": item.syfjqdj,
                                        "scgbydq": item.scgbydq,
                                        "lsdw": item.lsdw,
                                        "rjzyjsxnzb": item.rjzyjsxnzb
                                    };
                                    softwExpenses.push(expense);
                                }
                                //保存软件使用费
                                AjaxUtil.post({
                                    url: AjaxUtil.ctx + "staSoftwareexpenses/batchInsert/" + fyId,
                                    contentType: "application/json",
                                    data: JSON.stringify(softwExpenses),
                                    success: function (res) {
                                    },
                                    error: function (error) {
                                    }
                                });
                            }//材料费
                            else if ($("#fylbmc").val().indexOf("材料费") > -1) {
                                var matCosts = [];
                                var curData = table.cache["currentTableId_Clf"];
                                for (const item of curData) {
                                    var cost = {
                                        "zb": fyId,
                                        "xh": item.xh,
                                        "clmc": item.clmc,
                                        "gghxh": item.gghxh,
                                        "jldw": item.jldw,
                                        "dj": item.dj,
                                        "clfy": item.clfy,
                                        "jflz": item.jflz
                                    };
                                    matCosts.push(cost);
                                }
                                //保存材料费
                                AjaxUtil.post({
                                    url: AjaxUtil.ctx + "staMaterialcost/batchInsert/" + fyId,
                                    contentType: "application/json",
                                    data: JSON.stringify(matCosts),
                                    success: function (res) {
                                    },
                                    error: function (error) {
                                    }
                                });
                            }//外委研究支出费
                            else if ($("#fylbmc").val().indexOf("外委研究支出费") > -1) {
                                var outExpenses = [];
                                var curData = table.cache["currentTableId_Ww"];
                                for (const item of curData) {
                                    var expense = {
                                        "zb": fyId,
                                        "xh": item.xh,
                                        "xzyjrwmc": item.xzyjrwmc,
                                        "xzyjrwnr": item.xzyjrwnr,
                                        "xzyjrwcddw": item.xzyjrwcddw,
                                        "jflz": item.jflz
                                    };
                                    outExpenses.push(expense);
                                }
                                //保存外委研究支出费
                                AjaxUtil.post({
                                    url: AjaxUtil.ctx + "staOutexpense/batchInsert/" + fyId,
                                    contentType: "application/json",
                                    data: JSON.stringify(outExpenses),
                                    success: function (res) {
                                    },
                                    error: function (error) {
                                    }
                                });
                            } //外协测试试验与加工费
                            else if ($("#fylbmc").val().indexOf("外协测试试验与加工费") > -1) {
                                var testExpenses = [];
                                var curData = table.cache["currentTableId_Wx"];
                                for (const item of curData) {
                                    var expense = {
                                        "zb": fyId,
                                        "xh": item.xh,
                                        "wxcssyyjgnr": item.wxcssyyjgnr,
                                        "wxcshyyjgdw": item.wxcshyyjgdw,
                                        "jldw": item.jldw,
                                        "dj": item.dj,
                                        "wxcshyyjgfy": item.wxcshyyjgfy,
                                        "jflz": item.jflz
                                    };
                                    testExpenses.push(expense);
                                }
                                //保存外协测试试验与加工费
                                AjaxUtil.post({
                                    url: AjaxUtil.ctx + "staOutttesting/batchInsert/" + fyId,
                                    contentType: "application/json",
                                    data: JSON.stringify(testExpenses),
                                    success: function (res) {
                                    },
                                    error: function (error) {
                                    }
                                });
                            }

                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        });
                    } else {
                        Message.error(res.message, 1000);
                    }
                },
                error: function (error) {
                    layer.close(index);
                }
            });
            return false;
        });

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

    /**
     *  扁平数据转树结构
     * @returns {[]}
     * @param data
     * @param firstPid
     */
    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);
            }
        }
    }

    function setTravelExpense(expense) {
        travelExpense = expense;
    }

    function getTravelExpense() {
        return travelExpense;
    }

    function setUpdateFlag() {
        updateflag = 1;
    }

    function setMember(member) {
        tempMember = member;
    }

    function getMember() {
        return tempMember;
    }

    function setDevExpense(expense) {
        devExpense = expense;
    }

    function getDevExpense() {
        return devExpense;
    }

    function setSoftExpense(expense) {
        softExpense = expense;
    }

    function getSoftExpense() {
        return softExpense;
    }

    function setMatCost(cost) {
        materialCost = cost;
    }

    function getMatCost() {
        return materialCost;
    }

    function setOutExpense(expense) {
        outExpense = expense;
    }

    function getOutExpense() {
        return outExpense;
    }

    function setOutTesting(expense) {
        outTesting = expense;
    }

    function getOutTesting() {
        return outTesting;
    }
</script>
</body>
</html>