<!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>
            <li>子课题</li>
            <li>内容</li>
            <li>项目预算</li>
            <li>出资方案</li>
            <li>说明</li>
            <li>联系方式</li>
            <li>附件</li>
        </ul>
        <div class="layui-tab-content">
            <!--基本信息开始-->
            <div class="layui-tab-item layui-show">
                <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 required" style="width: 10%">中文名称</label>
                            <div class="layui-input-inline" style="width: 35%">
                                <input type="hidden" id="id" name="id">
                                <input type="text" id="zwmc" name="zwmc" lay-verify="required" lay-reqtext="中文名称不能为空" maxlength="30"
                                       placeholder="请录入项目名称..." autocomplete="off" class="layui-input">
                                <div style="color: red">注：项目名称（中文）不能超过30字（含字符） </div>
                            </div>
                            <label class="layui-form-label" style="width: 15%">学科分类1</label>
                            <div class="layui-input-inline" style="width: 25%">
                                <select name="xkfl1" id="xkfl1" lay-filter="xkfl">
                                    <option value="">--请选择--</option>
                                    <option value="-1">[浏览]</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 10%">英文名称</label>
                            <div class="layui-input-inline" style="width: 35%">
                                <input type="text" id="ywmc" name="ywmc" placeholder="请录入项目(英文)名称..." maxlength="30"
                                       autocomplete="off" class="layui-input">
                                <div style="color: red">注：项目名称（英文）不能超过30字（含字符）</div>
                            </div>
                            <label class="layui-form-label" style="width: 15%">学科分类2</label>
                            <div class="layui-input-inline" style="width: 25%">
                                <select name="xkfl2" id="xkfl2" lay-filter="xkfl">
                                    <option value="">--请选择--</option>
                                    <option value="-1">[浏览]</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label required" style="width: 10%">ERP编号</label>
                            <div class="layui-input-inline" style="width: 35%">
                                <input type="text" id="erpbh" name="erpbh" autocomplete="off" class="layui-input"
                                       lay-verify="required" lay-reqtext="ERP编号不能为空" placeholder="请录入ERP编号..." maxlength="12">
                            </div>
                            <label class="layui-form-label" style="width: 15%">学科分类3</label>
                            <div class="layui-input-inline" style="width: 25%">
                                <select name="xkfl3" id="xkfl3" lay-filter="xkfl">
                                    <option value="">--请选择--</option>
                                    <option value="-1">[浏览]</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label required" style="width: 10%">项目类型</label>
                            <div class="layui-input-inline" style="width: 35%">
                                <select name="xmlx" id="xmlx" lay-filter="xmlx" lay-verify="required"
                                        lay-reqtext="项目类型不能为空">
                                    <option value="">-- 请选择 --</option>
                                    <option th:each="item:${xmlxList}" th:text="${item.name}"
                                            th:value="${item.code}"></option>
                                </select>
                                <tip>此项只能新建时修改</tip>
                            </div>
                            <label class="layui-form-label" style="width: 15%">所属国民经济行业</label>
                            <div class="layui-input-inline" style="width: 25%">
                                <select name="ssgmjjhy" id="ssgmjjhy" lay-filter="gmjjhy">
                                    <option value="">--请选择--</option>
                                    <option value="-1">[浏览]</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 10%">可研报告</label>
                            <div class="layui-input-inline" style="width: 35%">
                                <input type="hidden" id="bm" name="bm" class="layui-input">
                                <input type="hidden" id="kybgmc" name="kybgmc" class="layui-input">
                                <select name="kybg" id="kybg" lay-filter="kybg">
                                    <option value="">--请选择--</option>
                                    <option value="-1">[浏览]</option>
                                </select>
                            </div>
                            <label class="layui-form-label" style="width: 15%">是否国家秘密技术项目</label>
                            <div class="layui-input-inline">
                                <input type="checkbox" name="sfgjmmjsxm" lay-skin="primary">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 10%">费用来源</label>
                            <div class="layui-input-inline" style="width: 35%">
                                <input type="text" id="fyly" name="fyly" autocomplete="off" class="layui-input" placeholder="请录入费用来源...">
                            </div>
                        </div>

                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label required" style="width: 10%">项目起止时间</label>
                            <div class="layui-form-item layui-inline" style="width: auto">
                                <div class="layui-input-inline" style="width: 40%">
                                    <input type="text" name="qs" id="qs" lay-verify="required|date" placeholder="开始日期"
                                           lay-reqtext="开始日期不能为空" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid">-</div>
                                <div class="layui-input-inline" style="width: 40%">
                                    <input type="text" name="wc" id="wc" lay-verify="required|date" placeholder="结束日期"
                                           lay-reqtext="结束日期不能为空" autocomplete="off" class="layui-input">
                                    <div style="color: red">请录入结束时间...</div>
                                </div>
                            </div>
                        </div>

                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 10%">项目总预算(万)</label>
                            <div class="layui-input-inline" style="width: 35%">
                                <input type="text" id="rwsys2" name="rwsys2"
                                       class="layui-input" th:value="${rwsys}" readonly placeholder="自动带入，无需填写！">
                                <div  style="color: red">
                                    注:此处项目总预算由子课题中单位分工经费累加所得, 并且请先填写下方主要完成人和主要完成单位!!
                                </div>
                            </div>
                        </div>
                        <!--Tab列表-->
                        <div class="layui-tab layui-tab-brief" style="padding-left: 30px; padding-right: 30px">
                            <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">
                                    <div class="layuimini-container">
                                        <div class="layui-btn-group" style="margin-bottom: 0.5%">
                                            <button type="button"
                                                    class="layui-btn  layui-btn-primary layui-btn-sm upload"
                                                    lay-filter="subImport1" lay-data="{fileType:'memberFile'}"><i
                                                    class="layui-icon"></i>导入
                                            </button>
                                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                                    lay-filter="subAdd1"><i class="layui-icon"></i>新建
                                            </button>
                                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                                    lay-filter="subEdit1"><i class="layui-icon"></i>编辑
                                            </button>
                                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                                    lay-filter="subView1"><i class="layui-icon">&#xe63c;</i>查看
                                            </button>
                                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                                    lay-filter="subDelete1"><i class="layui-icon"></i>删除
                                            </button>
                                            <a class="layui-btn layui-btn-primary layui-btn-sm "
                                               th:href="${ReportRYTemplate}">
                                                <i class="layui-icon layui-icon-export" style="font-size: 10px;"></i>人员模板
                                            </a>
                                        </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-tab-item">
                                    <div class="layuimini-container">
                                        <div class="layui-btn-group" style="margin-bottom: 0.5%">
                                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                                    lay-filter="subAdd2"><i class="layui-icon"></i>新建
                                            </button>
                                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                                    lay-filter="subEdit2"><i class="layui-icon"></i>编辑
                                            </button>
                                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                                    lay-filter="subView2"><i class="layui-icon">&#xe63c;</i>查看
                                            </button>
                                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                                    lay-filter="subDelete2"><i class="layui-icon"></i>删除
                                            </button>
                                        </div>
                                        <table class="layui-hide" id="currentTableId2" name="currentTableId2"
                                               lay-filter="currentTableFilter2"
                                               style="padding-bottom: 0px;margin-bottom: 0px"></table>
                                    </div>
                                </div>
                                <!--主要完成单位结束-->
                            </div>
                        </div>

                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 10%">总人数</label>
                            <div class="layui-input-inline" style="width: 18%">
                                <input type="text" id="zrs" name="zrs" class="layui-input" placeholder='无需操作，自动汇总!' readonly>
                            </div>
                            <label class="layui-form-label" style="width: 10%">高级职称</label>
                            <div class="layui-input-inline" style="width: 18%">
                                <input type="text" id="gjzc" name="gjzc" class="layui-input" placeholder='无需操作，自动汇总!' readonly>
                            </div>
                            <label class="layui-form-label" style="width: 10% ">中级职称</label>
                            <div class="layui-input-inline" style="width: 18%">
                                <input type="text" id="zjzc" name="zjzc" class="layui-input" placeholder='无需操作，自动汇总!' readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 10%">所属部门</label>
                            <div class="layui-input-inline" style="width: 18%">
                                <input type="hidden" id="ssbm" name="ssbm" class="layui-input"
                                       th:value="${userInfo.deptId}">
                                <input type="text" id="ssbmmc" name="ssbmmc" class="layui-input"
                                       th:value="${userInfo.deptName}" readonly>
                            </div>
                            <label class="layui-form-label" style="width: 10%;">初级职称</label>
                            <div class="layui-input-inline" style="width: 18%">
                                <input type="text" id="cjzc" name="cjzc" class="layui-input" placeholder='无需操作，自动汇总!' readonly>
                            </div>
                            <label class="layui-form-label" style="width: 10%">研究生</label>
                            <div class="layui-input-inline" style="width: 18%">
                                <input type="text" id="yjs" name="yjs" class="layui-input" placeholder='无需操作，自动汇总!' readonly>
                            </div>
                        </div>
