<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>新建</title>
    <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <link rel="stylesheet" th:href="@{/lib/font-awesome-4.7.0/css/font-awesome.min.css}" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form class="layui-form" action="" lay-filter="formDemo">
    <div class="layui-tab layui-tab-card">
        <ul class="layui-tab-title">
            <li class="layui-this">常规</li>
            <li>其它信息</li>
        </ul>
        <div class="layui-tab-content">
            <!--常规开始-->
            <div class="layui-tab-item layui-show" style="min-height: 550px">
                <form class="layui-form" action="" lay-filter="formDemo">
                    <div class="layui-form layuimini-form" style="padding-bottom: 100px">
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label required" style="width: 70px">申请名称</label>
                            <div class="layui-input-inline" style="width: 855px">
                                <input type="hidden" id="id" name="id" class="layui-input" readonly>
                                <input type="text" id="sqmc" name="sqmc" lay-verify="required" lay-reqtext="申请名称不能为空"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label required" style="width: 70px">项目名称</label>
                            <div class="layui-input-inline" style="width: 855px">
                                <input type="hidden" id="xmid" name="xmid" class="layui-input" th:value="${project.id}">
                                <input type="text" id="xmmc" name="xmmc" class="layui-input" lay-verify="required"
                                       lay-reqtext="申请名称不能为空" th:value="${project.zwmc}" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 70px">编号</label>
                            <div class="layui-input-inline" style="width: 380px">
                                <input type="text" id="bh" name="bh" class="layui-input" autocomplete="off">
                            </div>
                            <label class="layui-form-label" style="width: 85px">年份</label>
                            <div class="layui-input-inline" style="width: 350px">
                                <input type="number" id="nf" name="nf" min="2000" value="2023" class="layui-input"
                                       autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label required" style="width: 70px">费用类别</label>
                            <div class="layui-input-inline" style="width: 380px">
                                <input type="hidden" id="fylb" name="fylb" class="layui-input">
                                <input type="text" id="fylbmc" name="fylbmc" lay-verify="required"
                                       lay-reqtext="费用类别不能为空" class="layui-input" readonly>
                            </div>
                            <label class="layui-form-label required" style="width: 85px">申请金额(元)</label>
                            <div class="layui-input-inline" style="width: 350px">
                                <input type="number" id="sqje" name="sqje" class="layui-input" lay-verify="required"
                                       lay-reqtext="申请金额不能为空" autocomplete="off">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 70px">申请人</label>
                            <div class="layui-input-inline" style="width: 380px">
                                <input type="hidden" id="sqr" name="sqr" class="layui-input">
                                <input type="text" id="sqrxm" name="sqrxm" class="layui-input" readonly>
                            </div>
                            <label class="layui-form-label" style="width: 85px">申请时间</label>
                            <div class="layui-input-inline" style="width: 350px">
                                <input type="text" id="sqsj" name="sqsj" class="layui-input" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 70px">是否备用金</label>
                            <div class="layui-input-inline">
                                <input type="checkbox" id="sfbyj" name="sfbyj" lay-skin="primary">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 70px">差旅费</label>
                            <div class="layuimini-container" style="width: 855px; margin-left: 98px">
                                <div class="layui-btn-group" style="margin-bottom: -8px">
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subAdd"><i class="layui-icon"></i>新建
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subEdit"><i class="layui-icon"></i>编辑
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subView"><i class="layui-icon">&#xe63c;</i>查看
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="subDelete"><i class="layui-icon"></i>删除
                                    </button>
                                </div>
                                <table class="layui-hide" id="currentTableId1" name="currentTableId1"
                                       lay-filter="currentTableFilter" style="padding-top: 0px;margin-top: 0px"></table>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 70px">申请说明</label>
                            <div class="layui-input-inline" style="width: 855px">
                                <textarea id="sqsm" name="sqsm" class="layui-textarea"
                                          style="width: 100%;height: 150px"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 70px"></label>
                            <div class="layui-input-inline" style="width: 855px">
                                <tip style="color: red">请使用Ctrl+Shift+V 粘贴，用于删除内容格式。</tip>
                                <br/>
                                <tip>”申请说明“除写明费用支出与项目研究内容的相关性外，还需明确以下细节：</tip>
                                <br/>
                                <tip>
                                    1）临时性研究人员人工费:一个项目同一段时期，临时性研究人员原则上不超过3人，目聘用时间不超过3个月。费用申请中请明确聘用人员，聘用时间，具体从事的工作内容，需要的技能或学历等，确保工作量与时间、费用、能力相匹配。
                                </tip>
                                <br/>
                                <tip>2）会议费:申请中请明确会议内容、时间，参会人员等信息，费用按350元/人天的标准进行总额控制，其中餐费按80元/人天标准控制。请尽量减少陪会人员，缩小会议规模。
                                </tip>
                                <br/>
                                <tip>3）差旅费:申请中请明确出差人，出差时间，出差地点，出差事由</tip>
                                <br/>
                                <tip>
                                    4）外委研究支出费:请在招标之前先完成费用申请流程，标题为项目名称-外委研究内容具体标题。费用申请中请明确(1)外委研究/合作研究的类型，其中外委研究费用不超过项目组自控经费的30%;(2)外委研究/合作研究的必要性;(3)具体的研究内容;(4)技术指标和具体参数(5)对方需提交的最终成果形式，如包含硬件或软件的，需明确是否需要对方提供第三方检测报告或实验室自行检测，目检测内容应明确;
                                </tip>
                                <tip style="color: red">
                                    (提交的成果形式中若有硬件或软件的，应提供第三方检测报告:确无法提供第三方检测报告的，需明确要提供专家见证试验或现场测试报告)
                                </tip>
                                <tip>(6)验收的标准;(7)费用预估等内容。</tip>
                                <br/>
                                <tip>
                                    5）外协测试试验与加工:申请中请明确外协的必要性、测试的具体内容、测试频次、测试参数、测试设备、样本类型、样本数量等测试要素的具体要求;明确外协单位的测试能力、资质水平的相关要求。
                                </tip>

                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 70px">附件</label>
                            <div class="layuimini-container" style="width: 855px; margin-left: 98px">
                                <input type="hidden" id="fj" name="fj" class="layui-input">
                                <div class="layui-btn-group" style="margin-bottom: -8px">
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="upLoad"><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>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="upward"><i class="layui-icon"></i>向上
                                    </button>
                                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm"
                                            lay-filter="downward"><i class="layui-icon">&#xe63c;</i>向下
                                    </button>
                                </div>
                                <table class="layui-hide" id="currentTableId2" name="currentTableId2"
                                       lay-filter="currentTableFilter" style="padding-top: 0px;margin-top: 0px"></table>
                            </div>
                        </div>

                        <!-- 右侧悬浮按钮 -->
                        <div class="right-bottom-btn">
                            <button type="button" class="layui-btn" lay-filter="viewRwsBtn">
                                <i class="layui-icon layui-icon-file"></i>查看任务书
                            </button>
                            <!--                            <button type="button" class="layui-btn" lay-filter="spListBtn">-->
                            <!--                                <i class="layui-icon layui-icon-file-b"></i>审批列表-->
                            <!--                            </button>-->
                            <button type="button" class="layui-btn" lay-submit lay-filter="saveBtn">
                                <i class="layui-icon layui-icon-ok"></i>保存
                            </button>
                            <button class="layui-btn" lay-filter="cancleBtn">
                                <i class="layui-icon layui-icon-close"></i>取消
                            </button>
                        </div>
                    </div>
                </form>
            </div>
            <!--常规结束-->
            <!--其它信息开始-->
            <div class="layui-tab-item" style="height: 550px">
                <form class="layui-form" action="" lay-filter="formDemo">
                    <div class="layui-form layuimini-form" style="padding-bottom: 100px">
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 85px">ERP编号</label>
                            <div class="layui-input-inline" style="width: 845px">
                                <input type="text" id="erpbh" name="erpbh" class="layui-input"
                                       th:value="${project.erpbh}" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 85px">项目类型</label>
                            <div class="layui-input-inline" style="width: 845px">
                                <input type="hidden" id="xmlx" name="xmlx" class="layui-input"
                                       th:value="${project.xmlx}">
                                <input type="text" id="xmlxmc" name="xmlxmc" class="layui-input"
                                       th:value="${project.xmlxmc}" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 85px">项目负责人</label>
                            <div class="layui-input-inline" style="width: 845px">
                                <input type="hidden" id="xmfzr" name="xmfzr" class="layui-input"
                                       th:value="${project.xmfzr}">
                                <input type="text" id="xmfzrxm" name="xmfzrxm" class="layui-input"
                                       th:value="${project.xmfzrxm}" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 85px">电科院负责人</label>
                            <div class="layui-input-inline" style="width: 845px">
                                <input type="hidden" id="dkyfzr" name="dkyfzr" class="layui-input"
                                       th:value="${project.dkyfzr}">
                                <input type="text" id="dkyfzrxm" name="dkyfzrxm" class="layui-input"
                                       th:value="${project.dkyfzrxm}" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 85px">所属部门</label>
                            <div class="layui-input-inline" style="width: 845px">
                                <input type="hidden" id="ssbm" name="ssbm" class="layui-input"
                                       th:value="${project.ssbm}">
                                <input type="text" id="ssbmmc" name="ssbmmc" class="layui-input"
                                       th:value="${project.ssbmmc}" readonly>
                            </div>
                        </div>

                        <!-- 右侧悬浮按钮 -->
                        <div class="right-bottom-btn">
                            <button type="button" class="layui-btn" lay-filter="viewBtn">
                                <i class="layui-icon layui-icon-ok"></i>查看任务书
                            </button>
                            <button type="button" class="layui-btn" lay-submit lay-filter="saveBtn">
                                <i class="layui-icon layui-icon-ok"></i>保存
                            </button>
                            <button class="layui-btn" lay-filter="cancleBtn">
                                <i class="layui-icon layui-icon-close"></i>取消
                            </button>
                        </div>
                    </div>
                </form>
            </div>
            <!--其它信息结束-->
        </div>
    </div>