<!--                        <div class="layui-form-item">
                            <label class="layui-form-label" style="width: 90px">所属部门</label>
                            <div class="layui-input-inline" style="width: 600px">
                                <input type="hidden" id="ssbm" name="ssbm" class="layui-input"
                                       th:value="${userInfo.deptId}">
                                <input type="text" id="ssbmmc" name="ssbmmc" class="layui-input"
                                       th:value="${userInfo.deptName}" readonly>
                            </div>
                        </div>-->
                        <div class="layui-form-item" style="width: 100%">
                            <label class="layui-form-label" style="width: 10%">电科院负责人</label>
                            <div class="layui-input-inline" style="width: 18%">
                                <input type="hidden" id="dkyfzr" name="dkyfzr" class="layui-input">
                                <input type="text" id="dkyfzrxm" name="dkyfzrxm" placeholder="请选择..." autocomplete="off"
                                       class="layui-input" lay-verify="required" lay-reqtext="电科院负责人不能为空" readonly>
                                <div style="color: red">注:可多选</div>
                            </div>
                        </div>

                        <!-- 右侧悬浮按钮 -->
                        <div class="right-bottom-btn">
                            <button type="button" class="layui-btn" lay-submit lay-filter="saveBtn1">
                                <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="min-height: 540px">
                <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: 10%">填写说明</label>
                            <div class="layui-input-inline" style="width: 70%">
                                <textarea id="txsm" name="txsm" class="layui-textarea"
                                          style="width: 100%;height: 510px" placeholder="请在此处填写说明..."></textarea>
                            </div>
                        </div>

                        <!-- 右侧悬浮按钮 -->
                        <div class="right-bottom-btn">
                            <button type="button" class="layui-btn" lay-filter="saveBtn2">
                                <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="min-height: 565px; padding-left: 30px; padding-right: 30px">
                <form class="layui-form" action="" lay-filter="formDemo">
                    <div class="layui-form layuimini-form" style="padding-bottom: 100px">
                        <div style="color:  red"> 请新建子课题...</div>
                        <div class="layui-btn-group" style="margin-bottom: 0.5%">
                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                    lay-filter="btnAdd3"><i class="layui-icon"></i>新建
                            </button>
                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                    lay-filter="btnEdit3"><i class="layui-icon"></i>编辑
                            </button>
                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                    lay-filter="btnView3"><i class="layui-icon">&#xe63c;</i>查看
                            </button>
                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                    lay-filter="btnDelete3"><i class="layui-icon"></i>删除
                            </button>
                        </div>
                        <table class="layui-hide" id="currentTableId3" lay-filter="currentTableFilter3"></table>
                        <div style="color: red">注意：请在此处填写信息，填写完成后，项目总预算会自动同步更新！</div>
                        <script type="text/html" id="currentTableBar3">
                            <a class="layui-btn layui-btn-xs layui-btn-warm data-count-view" lay-event="view">
                                <i class="layui-icon layui-icon-set" style="font-size: 10px;"></i>查看
                            </a>
                            <a class="layui-btn layui-btn-xs data-count-update" lay-event="update">
                                <i class="layui-icon layui-icon-edit" style="font-size: 10px;"></i>编辑
                            </a>
                            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delFlag">
                                <i class="layui-icon layui-icon-delete" style="font-size: 10px;"></i>删除
                            </a>
                        </script>

                        <!-- 右侧悬浮按钮 -->
                        <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 class="layui-tab-item" style="min-height: 540px">
                <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:10%">研究内容及<br>考核指标</label>
                            <div class="layui-input-inline" style="width: 70%">
                                <textarea id="yjnrjkhzb" name="yjnrjkhzb" class="layui-textarea" placeholder="请在此处填写研究内容和考试指标..."
                                          style="width: 100%;height: 510px"></textarea>
                            </div>
                        </div>

                        <!-- 右侧悬浮按钮 -->
                        <div class="right-bottom-btn">
                            <button type="button" class="layui-btn" lay-filter="saveBtn4">
                                <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="min-height: 555px; padding-left: 30px; padding-right: 30px">
                <form class="layui-form" action="" lay-filter="formDemo">
                    <div class="layui-form layuimini-form" style="padding-bottom: 100px">
                        <div class="layui-form-item" style="margin-bottom: -10px">
                            <div class="layui-inline">
                                <label class="layui-form-label"
                                       style="width: fit-content; margin-bottom: -10px">单位：万元</label>
                                <label class="layui-form-label" style="width: 170px"></label>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width: 70px; margin-left: -10px">项目总预算</label>
                                <div class="layui-input-inline" style="width: 100px">
                                    <input type="text" id="rwsys" name="rwsys" class="layui-input" th:value="${rwsys}"
                                           readonly>
                                </div>
                            </div>
                        </div>
                        <table class="layui-hide" id="currentTableId5" lay-filter="currentTableFilter5"></table>

                        <!-- 右侧悬浮按钮 -->
                        <div class="right-bottom-btn">
                            <button type="button" class="layui-btn" lay-filter="saveBtn5">
                                <input type="hidden" id="ysje_cz" name="ysje_cz" class="layui-input">
                                <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="min-height: 565px; padding-left: 30px; padding-right: 30px">
                <form class="layui-form" action="" lay-filter="formDemo">
                    <div class="layuimini-form" style="padding-bottom: 100px">
                        <div class="layui-btn-group" style="margin-bottom: 0.5%">
                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                    lay-filter="btnAdd6"><i class="layui-icon"></i>新建
                            </button>
                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                    lay-filter="btnEdit6"><i class="layui-icon"></i>编辑
                            </button>
                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                    lay-filter="btnView6"><i class="layui-icon">&#xe63c;</i>查看
                            </button>
                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                    lay-filter="btnDelete6"><i class="layui-icon"></i>删除
                            </button>
                        </div>
                        <table class="layui-hide" id="currentTableId6" lay-filter="currentTableFilter6"></table>
                        <script type="text/html" id="currentTableBar6">
                            <a class="layui-btn layui-btn-xs layui-btn-warm data-count-view" lay-event="view">
                                <i class="layui-icon layui-icon-set" style="font-size: 10px;"></i>查看
                            </a>
                            <a class="layui-btn layui-btn-xs data-count-update" lay-event="update">
                                <i class="layui-icon layui-icon-edit" style="font-size: 10px;"></i>编辑
                            </a>
                            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delFlag">
                                <i class="layui-icon layui-icon-delete" style="font-size: 10px;"></i>删除
                            </a>
                        </script>

                        <!-- 右侧悬浮按钮 -->
                        <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 class="layui-tab-item" style="min-height: 540px">
                <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: 10%">有关问题说明</label>
                            <div class="layui-input-inline" style="width: 70%">
                                <textarea id="ygwtsm" name="ygwtsm" class="layui-textarea" placeholder="请填入说明..."
                                          style="width: 100%;height: 510px"></textarea>
                            </div>
                        </div>

                        <!-- 右侧悬浮按钮 -->
                        <div class="right-bottom-btn">
                            <button type="button" class="layui-btn" lay-filter="saveBtn7">
                                <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="min-height: 565px; padding-left: 30px; padding-right: 30px">
                <form class="layui-form" action="" lay-filter="formDemo">
                    <div class="layuimini-form" style="padding-bottom: 100px">
                        <div class="layui-btn-group" style="margin-bottom:0.5%">
                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                    lay-filter="btnAdd8"><i class="layui-icon"></i>新建
                            </button>
                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                    lay-filter="btnEdit8"><i class="layui-icon"></i>编辑
                            </button>
                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                    lay-filter="btnView8"><i class="layui-icon">&#xe63c;</i>查看
                            </button>
                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                    lay-filter="btnDelete8"><i class="layui-icon"></i>删除
                            </button>
                        </div>
                        <table class="layui-hide" id="currentTableId8" lay-filter="currentTableFilter8"></table>

                        <!-- 右侧悬浮按钮 -->
                        <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 class="layui-tab-item" style="min-height: 555px; padding-left: 30px; padding-right: 30px">
                <form class="layui-form" action="" lay-filter="formDemo">
                    <div class="layuimini-form" style="padding-bottom: 100px">
                        <input type="hidden" id="fj" name="fj" class="layui-input">
                        <div class="layui-btn-group" style="margin-bottom: 0.5%">
                            <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm upload"
                                    lay-filter="upLoad" lay-data="{fileType:'project'}"><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>
                            <a class="layui-btn layui-btn-primary layui-btn-sm " href="/fileDownload/download">
                                <i class="layui-icon layui-icon-export" style="font-size: 10px;"></i>模板下载
                            </a>
                        </div>
                        <table class="layui-hide" id="currentTableId9" name="currentTableId9"
                               lay-filter="currentTableFilter9" style="padding-top: 0px;margin-top: 0px"></table>

                        <!-- 右侧悬浮按钮 -->
                        <div class="right-bottom-btn">
                            <button type="button" class="layui-btn" lay-submit lay-filter="saveBtn9">
                                <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>
    </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-v2.6.3/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 ObjId = '0';
    var ObjName = '';
    var updateflag = 0;
    var prjMember = [];
    var prjCompany = [];
    var subTopic = [];
    var budgetCols = [];
    var dataBudget = new Array();
    layui.use(['form', 'table', 'treeTable', 'layCascader', 'tableSelect', 'upload'], function () {
        var form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            layer = layui.layer,
            upload = layui.upload,
            treeTable = layui.treeTable,
            tableSelect = layui.tableSelect,
            layCascader = layui.layCascader;
        var cascader;
        var initFlag = 0;
        var xmId = -1;

        //日期
        laydate.render({
            elem: '#qs',
            value: new Date(),
            done:function (value,date,endDate) {
                setTimeout(function () {
                    console.log('进来了');
                    let qs= $('#qs').val();
                    let wc= $('#wc').val();
                    let qss = new Date(qs);
                    let wcs = new Date(wc);
                    let timeDiff = wcs.getTime() - qss.getTime();
                    let threeMonthsInMillis = 3 * 30 * 24 * 60 * 60 * 1000;
                    if (wc < qs){
                        layer.msg('完成时间不能早于项目开始时间！',{icon:2});
                        $('#wc').val('');
                        return;
                    }else if (qs == wc){
                        layer.msg('项目周期不能是同一天！',{icon:2});
                        $('#qs').val('');
                        return;
                    }else if (timeDiff< threeMonthsInMillis){
                        layer.msg('项目周期小于三个月',{icon:2},function () {
                            $('#wc').val('');
                            return;
                        });
                    }
                },800);
            }

        });
        laydate.render({
            elem: '#wc',
            done:function (value,date,endDate) {
                setTimeout(function () {
                    console.log('进来了wc')
                    let qs= $('#qs').val();
                    let wc= $('#wc').val();
                    console.log('qs:'+qs);
                    console.log('wc:'+wc);
                    let qss = new Date(qs);
                    let wcs = new Date(wc);
                    let timeDiff = wcs.getTime() - qss.getTime();
                    let threeMonthsInMillis = 3 * 30 * 24 * 60 * 60 * 1000;
                    if (wc < qs){
                        layer.msg('完成时间不能早于项目开始时间！',{icon:2});
                        $('#qs').val('');
                        return;
                    }else if (qs == wc){
                        layer.msg('项目周期不能是同一天！',{icon:2});
                        $('#qs').val('');
                        return;
                    }else if (timeDiff< threeMonthsInMillis){
                        layer.msg('项目周期小于三个月',{icon:2},function () {
                            $('#wc').val('');
                            return;
                        });
                    }
                },800);
            }
        });

        //监听学科分类
        form.on('select(xkfl)', function (data) {
            if (data.value == "-1") {
                layer.open({
                    title: '浏览学科分类',
                    type: 2,
                    shade: 0.3,
                    maxmin: true,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjProject/xkfl',
                    end: function (index) {
                        if (ObjId != '0') {
                            $("#" + data.elem.id).append("<option value=" + ObjId + " selected>" + ObjName + "</option>");

                            ObjId = '0';
                            ObjName = '';
                        } else {
                            $("#" + data.elem.id).val(0);
                        }
                        form.render('select');
                    }
                });
            }
            return false;
        });
        //监听国民经济行业
        form.on('select(gmjjhy)', function (data) {
            if (data.value == "-1") {
                layer.open({
                    title: '浏览国民经济行业',
                    type: 2,
                    shade: 0.3,
                    maxmin: true,
                    area: [layerwidth + 'px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjProject/gmjjhy',
                    end: function (index) {
                        if (ObjId != '0') {
                            $("#" + data.elem.id).append("<option value=" + ObjId + " selected>" + ObjName + "</option>");

                            ObjId = '0';
                            ObjName = '';
                        } else {
                            $("#" + data.elem.id).val("");
                        }
                        form.render('select');
                    }
                });
            }
            return false;
        });

        //监听可研报告
        form.on('select(kybg)', function (data) {
            if ($("#xmlx").val() == undefined || $("#xmlx").val() == '') {
                Message.error("请先选择项目类型", 1000);
                return false;
            }

            var len = $("#kybg")[0].length;
            while (len > 2)
                $("#kybg")[0].options[--len].remove();
            if (data.value == "") {
                $("#kybg").val(0);
                $("#bm").val('');
                $("#kybgmc").val('');
                form.render();
            }

            if (data.value == "-1") {
                parent.layer.open({
                    title: '浏览可研报告',
                    type: 2,
                    shade: 0.3,
                    maxmin: true,
                    area: ['1200px', '750px'],
                    content: AjaxUtil.ctx + 'prjProject/init_kybg?xmlx=' + $("#xmlx").val(),
                    end: function (obj) {
                        var kybg = localStorage.getItem("kybg");
                        var updateflag = localStorage.getItem("updateflag");
                        if (updateflag == "1") {
                            var kybgmc = localStorage.getItem("kybgmc");
                            $("#kybg").append("<option value=" + kybg + " selected>" + kybgmc + "</option>");
                            $("#bm").val(kybg);
                            $("#kybgmc").val(kybgmc);
                        } else {
                            $("#kybg").val(0);
                            $("#bm").val('');
                            $("#kybgmc").val('');
                        }
                        form.render();
                    }
                });
            }
            return false;
        });

        // 用于存放表格数据
        var dataMember = new Array();
        //主要完成人
        var currTable1 = table.render({
            elem: '#currentTableId1',
            data: dataMember,
            cols: [
                [
                    {type: "checkbox"},
                    {type: 'numbers', align: 'center',title: '序号',width: '10%'},
                    {field: 'ryxm', width: '10%', title: '人员', align: 'left'},
                    {field: 'xmjsmc', width: '15%', title: '项目角色', align: 'left'},
                    {field: 'bxmfg', width: '20%', title: '本项目分工', align: 'left'},
                    {field: 'trgzzys', width: '15%', title: '投入工作总月数', align: 'center'},
                   /* {field: 'sxbh', width: '10%', title: '顺序编号', align: 'center'},*/
                    {field: 'dwmc', title: '单位', align: 'left',width: '20%'}
                ]
            ],
            autoSort: true,
            limit: Number.MAX_VALUE,
            initSort: {
                field: 'sxbh', //排序字段
                type: 'asc' //排序方式:desc 降序,asc 升序
            }
        });
        // 监听新建按钮(主要完成人）
        $("button[lay-filter='subAdd1']").click(function () {
            layer.open({
                title: '新建项目人员',
                type: 2,
                maxmin: true,
                shade: 0.2,
                area: ['820px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'prjMember/forAdd',
                end: function (index) {
                    if (updateflag == 1) {
                        updateflag = 0;
                        var oldData = table.cache["currentTableId1"];
                        for (let item of oldData) {
                            if (item.ry === prjMember.ry) {
                                Message.warning("该人员已在主要完成人列表中，如需修改，请选中后编辑！", 2000);
                                return;
                            }
                        }

                        if (prjMember.dw == undefined)
                            prjMember.dw = "";
                        if (prjMember.dwlx == undefined)
                            prjMember.dwlx = "";
                        if (prjMember.zc == undefined)
                            prjMember.zc = "";
                        if (prjMember.xl == undefined)
                            prjMember.xl = "";

                        var item = {
                            "ry": prjMember.ry,
                            "ryxm": prjMember.ryxm,
                            "dw": prjMember.dw,
                            "dwmc": prjMember.dwmc,
                            "dwlx": prjMember.dwlx,
                            "dwlxmc": prjMember.dwlxmc,
                            "zc": prjMember.zc,
                            "zcmc": prjMember.zcmc,
                            "xl": prjMember.xl,
                            "xlmc": prjMember.xlmc,
                            "xmjs": prjMember.xmjs,
                            "xmjsmc": prjMember.xmjsmc,
                            "bxmfg": prjMember.bxmfg,
                            "sxbh": prjMember.sxbh,
                            "trgzzys": prjMember.trgzzys
                        };
                        //刷新表格
                        oldData.push(item);
                        table.reload('currentTableId1', {
                            data: oldData
                        });

                        var gjzc = 0, zjzc = 0, cjzc = 0, yjs = 0;
                        for (let item of oldData) {
                            if (item.zc.substring(2, 3) == 1 || item.zc.substring(2, 3) == 2)
                                gjzc++;
                            else if (item.zc.substring(2, 3) == 2)
                                zjzc++;
                            else if (item.zc.substring(2, 3) == 3)
                                cjzc++;
                            if (item.xlmc.indexOf("研究生") > -1)
                                yjs++;
                        }
                        //更新统计信息
                        $("#zrs").val(oldData.length);
                        $("#gjzc").val(gjzc);
                        $("#zjzc").val(zjzc);
                        $("#cjzc").val(cjzc);
                        $("#yjs").val(yjs);
                    }
                }
            });
        });
        // 监听编辑按钮(主要完成人）
        $("button[lay-filter='subEdit1']").click(function () {
            var members = table.cache["currentTableId1"];
            if (members.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 {
                prjMember = {
                    "ry": data[0].ry,
                    "ryxm": data[0].ryxm,
                    "dw": data[0].dw,
                    "dwmc": data[0].dwmc,
                    "dwlx": data[0].dwlx,
                    "dwlxmc": data[0].dwlxmc,
                    "zc": data[0].zc,
                    "zcmc": data[0].zcmc,
                    "xl": data[0].xl,
                    "xlmc": data[0].xlmc,
                    "xmjs": data[0].xmjs,
                    "xmjsmc": data[0].xmjsmc,
                    "bxmfg": data[0].bxmfg,
                    "sxbh": data[0].sxbh,
                    "trgzzys": data[0].trgzzys
                };

                layer.open({
                    title: '编辑项目人员',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['820px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjMember/forUpdate',
                    end: function (index) {
                        if (updateflag == 1) {
                            updateflag = 0;

                            var currMember = {
                                "ry": prjMember.ry,
                                "ryxm": prjMember.ryxm,
                                "dw": prjMember.dw,
                                "dwmc": prjMember.dwmc,
                                "dwlx": prjMember.dwlx,
                                "dwlxmc": prjMember.dwlxmc,
                                "zc": prjMember.zc,
                                "zcmc": prjMember.zcmc,
                                "xl": prjMember.xl,
                                "xlmc": prjMember.xlmc,
                                "xmjs": prjMember.xmjs,
                                "xmjsmc": prjMember.xmjsmc,
                                "bxmfg": prjMember.bxmfg,
                                "sxbh": prjMember.sxbh,
                                "trgzzys": prjMember.trgzzys
                            };

                            var oldData = table.cache["currentTableId1"];
                            for (var i = 0; i < oldData.length; i++) {
                                var item = oldData[i];
                                if (item.LAY_CHECKED) {//条件：选中
                                    // oldData.splice(i, 1);//移除后后造成数组下标索引发生变化，所以下面需要i--
                                    oldData[i] = currMember;
                                    break;
                                }
                            }

                            var currData = oldData;
                            // currData.push(currMember);
                            table.reload('currentTableId1', {
                                data: currData
                            });
                        }
                    }
                });
            }
        });
        // 监听查看按钮(主要完成人）
        $("button[lay-filter='subView1']").click(function () {
            var members = table.cache["currentTableId1"];
            if (members.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 {
                layer.open({
                    title: '浏览项目人员',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['820px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjMember/forView',
                    end: function (index) {

                    }
                });
            }
        });
        // 监听删除按钮(主要完成人）
        $("button[lay-filter='subDelete1']").click(function () {
            var members = table.cache["currentTableId1"];
            if (members.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId1')
                , data = checkStatus.data;
            if (data == null || data.length == 0) {
                Message.warning("请选择要删除的项目人员！", 1000);
                return;
            }

            var gjzc = 0, zjzc = 0, cjzc = 0, yjs = 0;
            var oldData = table.cache["currentTableId1"];
            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
            });
            for (let item of currData) {
                if (item.zc.substring(2, 3) == 1 || item.zc.substring(2, 3) == 2)
                    gjzc++;
                else if (item.zc.substring(2, 3) == 2)
                    zjzc++;
                else if (item.zc.substring(2, 3) == 3)
                    cjzc++;
                if (item.xlmc.indexOf("研究生") > -1)
                    yjs++;
            }
            //更新统计信息
            $("#zrs").val(currData.length);
            $("#gjzc").val(gjzc);
            $("#zjzc").val(zjzc);
            $("#cjzc").val(cjzc);
            $("#yjs").val(yjs);
        });

        var dataCompany = new Array();
        //主要完成单位
        var currTable2 = table.render({
            elem: '#currentTableId2',
            data: dataCompany,
            cols: [
                [
                    {type: "checkbox"},
                    {type: 'numbers', align: 'center',title: '序号',width: '10%'},
                    {field: 'dwmc', width: '30%', title: '单位', align: 'left'},
                    {field: 'dwqc', width: '30%', title: '单位全称', align: 'left'},
                    /*{field: 'sxbh', width: '10%', title: '顺序编号', align: 'center'},*/
                    {field: 'lxrxm', width: '15%', title: '联系人', align: 'left'},
                    {field: 'sfzyzfmc', width: '15%', title: '是否转移支付', align: 'center'}
                ]
            ]
        });
        // 监听新建按钮(主要完成单位）
        $("button[lay-filter='subAdd2']").click(function () {
            layer.open({
                title: '新建项目单位',
                type: 2,
                maxmin: true,
                shade: 0.2,
                area: ['820px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'prjCompletecompany/forAdd',
                end: function (index) {
                    if (updateflag == 1) {
                        updateflag = 0;
                        var oldData = table.cache["currentTableId2"];
                        for (let item of oldData) {
                            if (item.dw === prjCompany.dw) {
                                Message.warning("该单位已在主要完成单位列表中，如需修改，请选中后编辑！", 2000);
                                return;
                            }
                        }

                        if (prjCompany.sfzyzf == undefined)
                            prjCompany.sfzyzf = 0;
                        else
                            prjCompany.sfzyzf = 1;

                        var sfzyzfmc = "否";
                        if (prjCompany.sfzyzf == 1)
                            sfzyzfmc = "是";

                        var item = {
                            "dw": prjCompany.dw,
                            "dwmc": prjCompany.dwmc,
                            "dwqc": prjCompany.dwqc,
                            "sxbh": prjCompany.sxbh,
                            "lxr": prjCompany.lxr,
                            "lxrxm": prjCompany.lxrxm,
                            "sfzyzf": prjCompany.sfzyzf,
                            "sfzyzfmc": sfzyzfmc
                        };
                        //刷新表格
                        oldData.push(item);
                        table.reload('currentTableId2', {
                            data: oldData
                        });
                    }
                }
            });
        });
        // 监听编辑按钮(主要完成单位）
        $("button[lay-filter='subEdit2']").click(function () {
            var companys = table.cache["currentTableId2"];
            if (companys.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId2')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要编辑的单位！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行编辑操作！", 1500);
            } else {
                prjCompany = {
                    "dw": data[0].dw,
                    "dwmc": data[0].dwmc,
                    "dwqc": data[0].dwqc,
                    "sxbh": data[0].sxbh,
                    "lxr": data[0].lxr,
                    "lxrxm": data[0].lxrxm,
                    "sfzyzf": data[0].sfzyzf
                };

                layer.open({
                    title: '编辑项目单位',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['820px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjCompletecompany/forUpdate',
                    end: function (index) {
                        if (updateflag == 1) {
                            updateflag = 0;
                            if (prjCompany.sfzyzf == undefined)
                                prjCompany.sfzyzf = 0;
                            else
                                prjCompany.sfzyzf = 1;

                            var sfzyzfmc = "否";
                            if (prjCompany.sfzyzf == 1)
                                sfzyzfmc = "是";

                            var currCompany = {
                                "dw": prjCompany.dw,
                                "dwmc": prjCompany.dwmc,
                                "dwqc": prjCompany.dwqc,
                                "sxbh": prjCompany.sxbh,
                                "lxr": prjCompany.lxr,
                                "lxrxm": prjCompany.lxrxm,
                                "sfzyzf": prjCompany.sfzyzf,
                                "sfzyzfmc": sfzyzfmc
                            };

                            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--
                                    oldData[i] = currCompany;
                                    break;
                                }
                            }

                            //刷新表格
                            var currData = oldData;
                            // currData.push(currCompany);
                            table.reload('currentTableId2', {
                                data: currData
                            });
                        }
                    }
                });
            }
        });
        // 监听查看按钮(主要完成单位）
        $("button[lay-filter='subView2']").click(function () {
            var companys = table.cache["currentTableId2"];
            if (companys.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId2')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要浏览的单位！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行浏览！", 1500);
            } else {
                prjCompany = {
                    "dw": data[0].dw,
                    "dwmc": data[0].dwmc,
                    "dwqc": data[0].dwqc,
                    "sxbh": data[0].sxbh,
                    "lxr": data[0].lxr,
                    "lxrxm": data[0].lxrxm,
                    "sfzyzf": data[0].sfzyzf
                };

                layer.open({
                    title: '浏览完成单位',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['820px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjCompletecompany/forView'
                });
            }
        });
        // 监听删除按钮(主要完成单位）
        $("button[lay-filter='subDelete2']").click(function () {
            var companys = table.cache["currentTableId2"];
            if (companys.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) {//条件：选中
                    if (i != oldData.length - 1) {
                        Message.warning("完成单位和项目预算关联，只能从最后一项删除！", 2000);
                        return;
                    }
                    oldData.splice(i, 1);//移除后后造成数组下标索引发生变化，所以下面需要i--
                    i--;
                }
            }

            var currData = oldData;
            table.reload('currentTableId2', {
                data: currData
            });
        });

        // //所属部门
        // var index = layer.load(0, {shade: 0.1});
        // AjaxUtil.get({
        //     url: AjaxUtil.ctx + 'deptinfo/list',
        //     success: function (res) {
        //         var datalist = [];
        //         for (let item of res.data) {
        //             item.value = item.deptId;
        //             item.label = item.deptName;
        //             datalist.push(item);
        //         }
        //         // 扁平数据转树
        //         var options = arrayToTree(datalist, "0");
        //
        //         // 初始化cascader实例
        //         cascader = layCascader({
        //             elem: '#ssbmmc',
        //             clearable: true,
        //             showAllLevels: false, // 配置仅显示最后一级
        //             props: {
        //                 checkStrictly: true // 配置选择任意一级选项
        //             },
        //             options: options
        //         });
        //
        //         // 监听cascader变化
        //         cascader.changeEvent(function (value, node) {
        //             // 主动关闭面板
        //             cascader.close();
        //             $("#ssbm").val(value);
        //             $("#ssbmmc").val(node.data.label);
        //         });
        //         layer.close(index);
        //     },
        //     error: function (error) {
        //         Message.error('获取部门信息失败！', 1000);
        //         layer.close(index);
        //     }
        // });
        //电科院负责人
        tableSelect.render({
            elem: '#dkyfzrxm',
            checkedKey: 'id',
            searchKey: 'xm',
            searchPlaceholder: '搜索姓名',
            table: {
                url: AjaxUtil.ctx + 'basePerson/rylist',
                cols: [
                    [
                        {type: "checkbox", fixed: 'left',title: '😊'},
                        {type: 'numbers', align: 'center',title: '序号',width: '15%'},
                        {field: 'xm', width: '15%', title: '姓名', align: 'left'},
                        {field: 'dwmc', title: '公司/单位', align: 'left',width: '60%'}
                    ]
                ]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                var NEWJSON1 = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.xm);
                    NEWJSON1.push(item.id);
                });
                elem.val(NEWJSON.join(","));
                $("#dkyfzr").val(NEWJSON1.join(","));
            }
        });

        // 监听确认按钮（基本信息）
        form.on('submit(saveBtn1)', function (data) {
            var qsrq = document.getElementById('qs').value;
            var jsrq = document.getElementById('wc').value;
            var sd = new Date(qsrq);
            var ed = new Date(jsrq);
            if (sd > ed) {
                Message.warning("起始日期必须小于结束日期", 1500);
                return;
            }
            var url = AjaxUtil.ctx + "prjProject/doUpdateNormal";
            if (xmId == -1)
                url = AjaxUtil.ctx + "prjProject/doAddNormal";
            //基本信息
            AjaxUtil.post({
                url: url,
                data: data.field,
                success: function (res) {
                    if (res.code === 0) {
                        Message.success(1000, res.message, function () {
                            parent.setUpdateFlag();
                            //任务书Id
                            if (xmId == -1) {
                                xmId = res.data.id;
                                $("#id").val(xmId);
                            }

                            //主要完成人
                            var members = [];
                            var oldMembers = table.cache["currentTableId1"];
                            for (const item of oldMembers) {
                                var member = {
                                    "xm": xmId,
                                    "ry": item.ry,
                                    "dw": item.dw,
                                    "ryxm": item.ryxm,
                                    "dwmc": item.dwmc,
                                    "dwlx": item.dwlx,
                                    "xmjs": item.xmjs,
                                    "sxbh": item.sxbh,
                                    "zc": item.zc,
                                    "xl": item.xl,
                                    "trgzzys": item.trgzzys,
                                    "bxmfg": item.bxmfg
                                };
                                members.push(member);
                            }
                            AjaxUtil.post({
                                url: AjaxUtil.ctx + "prjMember/batchInsert/" + xmId,
                                contentType: "application/json",
                                data: JSON.stringify(members),
                                success: function (res) {
                                    if (res.code === 0) {
                                        // Message.success(1000, res.message, function () {
                                        //
                                        // });
                                    } else {
                                        // Message.error(res.message, 1000);
                                    }
                                },
                                error: function (error) {
                                }
                            });

                            //主要完成单位
                            var companys = [];
                            var oldCompanys = table.cache["currentTableId2"];
                            for (let item of oldCompanys) {
                                var company = {
                                    "xm": xmId,
                                    "dw": item.dw,
                                    "dwmc": item.dwmc,
                                    "dwqc": item.dwqc,
                                    "lxr": item.lxr,
                                    "lxrxm": item.lxrxm,
                                    "sfzyzf": item.sfzyzf
                                };
                                companys.push(company);
                            }
                            AjaxUtil.post({
                                url: AjaxUtil.ctx + "prjCompletecompany/batchInsert/" + xmId,
                                contentType: "application/json",
                                data: JSON.stringify(companys),
                                success: function (res) {
                                    dataCompany = companys;
                                    $.ajax({
                                        url: AjaxUtil.ctx + 'prjBudget/list/' + xmId,
                                        type: "post",
                                        async: false,
                                        dataType: "json",
                                        success: function (result) {
                                            dataBudget = result;
                                        }
                                    });
                                    setPrjBudge();
                                    if (res.code === 0) {
                                        // Message.success(1000, res.message, function () {
                                        //
                                        // });
                                    } else {
                                        // Message.error(res.message, 1000);
                                    }
                                },
                                error: function (error) {
                                }
                            });
                        });
                    } else {
                        Message.error(res.message, 1000);
                    }
                },
                fail: function (res) {
                    layer.close(index);
                    Message.error(res.message, 1500);
                },
                error: function (error) {

                }
            });
            return false;
        });

        // 监听确认按钮（填写说明）
        $("button[lay-filter='saveBtn2']").click(function () {
            if (xmId == -1) {
                Message.error("请先创建项目任务书，然后再保存填写说明", 2000);
            } else {
                var project = {
                    "id": xmId,
                    "txsm": $("#txsm").val()
                }
                var index = layer.load(0, {shade: 0.1});
                AjaxUtil.post({
                    url: AjaxUtil.ctx + "prjProject/doUpdateTxsm",
                    contentType: "application/json",
                    data: JSON.stringify(project),
                    success: function (res) {
                        if (res.code === 0) {
                            Message.success(1000, res.message, function () {
                                parent.setUpdateFlag();
                            });
                        } else {
                            Message.error(res.message, 1000);
                        }
                        layer.close(index);
                    },
                    error: function (error) {
                        layer.close(index);
                    }
                });
            }
        });

        //子课题
        var dataSubtopic = new Array();
        //子课题单位分工费用统计
        var prjCompletecompanyListFy = new Array();

        function freshSubtopic() {
            $.ajax({
                url: AjaxUtil.ctx + 'prjSubtopic/list/' + xmId,
                type: "post",
                async: false,
                dataType: "json",
                success: function (result) {
                    dataSubtopic = result.data.rows;
                    prjCompletecompanyListFy =  result.data.prjCompletecompanyListFy;
//年度预算总和

                    document.getElementById('rwsys').value = result.data.sum;

                    document.getElementById('rwsys2').value = result.data.sum;
                }
            });
            table.reload('currentTableId3', {
                data: dataSubtopic
            });
        }

        var currTable3 = table.render({
            elem: '#currentTableId3',
            data: dataSubtopic,
            cols: [
                [
                    {type: "checkbox"},
// {type: 'numbers', align: 'center'},
                    {type: 'numbers', title: '序号', width: '10%', align: 'center'},
                    {field: 'ktmc', title: '课题名称', width: '30%'},
                    {field: 'fzrxm', title: '负责人', width: '10%'},
                    {field: 'fzrszdwmc', title: '负责人所在单位', width: '25%'},
                    {field: 'qssj', title: '起始时间', width: '12%', align: 'center'},
                    {field: 'jssj', title: '结束时间', width: '12%', align: 'center'}
// {title: '操作', toolbar: '#currentTableBar3', align: 'center', fixed: 'right'}
                ]
            ],
            autoSort: false,
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'grid',
            parseData: function (res) { //res 即为原始返回的数据
//年度预算总和
                document.getElementById('rwsys').value = res.data.sum;
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.rows //解析数据列表
                };
            }
        });
        // 监听新建按钮(子课题)
        $("button[lay-filter='btnAdd3']").click(function () {
            if (xmId == -1) {
                Message.error("请先创建项目任务书，然后再添加子课题", 2000);
            } else {
                layer.open({
                    title: '新建子课题',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['1020px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjSubtopic/forAdd/' + xmId,
                    end: function (index) {
                        // 重载表格
                        if (updateflag == 1)
                            freshSubtopic();
                        updateflag = 0;
                        layer.close(index);
                    }
                });
            }
        });
        // 监听编辑按钮(子课题)
        $("button[lay-filter='btnEdit3']").click(function () {
            var subTopics = table.cache["currentTableId3"];
            if (subTopics.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 {
                layer.open({
                    title: '编辑子课题',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['1030px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjSubtopic/forUpdate/' + data[0].id,
                    end: function (index) {
                        // 重载表格
                        if (updateflag == 1)
                            freshSubtopic();
                        updateflag = 0;
                        layer.close(index);
                    }
                });
            }
        });
        // 监听查看按钮(子课题)
        $("button[lay-filter='btnView3']").click(function () {
            var subTopics = table.cache["currentTableId3"];
            if (subTopics.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 {
                layer.open({
                    title: '浏览子课题',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['1030px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjSubtopic/forView/' + data[0].id,
                    end: function () {
                        layer.close(index);
                    }
                });
            }
        });
        // 监听删除按钮(子课题)
        $("button[lay-filter='btnDelete3']").click(function () {
            var subTopics = table.cache["currentTableId3"];
            if (subTopics.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId3')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要删除的子课题！", 1500);
            } else {
                layer.confirm('确定批量删除子课题吗？', function (index) {
                    layer.close(index);
                    AjaxUtil.post({
                        url: AjaxUtil.ctx + "prjSubtopic/batchDelete",
                        contentType: "application/json",
                        data: JSON.stringify(data),
                        success: function (res) {
                            if (res.code === 0) {
                                Message.success(1000, res.message, function () {
                                    // 重载表格
                                    freshSubtopic();
                                });
                            } else {
                                Message.error(res.message, 1000);
                            }
                        },
                        error: function (error) {
                        }
                    });
                });
            }
        });
        // 监听行工具事件（子课题）
        table.on('tool(currentTableFilter3)', function (obj) {
            var data = obj.data;
            if (obj.event === 'view') {
                layer.open({
                    title: '浏览子课题',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['1030px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjSubtopic/forView/' + data.id,
                    end: function () {
                        layer.close(index);
                    }
                });
            } else if (obj.event === 'update') {
                layer.open({
                    title: '编辑子课题',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['1030px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjSubtopic/forUpdate/' + data.id,
                    end: function (index) {
                        // 重载表格
                        if (updateflag == 1)
                            freshSubtopic();
                        updateflag = 0;
                    }
                });
            } else if (obj.event === 'delFlag') {
                layer.confirm('确定删除该课题吗？', function (index) {
                    AjaxUtil.get({
                        url: AjaxUtil.ctx + "prjSubtopic/delete/" + data.id,
                        success: function (res) {
                            if (res.code === 0) {
                                Message.success(1000, res.message, function () {
                                    // 重载表格
                                    freshSubtopic();
                                });
                            } else {
                                Message.error(res.message, 1000);
                            }
                        },
                        error: function (error) {
                        }
                    });
                });
            }
            return false;
        });
        //双击（子课题）
        table.on('rowDouble(currentTableFilter3)', function (obj) {
            var data = obj.data;
            layer.open({
                title: '浏览子课题',
                type: 2,
                maxmin: true,
                shade: 0.2,
                area: ['1030px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'prjSubtopic/forView/' + data.id,
                end: function () {
                    layer.close(index);
                }
            });
        });

        // 监听确认按钮（内容）
        $("button[lay-filter='saveBtn4']").click(function () {
            if (xmId == -1) {
                Message.error("请先创建项目任务书，然后再保存研究内容及考核指标", 2000);
            } else {
                var project = {
                    "id": xmId,
                    "yjnrjkhzb": $("#yjnrjkhzb").val()
                }
                var index = layer.load(0, {shade: 0.1});
                AjaxUtil.post({
                    url: AjaxUtil.ctx + "prjProject/updateContent",
                    contentType: "application/json",
                    data: JSON.stringify(project),
                    success: function (res) {
                        if (res.code === 0) {
                            Message.success(1000, res.message, function () {
                                parent.setUpdateFlag();
                            });
                        } else {
                            Message.error(res.message, 1000);
                        }
                        layer.close(index);
                    },
                    error: function (error) {
                        layer.close(index);
                    }
                });
            }
        });

        //项目预算列标题
        function getBudgetCols() {
            budgetCols = [];
            budgetCols.push({type: 'numbers', width: '3%'});
            budgetCols.push({field: 'mc', width: '22%', title: '名称'});
            budgetCols.push({field: 'ysje', width: '10%', title: '预算金额(万元)'});
            for (var i = 0; i < dataCompany.length; i++) {
                budgetCols.push({
                    field: "dw" + (i + 1),
                    width: '10%',
                    title: dataCompany[i].dwmc + '(万元)',
                    edit: 'number'
                })
                if (i >= 9)
                    break;
            }
            ;
        }

        //项目预算
        var insTb5;

        function loadTreetable() {
            insTb5 = treeTable.render({
                elem: '#currentTableId5',
                data: dataBudget,
                skin: 'grid',
                tree: {
                    treeColIndex: 1,
                    treeSpid: "",   //最上级的父级id
                    iconIndex: 1,   // 折叠图标显示在第几列
                    isPidData: true,// 是否是id、pid形式数据
                    idName: 'bm',  // id字段名称
                    pidName: 'fj', // pid字段名称
                    arrowType: 'arrow2',
                    getIcon: 'ew-tree-icon-style2',
                    openName: 'bm'
                },
                treeDefaultClose: false,
                page: false,
                // toolbar: '#toolbarDemo',
                cols: [budgetCols]
            });
        }

        function setPrjBudge() {
            getBudgetCols();
            loadTreetable();
        }

        //加载预算项
        setPrjBudge();
        // 监听单元格编辑
        treeTable.on('edit(currentTableId5)', function (obj) {
            var value = obj.value,
                item = obj.data,
                dw = obj.field;
            if (item.children == undefined) {
                //当前行预算
                setCurBudget(item.bm, dw, value);
                //父级预算
                setFjBudget(item.fj);
            }
            loadTreetable();
        });

        //当前行预算
        function setCurBudget(bm, dw, value) {
            for (var i = 0; i < dataBudget.length; i++) {
                if (bm == dataBudget[i].bm) {
                    value = parseFloat(value);
                    if (value<0){
                        alert("金额不能为负数或无效的数字，请重新输入！");
                        value = null;
                    }
                    if (isNaN(value))
                        value = null;
                    var rwsys = $("#rwsys").val();
                    // if (value !== null && value > rwsys * 0.2) {
                    //     alert("不能超过任务书预算的20%！");
                    //     return; // 返回，不进行后续处理
                    // }

                    //当前单元格
                    if (dw == "dw1") {
                        dataBudget[i].dw1 = value;
                    } else if (dw == "dw2") {
                        dataBudget[i].dw2 = value;
                    } else if (dw == "dw3") {
                        dataBudget[i].dw3 = value;
                    } else if (dw == "dw4") {
                        dataBudget[i].dw4 = value;
                    } else if (dw == "dw5") {
                        dataBudget[i].dw5 = value;
                    } else if (dw == "dw6") {
                        dataBudget[i].dw6 = value;
                    } else if (dw == "dw7") {
                        dataBudget[i].dw7 = value;
                    } else if (dw == "dw8") {
                        dataBudget[i].dw8 = value;
                    } else if (dw == "dw9") {
                        dataBudget[i].dw9 = value;
                    } else if (dw == "dw10") {
                        dataBudget[i].dw10 = value;
                    }

                    //正在编辑的预算
                    var dw1 = 0, dw2 = 0, dw3 = 0, dw4 = 0, dw5 = 0,
                        dw6 = 0, dw7 = 0, dw8 = 0, dw9 = 0, dw10 = 0;
                    if (dataBudget[i].dw1 != null) {
                        dw1 = parseFloat(dataBudget[i].dw1);
                        if (isNaN(dw1))
                            dw1 = 0;
                    }
                    if (dataBudget[i].dw2 != null) {
                        dw2 = parseFloat(dataBudget[i].dw2);
                        if (isNaN(dw2))
                            dw2 = 0;
                    }
                    if (dataBudget[i].dw3 != null) {
                        dw3 = parseFloat(dataBudget[i].dw3);
                        if (isNaN(dw3))
                            dw3 = 0;
                    }
                    if (dataBudget[i].dw4 != null) {
                        dw4 = parseFloat(dataBudget[i].dw4);
                        if (isNaN(dw4))
                            dw4 = 0;
                    }
                    if (dataBudget[i].dw5 != null) {
                        dw5 = parseFloat(dataBudget[i].dw5);
                        if (isNaN(dw5))
                            dw5 = 0;
                    }
                    if (dataBudget[i].dw6 != null) {
                        dw6 = parseFloat(dataBudget[i].dw6);
                        if (isNaN(dw6))
                            dw6 = 0;
                    }
                    if (dataBudget[i].dw7 != null) {
                        dw7 = parseFloat(dataBudget[i].dw7);
                        if (isNaN(dw7))
                            dw7 = 0;
                    }
                    if (dataBudget[i].dw8 != null) {
                        dw8 = parseFloat(dataBudget[i].dw8);
                        if (isNaN(dw8))
                            dw8 = 0;
                    }
                    if (dataBudget[i].dw9 != null) {
                        dw9 = parseFloat(dataBudget[i].dw9);
                        if (isNaN(dw9))
                            dw9 = 0;
                    }
                    if (dataBudget[i].dw10 != null) {
                        dw10 = parseFloat(dataBudget[i].dw10);
                        if (isNaN(dw10))
                            dw10 = 0;
                    }

                    var ysje = (dw1 + dw2 + dw3 + dw4 + dw5 + dw6 + dw7 + dw8 + dw9 + dw10).toFixed(2);
                    // alert(ysje);
                    if (ysje == 0)
                        dataBudget[i].ysje = "";
                    else
                        dataBudget[i].ysje = ysje;

                    break;
                }
            }
        }

        //父级预算
        function setFjBudget(fj) {
            if (fj != null && fj != '') {
                var dw1 = 0, dw2 = 0, dw3 = 0, dw4 = 0, dw5 = 0,
                    dw6 = 0, dw7 = 0, dw8 = 0, dw9 = 0, dw10 = 0;

                //子节点的值相加
                for (var j = 0; j < dataBudget.length; j++) {
                    if (fj == dataBudget[j].fj) {
                        var t1 = parseFloat(dataBudget[j].dw1);
                        if (!isNaN(t1))
                            dw1 += t1;
                        var t2 = parseFloat(dataBudget[j].dw2);
                        if (!isNaN(t2))
                            dw2 += t2;
                        var t3 = parseFloat(dataBudget[j].dw3);
                        if (!isNaN(t3))
                            dw3 += t3;
                        var t4 = parseFloat(dataBudget[j].dw4);
                        if (!isNaN(t4))
                            dw4 += t4;
                        var t5 = parseFloat(dataBudget[j].dw5);
                        if (!isNaN(t5))
                            dw5 += t5;
                        var t6 = parseFloat(dataBudget[j].dw6);
                        if (!isNaN(t6))
                            dw6 += t6;
                        var t7 = parseFloat(dataBudget[j].dw7);
                        if (!isNaN(t7))
                            dw7 += t7;
                        var t8 = parseFloat(dataBudget[j].dw8);
                        if (!isNaN(t8))
                            dw8 += t8;
                        var t9 = parseFloat(dataBudget[j].dw9);
                        if (!isNaN(t9))
                            dw9 += t9;
                        var t10 = parseFloat(dataBudget[j].dw10);
                        if (!isNaN(t10))
                            dw10 += t10;
                    }
                }


                //更新父节点的值
                for (var j = 0; j < dataBudget.length; j++) {
                    if (fj == dataBudget[j].bm) {
                        if (dw1 == 0)
                            dataBudget[j].dw1 = '';
                        else
                            dataBudget[j].dw1 = dw1.toFixed(2);

                        if (dw2 == 0)
                            dataBudget[j].dw2 = '';
                        else
                            dataBudget[j].dw2 = dw2.toFixed(2);
                        if (dw3 == 0)
                            dataBudget[j].dw3 = '';
                        else
                            dataBudget[j].dw3 = dw3.toFixed(2);
                        if (dw4 == 0)
                            dataBudget[j].dw4 = '';
                        else
                            dataBudget[j].dw4 = dw4.toFixed(2);
                        if (dw5 == 0)
                            dataBudget[j].dw5 = '';
                        else
                            dataBudget[j].dw5 = dw5.toFixed(2);
                        if (dw6 == 0)
                            dataBudget[j].dw6 = '';
                        else
                            dataBudget[j].dw6 = dw6.toFixed(2);
                        if (dw7 == 0)
                            dataBudget[j].dw7 = '';
                        else
                            dataBudget[j].dw7 = dw7.toFixed(2);
                        if (dw8 == 0)
                            dataBudget[j].dw8 = '';
                        else
                            dataBudget[j].dw8 = dw8.toFixed(2);
                        if (dw9 == 0)
                            dataBudget[j].dw9 = '';
                        else
                            dataBudget[j].dw9 = dw9.toFixed(2);
                        if (dw10 == 0)
                            dataBudget[j].dw10 = '';
                        else
                            dataBudget[j].dw10 = dw10.toFixed(2);

                        var ysje = dw1 + dw2 + dw3 + dw4 + dw5 + dw6 + dw7 + dw8 + dw9 + dw10;


                        if (ysje == 0) {
                            dataBudget[j].ysje = "";
                        } else
                            dataBudget[j].ysje = ysje.toFixed(2);

                        setFjBudget(dataBudget[j].fj);

                        break;
                    }
                }
            }
        }

        //组织要保存的数据
        function getBudget(budgets, data) {
            var budget = {
                "id": data.id,
                "fj": data.fj,
                "ysje": data.ysje,
                "dw1": data.dw1,
                "dw2": data.dw2,
                "dw3": data.dw3,
                "dw4": data.dw4,
                "dw5": data.dw5,
                "dw6": data.dw6,
                "dw7": data.dw7,
                "dw8": data.dw8,
                "dw9": data.dw9,
                "dw10": data.dw10
            };
            budgets.push(budget);
            if (data.children != undefined) {
                getChildNode(budgets, data);
            }
        }

        function getChildNode(budgets, data) {
            for (let item of data.children) {
                getBudget(budgets, item);
            }
        }

        // 监听确认按钮（项目预算）
        $("button[lay-filter='saveBtn5']").click(function () {

            if (xmId == -1) {
                Message.error("请先创建项目任务书，然后再填写项目预算", 2000);
            } else {
                var data = insTb5.options.data;
                var budgets = new Array();

                for (var i = 0; i < data.length; i++) {
                    getBudget(budgets, data[i]);
                }
                for (let i = 0; i < prjCompletecompanyListFy.length; i++) {
                    if (prjCompletecompanyListFy[i].sumjf == null){
                        prjCompletecompanyListFy[i].sumjf =0;
                    }
                    if ( budgets[0]['dw' + (i + 1)] == null ||  budgets[0]['dw' + (i + 1)] ==''){
                        budgets[0]['dw' + (i + 1)] ==0;
                    }
                    if (budgets[0]['dw' + (i + 1)] != prjCompletecompanyListFy[i].sumjf ){
                        alert("保存失败,"+prjCompletecompanyListFy[i].dwmc+'在子课题单位分工中所有经费总和为:'
                            +prjCompletecompanyListFy[i].sumjf+'万元,请确保所填数据一致!!!')
                        return false
                    }
                }

                var index = layer.load(0, {shade: 0.1});
                AjaxUtil.post({
                    url: AjaxUtil.ctx + "prjProject/doUpdateXmys",
                    contentType: "application/json",
                    data: JSON.stringify(budgets),
                    success: function (res) {
                        if (res.code === 0) {
                            Message.success(1000, res.message, function () {
                                loadTreetable();
                                parent.setUpdateFlag();
                            });
                        } else {
                            Message.error(res.message, 1000);
                        }
                        layer.close(index);
                    },
                    error: function (error) {
                        layer.close(index);
                    }
                });
            }
            alert(ysje)
        });

        //出资方案
        var dataFeescheme = new Array();

        function freshFeescheme() {
            $.ajax({
                url: AjaxUtil.ctx + 'prjFeescheme/list/' + xmId,
                type: "post",
                async: false,
                dataType: "json",
                success: function (result) {
                    dataFeescheme = result.data.rows;
                }
            });
            table.reload('currentTableId6', {
                data: dataFeescheme
            });
        }

        var currTable6 = table.render({
            elem: '#currentTableId6',
            data: dataFeescheme,
            cols: [
                [
                    {type: "checkbox"},
                    // {type: 'numbers', align: 'center'},
                    {type: 'numbers', title: '序号', align: 'center'},
                    {field: 'nf', title: '年份', width: '12%', align: 'center'},
                    {field: 'dwmc', title: '出资单位', width: '45%'},
                    {field: 'czje', title: '出资金额(万元)', width: '15%', align: 'center'}
                    // {title: '操作', toolbar: '#currentTableBar6', align: 'center', fixed: 'right'}
                ]
            ],
            autoSort: false,
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'grid',
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.rows //解析数据列表
                };
            }
        });
        // 监听新建按钮(出资方案)
        $("button[lay-filter='btnAdd6']").click(function () {
            if (xmId == -1) {
                Message.error("请先创建项目任务书，然后再添加出资方案", 2000);
            } else {
                layer.open({
                    title: '新建出资方案',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['1010px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjFeescheme/forAdd/' + xmId + '?qs=' + $("#qs").val() + '&wc=' + $("#wc").val() + '&ysjecz=' + $("#rwsys").val(),
                    end: function (index) {
                        // 重载表格
                        if (updateflag == 1)
                            freshFeescheme();
                        updateflag = 0;
                        layer.close(index);
                    }
                });
            }
        });
        // 监听编辑按钮(出资方案)
        $("button[lay-filter='btnEdit6']").click(function () {
            var czfas = table.cache["currentTableId6"];
            if (czfas.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId6')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要编辑的出资方案！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行编辑！", 1500);
            } else {
                layer.open({
                    title: '编辑出资方案',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['1010px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjFeescheme/forUpdate/' + data[0].id + '?qs=' + $("#qs").val() + '&wc=' + $("#wc").val() + '&ysjecz=' + $("#rwsys").val(),

                    end: function (index) {
                        // 重载表格
                        if (updateflag == 1)
                            freshFeescheme();
                        updateflag = 0;
                        layer.close(index);
                    }
                });
            }
        });
        // 监听查看按钮(出资方案)
        $("button[lay-filter='btnView6']").click(function () {
            var czfas = table.cache["currentTableId6"];
            if (czfas.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId6')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要浏览的出资方案！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行浏览！", 1500);
            } else {
                layer.open({
                    title: '浏览出资方案',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['1010px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjFeescheme/forView/' + data[0].id,
                });
            }
        });
        // 监听删除按钮(出资方案)
        $("button[lay-filter='btnDelete6']").click(function () {
            var czfas = table.cache["currentTableId6"];
            if (czfas.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId6')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要删除的出资方案！", 1500);
            } else {
                layer.confirm('确定批量删除出资方案吗？', function (index) {
                    layer.close(index);
                    AjaxUtil.post({
                        url: AjaxUtil.ctx + "prjFeescheme/batchDelete",
                        contentType: "application/json",
                        data: JSON.stringify(data),
                        success: function (res) {
                            if (res.code === 0) {
                                Message.success(1000, res.message, function () {
                                    // 重载表格
                                    alert('已删除所选数据');
                                    freshFeescheme();
                                });
                            } else {
                                Message.error(res.message, 1000);
                            }
                        },
                        error: function (error) {
                        }
                    });
                });
            }
        });
        // 监听行工具事件（出资方案）
        table.on('tool(currentTableFilter6)', function (obj) {
            var data = obj.data;
            if (obj.event === 'view') {
                layer.open({
                    title: '浏览出资方案',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['1010px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjFeescheme/forView/' + data.id,
                });
            } else if (obj.event === 'update') {
                layer.open({
                    title: '编辑出资方案',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['1010px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjFeescheme/forUpdate/' + data.id,
                    end: function (index) {
                        // 重载表格
                        if (updateflag == 1)
                            freshFeescheme();
                        updateflag = 0;
                        layer.close(index);
                    }
                });
            } else if (obj.event === 'delFlag') {
                layer.confirm('确定删除该出资方案吗？', function (index) {
                    layer.close(index);
                    AjaxUtil.get({
                        url: AjaxUtil.ctx + "prjFeescheme/delete/" + data.id,
                        success: function (res) {
                            if (res.code === 0) {
                                Message.success(1000, res.message, function () {
                                    // 重载表格
                                    freshFeescheme();
                                });
                            } else {
                                Message.error(res.message, 1000);
                            }
                        },
                        error: function (error) {
                        }
                    });
                });
            }
            return false;
        });
        //双击（出资方案）
        table.on('rowDouble(currentTableFilter6)', function (obj) {
            var data = obj.data;
            layer.open({
                title: '浏览出资方案',
                type: 2,
                maxmin: true,
                shade: 0.2,
                area: ['1010px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'prjFeescheme/forView/' + data.id,
            });
        });

        // 监听确认按钮（说明）
        $("button[lay-filter='saveBtn7']").click(function () {
            if (xmId == -1) {
                Message.error("请先创建项目任务书，然后再保存有关问题说明", 2000);
            } else {
                var project = {
                    "id": xmId,
                    "ygwtsm": $("#ygwtsm").val()
                }
                var index = layer.load(0, {shade: 0.1});
                AjaxUtil.post({
                    url: AjaxUtil.ctx + "prjProject/doUpdateYgwtsm",
                    contentType: "application/json",
                    data: JSON.stringify(project),
                    success: function (res) {
                        if (res.code === 0) {
                            Message.success(1000, res.message, function () {
                                parent.setUpdateFlag();
                            });
                        } else {
                            Message.error(res.message, 1000);
                        }
                        layer.close(index);
                    },
                    error: function (error) {
                        layer.close(index);
                    }
                });
            }
        });

        //联系方式
        var dataContacts = new Array();

        function freshContacts() {
            $.ajax({
                url: AjaxUtil.ctx + 'prjContacts/list/' + xmId,
                type: "post",
                async: false,
                dataType: "json",
                success: function (result) {
                    dataContacts = result.data.rows;
                }
            });
            table.reload('currentTableId8', {
                data: dataContacts
            });
        }

        var currTable8 = table.render({
            elem: '#currentTableId8',
            data: dataContacts,
            cols: [
                [
                    {type: "checkbox"},
                    {type: 'numbers', align: 'center'},
                    {field: 'dwmc', title: '单位', width: '30%'},
                    {field: 'lxrxm', title: '联系人', width: '10%'},
                    {field: 'gddh', title: '固定电话', width: '12%'},
                    {field: 'dzyj', title: '电子邮件', width: '18%'},
                    {field: 'lxmc', title: '类型', width: '10%'}
                ]
            ],
            autoSort: false,
            limits: [10, 15, 20, 25, 50, 100],
            limit: 10,
            page: true,
            skin: 'grid',
            parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.data.total, //解析数据长度
                    "data": res.data.rows //解析数据列表
                };
            }
        });
        // 监听新建按钮(联系方式)
        $("button[lay-filter='btnAdd8']").click(function () {
            if (xmId == -1) {
                Message.error("请先创建项目模板并保存，然后再添加联系方式", 2000);
            } else {
                layer.open({
                    title: '新建联系方式',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['900px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjContacts/forAdd/' + xmId,
                    end: function (index) {
                        console.log(updateflag);
                        // 重载表格
                        if (updateflag == 1)
                            freshContacts();
                        updateflag = 0;
                        layer.close(index);
                    }
                });
            }
        });
        // 监听编辑按钮(联系方式)
        $("button[lay-filter='btnEdit8']").click(function () {
            var contacts = table.cache["currentTableId8"];
            if (contacts.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId8')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要编辑的联系方式！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行编辑！", 1500);
            } else {
                layer.open({
                    title: '编辑联系方式',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['900px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjContacts/forUpdate/' + data[0].id,
                    end: function (index) {
                        // 重载表格
                        if (updateflag == 1)
                            freshContacts();
                        updateflag = 0;
                        layer.close(index);
                    }
                });
            }
        });
        // 监听查看按钮(联系方式)
        $("button[lay-filter='btnView8']").click(function () {
            var contacts = table.cache["currentTableId8"];
            if (contacts.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId8')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要浏览的联系方式！", 1500);
            } else if (data.length > 1) {
                Message.warning("请选择一条记录进行浏览！", 1500);
            } else {
                layer.open({
                    title: '浏览联系方式',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['900px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjContacts/forView/' + data[0].id,
                    end: function () {
                        layer.close(index);
                    }
                });
            }
        });
        // 监听删除按钮(联系方式)
        $("button[lay-filter='btnDelete8']").click(function () {
            var contacts = table.cache["currentTableId8"];
            if (contacts.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId8')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要删除的联系方式！", 1500);
            } else {
                layer.confirm('确定批量删除联系方式吗？', function (index) {
                    layer.close(index);
                    AjaxUtil.post({
                        url: AjaxUtil.ctx + "prjContacts/batchDelete",
                        contentType: "application/json",
                        data: JSON.stringify(data),
                        success: function (res) {
                            if (res.code === 0) {
                                Message.success(1000, res.message, function () {
                                    // 重载表格
                                    freshContacts();
                                });
                            } else {
                                Message.error(res.message, 1000);
                            }
                        },
                        error: function (error) {
                        }
                    });
                });
            }
        });
        // 监听行工具事件（联系方式）
        table.on('tool(currentTableFilter8)', function (obj) {
            var data = obj.data;
            if (obj.event === 'view') {
                layer.open({
                    title: '浏览联系方式',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['900px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjContacts/forView/' + data.id,
                    end: function () {
                        layer.close(index);
                    }
                });
            } else if (obj.event === 'update') {

                layer.open({
                    title: '编辑联系方式',
                    type: 2,
                    maxmin: true,
                    shade: 0.2,
                    area: ['900px', layerheight + 'px'],
                    content: AjaxUtil.ctx + 'prjContacts/forUpdate/' + data.id,
                    end: function (index) {
                        // 重载表格
                        if (updateflag == 1)
                            freshContacts();
                        updateflag = 0;
                        layer.close(index);
                    }
                });
            } else if (obj.event === 'delFlag') {
                layer.confirm('确定删除该联系方式吗？', function (index) {
                    layer.close(index);
                    AjaxUtil.get({
                        url: AjaxUtil.ctx + "prjContacts/delete/" + data.id,
                        success: function (res) {
                            if (res.code === 0) {
                                Message.success(1000, res.message, function () {
                                    // 重载表格
                                    freshContacts();
                                });
                            } else {
                                Message.error(res.message, 1000);
                            }
                        },
                        error: function (error) {
                        }
                    });
                });
            }
            return false;
        });
        //双击（联系方式）
        table.on('rowDouble(currentTableFilter8)', function (obj) {
            var data = obj.data;
            layer.open({
                title: '浏览联系方式',
                type: 2,
                maxmin: true,
                shade: 0.2,
                area: ['900px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'prjContacts/forView/' + data.id,
                end: function () {
                    layer.close(index);
                }
            });
        });

        // 用于存放表格数据
        var dataFj = new Array();
        //附件
        var currTable9 = table.render({
            elem: '#currentTableId9',
            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) {
                // debugger;
                if (0 === res.code) {
                    if (res.data.fileType == "memberFile") {
                        if (0 === res.data.code) {
                            var currData = [];
                            for (var i = 0; i < res.data.list.length; i++) {
                                var currMember = {
                                    "ry": res.data.list[i].ry,
                                    "ryxm": res.data.list[i].ryxm,
                                    "dw": res.data.list[i].dw,
                                    "dwmc": res.data.list[i].dwmc,
                                    "dwlx": res.data.list[i].dwlx,
                                    "dwlxmc": res.data.list[i].dwlxmc,
                                    "zc": res.data.list[i].zc,
                                    "zcmc": res.data.list[i].zcmc,
                                    "xl": res.data.list[i].xl,
                                    "xlmc": res.data.list[i].xlmc,
                                    "xmjs": res.data.list[i].xmjs,
                                    "xmjsmc": res.data.list[i].xmjsmc,
                                    "bxmfg": res.data.list[i].bxmfg,
                                    "sxbh": res.data.list[i].sxbh,
                                    "trgzzys": res.data.list[i].trgzzys
                                };
                                currData.push(currMember);
                            }
                            table.reload('currentTableId1', {
                                data: currData
                            });
                            var gjzc = 0, zjzc = 0, cjzc = 0, yjs = 0;
                            for (let item of currData) {
                                if (item.zc.substring(2, 3) == 1 || item.zc.substring(2, 3) == 2)
                                    gjzc++;
                                else if (item.zc.substring(2, 3) == 2)
                                    zjzc++;
                                else if (item.zc.substring(2, 3) == 3)
                                    cjzc++;
                                if (item.xlmc.indexOf("研究生") > -1)
                                    yjs++;
                            }
                            //更新统计信息
                            $("#zrs").val(currData.length);
                            $("#gjzc").val(gjzc);
                            $("#zjzc").val(zjzc);
                            $("#cjzc").val(cjzc);
                            $("#yjs").val(yjs);
                            form.render();
                        } else if (10 === res.data.code) {
                            layer.alert("文件中部分人员未录入到系统！" + res.data.tipList.toString());
                        } else if (20 === res.data.code) {
                            layer.alert("文件中不存在可识别的记录！");
                        } else {
                            layer.alert("上传格式错误！");
                        }
                    } else {
                        var curData = {
                            "wjm": res.data.fileName,
                            "scrq": res.data.fileDate,
                            "Url": res.data.fileUrl,
                            "sm": res.data.sm
                        };
                        dataFj.push(curData);
                        currTable9.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('currentTableId9')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要删除的附件！", 1000);
                return;
            }
            for (var i = 0; i < dataFj.length; i++) {
                var item = dataFj[i];
                if (item.LAY_CHECKED) {//条件：选中
                    dataFj.splice(i, 1);//移除后后造成数组下标索引发生变化，所以下面需要i--
                    i--;
                }
            }
            //刷新表格
            currTable9.reload();
        });
        //双击（附件）
        table.on('rowDouble(currentTableFilter9)', function (obj) {
            window.open(obj.data.Url);
        });

        // 监听确认按钮（附件）
        $("button[lay-filter='saveBtn9']").click(function () {
            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));

            var project = {
                "id": xmId,
                "fj": $("#fj").val()
            }
            var index = layer.load(0, {shade: 0.1});
            AjaxUtil.post({
                url: AjaxUtil.ctx + "prjProject/doUpdateFJ",
                contentType: "application/json",
                data: JSON.stringify(project),
                success: function (res) {
                    if (res.code === 0) {
                        Message.success(1000, res.message, function () {
                            parent.setUpdateFlag();
                        });
                    } else {
                        Message.error(res.message, 1000);
                    }
                    layer.close(index);
                },
                error: function (error) {
                    layer.close(index);
                }
            });
            return false;
        });

        // 监听取消按钮
        $("button[lay-filter='cancleBtn']").click(function () {
            if (updateflag == 1)
                currTable3.reload();
            updateflag = 0;
            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 setUpdateFlag() {
        updateflag = 1;
    }

    //从子页面设置父页面的值
    function setData(id, name) {
        ObjId = id;
        ObjName = name;
    }

    //设置项目完成人员信息
    function setMember(member) {
        prjMember = member;
    }

    //获取当前的项目人员
    function getMember() {
        return prjMember;
    }

    //获取当前的项目完成单位信息
    function getCompany() {
        return prjCompany;
    }

    //设置项目完成单位信息
    function setCompany(company) {
        prjCompany = company;
    }

    //获取子课题信息
    function getZktInfo() {
        return subTopic;
    }
</script>
</body>
</html>