</form>

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

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

    layui.use(['form', 'table', 'treeTable', 'layCascader', 'tableSelect', 'laydate'], function () {
        var form = layui.form,
            table = layui.table,
            layer = layui.layer,
            laydate = layui.laydate,
            tableSelect = layui.tableSelect;
        var fyId = -1;

        //费用类别
        tableSelect.render({
            elem: '#fylbmc',
            checkedKey: 'id',
            searchKey: 'mc',
            searchPlaceholder: '搜索费用名称',
            table: {
                url: AjaxUtil.ctx + 'baseProjectbudget/yslist/' + $("#xmid").val(),
                method: 'post',
                cols: [
                    [
                        {type: "radio", fixed: 'left'},
                        {type: 'numbers', align: 'center'},
                        {field: 'mc', width: '60%', title: '费用名称'},
                        {field: 'xmlxmc', title: '项目类型'}
                    ]
                ]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                var NEWJSON1 = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.mc);
                    NEWJSON1.push(item.id);
                })
                elem.val(NEWJSON.join(","));
                $("#fylb").val(NEWJSON1.join(","));
            }
        });
        // 申请人
        tableSelect.render({
            elem: '#sqrxm',
            checkedKey: 'id',
            searchKey: 'xm',
            searchPlaceholder: '搜索姓名',
            table: {
                url: AjaxUtil.ctx + 'basePerson/rylist',
                cols: [
                    [
                        {type: "radio", fixed: 'left'},
                        {type: 'numbers', align: 'center'},
                        {field: 'xm', width: '15%', title: '姓名', align: 'left'},
                        {field: 'dwmc', title: '公司/单位', align: 'left'}
                    ]
                ]
            },
            done: function (elem, data) {
                var NEWJSON = [];
                var NEWJSON1 = [];
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.xm);
                    NEWJSON1.push(item.id);
                })
                elem.val(NEWJSON.join(","));
                $("#sqr").val(NEWJSON1.join(","));
            }
        });
        //申请时间
        laydate.render({
            elem: '#sqsj',
            value: new Date()
        });

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

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

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

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

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

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

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

        // 用于存放表格数据
        var dataFj = new Array();
        //附件
        var currTable2 = table.render({
            elem: '#currentTableId2',
            data: dataFj,
            cols: [
                [
                    {type: 'numbers', align: 'center'},
                    {type: "checkbox", align: 'center'},
                    {field: 'wjm', title: '文件名', width: '30%'},
                    {field: 'scrq', title: '上传日期', width: '20%'},
                    {field: 'sm', title: '说明'},
                ]
            ]
        });

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

        // 监听确认按钮
        form.on('submit(saveBtn)', function (data) {
            var url = AjaxUtil.ctx;
            if (fyId == -1)
                url += "staBudgetapproval/doAddApply";
            else
                url += "staBudgetapproval/doUpdateApply";

            console.log(data.field);
            //基本信息
            var index = layer.load(0, {shade: 0.1});
            AjaxUtil.post({
                url: url,
                data: data.field,
                success: function (res) {
                    layer.close(index);
                    console.log(res);
                    if (res.code === 0) {
                        Message.success(1500, res.message, function () {
                            if (fyId == -1) {
                                fyId = res.data.id;
                                $("#id").val(fyId);
                            }
                            parent.setUpdateFlag();

                            //差旅费
                            var travleExpenses = [];
                            var oldExpenses = table.cache["currentTableId1"];
                            for (const item of oldExpenses) {
                                var expense = {
                                    "zb": fyId,
                                    "xh": item.xh,
                                    "ccr": item.ccr,
                                    "ccdd": item.ccdd,
                                    "qsrq": item.qsrq,
                                    "jtf": item.jtf,
                                    "zsf": item.zsf,
                                    "cb": item.cb,
                                    "jsrq": item.jsrq,
                                    "ccts": item.ccts,
                                    "zj": item.zj,
                                    "rpj": item.rpj
                                };
                                travleExpenses.push(expense);
                            }
                            //保存差旅费
                            AjaxUtil.post({
                                url: AjaxUtil.ctx + "staTravelexpenses/batchInsert/" + fyId,
                                contentType: "application/json",
                                data: JSON.stringify(travleExpenses),
                                success: function (res) {
                                    if (res.code === 0) {
                                        // Message.success(1500, res.message, function () {
                                        //
                                        // });
                                    } else {
                                        // Message.error(res.message, 1000);
                                    }
                                },
                                error: function (error) {
                                }
                            });
                        });
                    } else {
                        Message.error(res.message, 1000);
                    }
                },
                error: function (error) {
                    layer.close(index);
                }
            });
            return false;
        });


        // 项目负责人
        // tableSelect.render({
        //     elem: '#xmfzrxm',
        //     checkedKey: 'id',
        //     searchKey: 'xm',
        //     searchPlaceholder: '搜索姓名',
        //     table: {
        //         url: AjaxUtil.ctx + 'basePerson/rylist',
        //         cols: [
        //             [
        //                 {type: "radio", fixed: 'left'},
        //                 {type: 'numbers', align: 'center'},
        //                 {field: 'xm', width: '15%', title: '姓名', align: 'left'},
        //                 {field: 'dwmc', title: '公司/单位', align: 'left'}
        //             ]
        //         ]
        //     },
        //     done: function (elem, data) {
        //         var NEWJSON = [];
        //         var NEWJSON1 = [];
        //         layui.each(data.data, function (index, item) {
        //             NEWJSON.push(item.xm);
        //             NEWJSON1.push(item.id);
        //         })
        //         elem.val(NEWJSON.join(","));
        //         $("#xmfzr").val(NEWJSON1.join(","));
        //     }
        // });
        // //电科院负责人
        // tableSelect.render({
        //     elem: '#dkyfzrxm',
        //     checkedKey: 'id',
        //     searchKey: 'xm',
        //     searchPlaceholder: '搜索姓名',
        //     table: {
        //         url: AjaxUtil.ctx + 'basePerson/rylist',
        //         cols: [
        //             [
        //                 {type: "checkbox", fixed: 'left'},
        //                 {type: 'numbers', align: 'center'},
        //                 {field: 'xm', width: '15%', title: '姓名', align: 'left'},
        //                 {field: 'dwmc', title: '公司/单位', align: 'left'}
        //             ]
        //         ]
        //     },
        //     done: function (elem, data) {
        //         var NEWJSON = [];
        //         var NEWJSON1 = [];
        //         layui.each(data.data, function (index, item) {
        //             NEWJSON.push(item.xm);
        //             NEWJSON1.push(item.id);
        //         })
        //         elem.val(NEWJSON.join(","));
        //         $("#dkyfzr").val(NEWJSON1.join(","));
        //     }
        // });
        // //所属部门
        // var 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) {
        //         layer.close(index);
        //     }
        // });

        // 监听确认按钮（其它信息）
        // $("button[lay-filter='saveBtn']").click(function(){
        //     if(fyId == -1) {
        //         Message.error("请先创建费用申请，然后再保存其它信息",2000);
        //     } else {
        //         var fyApproval = {
        //             "id": fyId,
        //             "erpbh": $("#erpbh").val(),
        //             "xmlx": $("#xmlx").val(),
        //             "xmfzr": $("#xmfzr").val(),
        //             "ssbm": $("#ssbm").val()
        //         }
        //         var index = layer.load(0, {shade: 0.1});
        //         AjaxUtil.post({
        //             url: AjaxUtil.ctx + "staBudgetapproval/doUpdate2",
        //             contentType: "application/json",
        //             data: JSON.stringify(fyApproval),
        //             success: function (res) {
        //                 if (res.code === 0) {
        //                     Message.success(1500, res.message, function () {
        //                         parent.setUpdateFlag();
        //                     });
        //                 } else {
        //                     Message.error(res.message, 1000);
        //                 }
        //                 layer.close(index);
        //             },
        //             error: function (error) {
        //                 layer.close(index);
        //             }
        //         });
        //     }
        // });

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

    /**
     *  扁平数据转树结构
     * @returns {[]}
     * @param data
     * @param firstPid
     */
    function arrayToTree(data, firstPid) {
        const result = [];
        getChildren(data, result, firstPid);
        return result;
    }

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

    function setTravelExpense(expense) {
        travelExpense = expense;
    }

    function getTravelExpense() {
        return travelExpense;
    }

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