<!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-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: 15%">年度费用已报账</label>
            <div class="layui-input-inline" style="width: 70%">
                <input type="hidden" id="rws" name="rws" class="layui-input" lay-verify="required"
                       lay-reqtext="任务书不能为空">
                <input type="hidden" id="rwsmc" name="rwsmc" class="layui-input">
                <select name="ysrws" id="ysrws" lay-filter="ysrws">
                    <option value="">-- 请选择年度预算 --</option>
                    <option value="-1">[浏览]</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item layui-inline" style="width: 100%">
            <label class="layui-form-label required" style="width: 15%">费用类别</label>
            <div class="layui-input-inline" style="width: 70%">
                <input type="hidden" id="fjmc" name="fjmc" class="layui-input">
                <input type="hidden" id="fylb" name="fylb" class="layui-input">
                <input type="text" id="fylbmc" name="fylbmc" lay-verify="required"
                       lay-reqtext="费用类别不能为空" class="layui-input" placeholder="请选择费用类别..." readonly>
            </div>
        </div>
        <div class="layui-form-item layui-inline" style="width: 100%">
            <label class="layui-form-label required" style="width: 15%">合同</label>
            <div class="layui-input-inline" style="width:30%">
                <input type="hidden" id="htmc" name="htmc" class="layui-input" lay-verify="required"
                       lay-reqtext="合同名称不能为空">
                <input type="hidden" id="htes" name="htes" class="layui-input">
                <select name="ht" id="ht" lay-filter="ht" lay-verify="required" lay-reqtext="合同不能为空" lay-search=“”>
                    <option value="">-- 请选择合同 --</option>
                    <option value="-1">[浏览]</option>
                 </select>
            </div>
            <label class="layui-form-label required" style="width: 10%">合同金额(万元)</label>
            <div class="layui-input-inline" style="width: 25%">
                <input type="number" id="htje" name="htje" class="layui-input" lay-verify="required"
                       lay-reqtext="合同金额不能为空" autocomplete="off" placeholder="请填入合同金额..." readonly>
            </div>
        </div>
        <div class="layui-form-item layui-inline" style="width: 100%">
            <label class="layui-form-label required" style="width: 15%">付款计划</label>
            <div class="layui-input-inline" style="width: 30%">
                <select name="fkjh" id="fkjh" lay-filter="fkjh" lay-verify="required" lay-reqtext="付款计划不能为空">
                    <option value="">-- 请先选择合同，再选择付款计划 --</option>
                </select>
            </div>
            <label class="layui-form-label required" style="width: 10%;">本次付款金额(万元)</label>
            <div class="layui-input-inline" style="width: 25%">
                <input type="number" id="bcfkje" name="bcfkje" class="layui-input" lay-verify="required" lay-affix="number" placeholder="请填入本次付款金额..."
                       lay-reqtext="本次付款金额不能为空" autocomplete="off">
            </div>
        </div>
        <div class="layui-form-item layui-inline" style="width: 100%">
            <label class="layui-form-label" style="width: 15%">合同文件</label>
            <div class="layuimini-container" style="margin-left: 90px; margin-right: 20px; padding-bottom: 10px">
                <input type="hidden" id="htwj" name="htwj" class="layui-input">
                <div class="layui-btn-group" style="margin-bottom: -8px">
                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm upload" id="upLoad1"
                            lay-data="{fileType:'payhtwj'}"><i class="layui-icon"></i>上传
                    </button>
                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm upload" id="upLoad3"
                            lay-data="{fileType:'payhtwj'}"><i class="layui-icon"></i>上传
                    </button>
                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm" lay-filter="deleteFile1"><i
                            class="layui-icon"></i>删除
                    </button>
                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm" lay-filter="btnView2"><i
                            class="layui-icon">&#xe63c;</i>查看
                    </button>
                </div>
                <table class="layui-hide" id="currentTableId1" name="currentTableId1" lay-filter="currentTableFilter1"
                       style="padding-top: 0px;margin-top: 0px"></table>
                <label>请在合同管理中修改文件</label>
            </div>
        </div>
        <div class="layui-form-item layui-inline" style="width: 100%">
            <label class="layui-form-label" style="width: 15%">验收资料</label>
            <div class="layuimini-container" style="margin-left: 90px; margin-right: 20px; padding-bottom: 10px">
                <input type="hidden" id="yszl" name="yszl" class="layui-input">
                <div class="layui-btn-group" style="margin-bottom: -8px">
                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm upload" id="upLoad2"
                            lay-data="{fileType:'payyszl'}"><i class="layui-icon"></i>上传
                    </button>
                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm" lay-filter="deleteFile2"><i
                            class="layui-icon"></i>删除
                    </button>
                    <button type="button" class="layui-btn  layui-btn-primary layui-btn-sm" lay-filter="btnView2"><i
                            class="layui-icon">&#xe63c;</i>查看
                    </button>
                </div>
                <table class="layui-hide" id="currentTableId2" name="currentTableId2" lay-filter="currentTableFilter2"
                       style="padding-top: 0px;margin-top: 0px"></table>
                <label>需上传合同约定的技术报告、测试报告、第三方检测报告、图纸、文宣专利等乙方应提供成果；外委验收意见（包括完成情况表及专家签名）。</label>
            </div>
        </div>


        <!-- 右侧悬浮按钮 -->
        <div class="right-bottom-btn">
            <button type="button" class="layui-btn" lay-submit lay-filter="saveBtn">
                <i class="layui-icon layui-icon-ok"></i>保存
            </button>
            <button type="button" class="layui-btn" lay-filter="cancleBtn">
                <i class="layui-icon layui-icon-close"></i>取消
            </button>
        </div>
    </div>
</form>
<script>
    var bcfkje = document.getElementById('bcfkje').value;
    if (bcfkje < 0){
        layer.msg('本次付款金额不能小于0.00！',{icon: 2});
        document.getElementById('bcfkje').value == '';
    }else if (bcfkje == 0){
        layer.msg('本次付款金额不能等于0.00',{icon:2});
    }
</script>

<script th:src="@{/lib/jquery-3.4.1/jquery-3.4.1.min.js}" charset="utf-8"></script>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/lib/coco-message/coco-message.js}" charset="utf-8"></script>
<script th:src="@{/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 th:src="@{/lib/sweetalert/sweetalert-master/docs/assets/sweetalert/sweetalert.min.js}" charset="utf-8"></script>

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

    layui.use(['form', 'table', 'upload','tableSelect'], function () {
        var form = layui.form,
            table = layui.table,
            layer = layui.layer,
            upload = layui.upload,
            tableSelect = layui.tableSelect;
        var xmApproval = parent.getXmApproval();
        let htList = ' ';
        var ysId = 1;
        $("#fysq").val(xmApproval.fysq);
        $("#fysqmc").val(xmApproval.fysqmc);
        $("#rws").val(xmApproval.rws);
        $("#rwsmc").val(xmApproval.rwsmc);

        // 用于存放验收资料文件
        var dataYszl = new Array();

        // 用于存放合同文件
        var dataHtwj = new Array();

        //监听合同
        form.on('select(ht)', function (data) {
            var rws = document.getElementById('rwsmc').value;
            if (rws === null){
                layer.msg('请先选择任务书！');
                return false;

            }
            var len = $("#fkjh")[0].length;
            console.log('len'+len);
            while (len > 1) {
                $("#fkjh")[0].options[--len].remove();
            }

            if (data.value == "") {
                $("#htje").val("");
            } else {
                var htList = [[${htList}]];
                for (let ht of htList) {
                    if (ht.id == data.value) {
                        $("#htje").val(ht.htje);
                        var wj = JSON.parse(ht.wj);
                        var yszl = JSON.parse(ht.yszl);
                        dataHtwj.splice(0, dataHtwj.length)
                        dataYszl.splice(0, dataYszl.length)
                        dataHtwj.push.apply(dataHtwj, wj);
                        dataYszl.push.apply(dataYszl, yszl);
                        console.log(currTable1)
                        currTable1.reload();
                        currTable2.reload();
                        break;
                    }
                }
                $.ajax({
                    url: AjaxUtil.ctx + 'prjPayplan/list/' + data.value,
                    type: "post",
                    async: false,
                    dataType: "json",
                    success: function (result) {
                        while (len > 1)
                            $("#fkjh")[0].options[--len].remove();

                        var dataFkjh = result.data.rows;
                        for (let item of dataFkjh) {
                            $("#fkjh").append("<option value=" + item.id + ">" + item.jhmc + " / " + item.zfje + "</option>");
                        }
                    }
                });
            }
            $("#fkjh").val(0);
            form.render('select');

            return false;
        });

        // 用于存放验收资料文件
        var dataYszl = new Array();

        // 用于存放合同文件
        var dataHtwj = new Array();
        //任务书
        form.on('select(ht)', function (data) {

            var rws = document.getElementById('rwsmc').value;
            if (rws === null || rws == ''){
                layer.msg('请先选择已报账费用申请！');
                return false;
            }
            var xmmc = localStorage.getItem("xmmc");
            xmmc = xmmc.replace(/[\/\\]/g, '_');
            if (data.value == "-1") {
                parent.layer.open({
                    title: '浏览任务书',
                    type: 2,
                    shade: 0.3,
                    maxmin: true,
                    area: ['1200px', '750px'],
                    content: AjaxUtil.ctx + 'staPayapproval/init_projects/'+xmmc,
                    end: function (obj) {
                        rwsId = localStorage.getItem("rws");
                        var updateflag = localStorage.getItem("updateflag");
                        if (updateflag == "1") {
                            document.getElementById('htje').value = localStorage.getItem('htje');
                            var htmc = localStorage.getItem("htmc");
                            htmc = htmc.replace(/[\/\\]/g, '_');
                            var id = localStorage.getItem("id");
                            $("#ht").append("<option value=" + id + " selected>" + htmc + "</option>");
                            document.getElementById('htmc').value = localStorage.getItem('htmc');
                            var wjString = localStorage.getItem("wj");
                            var yszlString = localStorage.getItem("yszl");
                            var wj = JSON.parse(wjString);
                            var yszl = JSON.parse(yszlString);

                            dataHtwj.splice(0, dataHtwj.length);
                            dataYszl.splice(0, dataYszl.length);
                            dataHtwj.push.apply(dataHtwj, wj);
                            dataYszl.push.apply(dataYszl, yszl);

                            console.log(currTable1);
                            currTable1.reload();
                            currTable2.reload();


                            $.ajax({
                                url: AjaxUtil.ctx + 'prjPayplan/list/'+id,
                                type: "post",
                                async: false,
                                dataType: "json",
                                success: function (result) {
                                    var dataFkjh = result.data.rows;
                                    console.log('list'+result);
                                    // 假设data是包含合同数据的数组
                                    // 通过id获取select元素的DOM对象
                                    console.log(dataFkjh);
                                    var selectElement = document.getElementById('fkjh');
                                    // 清空select元素的选项
                                    selectElement.innerHTML = '';
                                    // 添加一个默认的“请选择”选项
                                    var defaultOption = document.createElement('option');
                                    defaultOption.value = '';
                                    defaultOption.innerText = '请选择';
                                    defaultOption.selected = true; // 设置为默认选中
                                    selectElement.appendChild(defaultOption);
                                    // 遍历数据，创建并添加option元素到select元素中
                                    dataFkjh.forEach(function(item) {
                                        var optionElement = document.createElement('option');
                                        optionElement.value = item.id;
                                        console.log(item.yfkje)
                                        if (item.yfkje==item.zfje){
                                            optionElement.disabled = true; // 设置为不可选择
                                        }else if (item.yfkje>item.zfje){
                                            optionElement.disabled = true; // 设置为不可选择
                                            alert('该合同下名称为'+item.jhmc+'的付款计划关联的付款申请，总付款额大于付款计划金额，已付款金额为'+item.yfkje+'万元，请联系系统管理员处理该问题！！')
                                        }
                                        if (item.yfkje==null){
                                            item.yfkje = 0
                                        }
                                        optionElement.innerText = item.jhmc+' / '+item.zfje+'/'+item.yfkje;
                                        selectElement.appendChild(optionElement);
                                    });
                                }
                            });

                        } else {
                            $("#ht").val(0);
                            $("#htes").val('');
                            $("#hts").val('');
                            $("#htes").val('');
                        }
                        form.render();
                    }
                });
            }

            return false;
        });
        //任务书
        form.on('select(ysrws)', function (data) {
            var len = $("#ysrws")[0].length;
            while (len > 2)
                $("#ysrws")[0].options[--len].remove();
            if (data.value == "") {
                $("#ysrws").val(0);
                $("#rws").val('');
                $("#rwsmc").val('');
                $("#qs").val('');
                $("#wc").val('');
                $("#xmzxq").val('');
                $("#xmmc").val('');
                $("#erpbh").val('');
                $("#xmlx").val('');
                $("#xmlxmc").val('');
                $("#xmfzr").val('');
                $("#xmfzrxm").val('');
                $("#ssbm").val('');
                $("#ssbmmc").val('');
                $("#rwsys").val('');
                form.render();
            }

            if (data.value == "-1") {
                parent.layer.open({
                    title: '浏览任务书',
                    type: 2,
                    shade: 0.3,
                    maxmin: true,
                    area: ['1200px', '750px'],
                    content: AjaxUtil.ctx + 'staPayapproval/init_project',
                    end: function (obj) {
                        rwsId = localStorage.getItem("rws");
                        var updateflag = localStorage.getItem("updateflag");
                        if (updateflag == "1") {
                            var rwsmc = localStorage.getItem("xmmc");
                            var fysqid = localStorage.getItem("id");
                            $("#ysrws").append("<option value=" + fysqid + " selected>" + rwsmc + "</option>");
                            $("#rws").val(fysqid);
                            $("#rwsmc").val(rwsmc);
                            $("#fysqmc").val(localStorage.getItem("fysqmc"));
                            $('#fysq').val(fysqid);
                            localStorage.setItem("fyId", fysqid);
                            console.log('这个NYSid是'+fysqid);
                            tableSelect.render({
                                elem: '#fylbmc',
                                checkedKey: 'id',
                                searchKey: 'mc',
                                searchPlaceholder: '搜索费用名称',
                                table: {
                                    url: AjaxUtil.ctx + 'staBudgetapproval/getFyBz/' + fysqid +'/?searchKey='+tableSelect.searchKey,
                                    method: 'get',
                                    cols: [
                                        [
                                            {type: "radio", fixed: 'left',title: '😊'},
                                            {type: 'numbers', align: 'center',title: '序号'},
                                            {field: 'fymc', width: '25%', title: '费用名称'},
                                            {title: '报账总金额(万元)',align: 'right',width: '20%',templet:function (row) {
                                                if (row.bzze == ' '){
                                                    return 0.00;
                                                }else if (row.bzze == null){
                                                    return 0.00;
                                                }else {
                                                    return  parseFloat(row.bzze).toFixed(2).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
                                                }
                                                }},
                                            {title: '已付总额(万元)',width: '20%',align: 'right',templet:function (row) {
                                                if (row.yfze == null || row.yfze == ' '){
                                                    return 0.00;
                                                }
                                                return row.yfze.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });

                                                }},
                                            {title: '可申请额度(万元)',align: 'right',width: '20%',templet:function (row) {
                                                    const bzze = parseFloat(row.bzze);
                                                    const yfze = parseFloat(row.yfze);
                                                    if (isNaN(bzze) || isNaN(yfze)) {
                                                        return 0.00;
                                                    }

                                                    const bzzeFormatted = bzze.toFixed(2);
                                                    const yfzeFormatted = yfze.toFixed(2);

                                                    const ye = bzzeFormatted - yfzeFormatted;
                                                    console.log('ye:'+ye);
                                                    if (ye > 0) {
                                                        return parseFloat(ye.toFixed(2)).toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 });
                                                    }
                                                    return 0.00;
                                                }
                                            }
                                        ]
                                    ]
                                },
                                done: function (elem, data) {
                                    var NEWJSON = [];
                                    var NEWJSON1 = [];
                                    var NEWJSON2 = [];
                                    var NEWJSON3 = [];
                                    layui.each(data.data, function (index, item) {
                                        NEWJSON.push(item.fymc);
                                        NEWJSON1.push(item.id);
                                        NEWJSON2.push(item.fjmc);
                                        NEWJSON3.push(item.ysje);
                                    })
                                    elem.val(NEWJSON.join(","));
                                    $("#fylb").val(NEWJSON1.join(","));
                                    $("#fjmc").val(NEWJSON2.join(","));
                                    // 假设 tableSelect 实例挂载在 window 下某个变量，尝试关闭
                                    if (typeof window.tableSelectInstance === 'object') {
                                        window.tableSelectInstance.close();

                                    }
                                }
                            });
                        } else {
                            $("#ysrws").val(0);
                            $("#rws").val('');
                            $("#rwsmc").val('');
                            $("#fysqmc").val('');
                        }
                        form.render();
                    }
                });
            }
            return false;
        });
        $("#bcfkje").blur(function (e) {
            var bcfkje = parseFloat(e.delegateTarget.value);

            if (bcfkje <= 0) {
                layer.msg('金额不能为负数或0的数字，请重新输入！',{icon:2});
                e.delegateTarget.value = "";
            }else if (bcfkje > 1000){
                layer.msg('本次付款金额单位为万元，请确认当前数据无误。',{icon:2});
            }
        });
        //合同文件
        var currTable1 = table.render({
            elem: '#currentTableId1',
            data: dataHtwj,
            cols: [
                [
                    {type: "checkbox", align: 'center'},
                    {type: 'numbers', align: 'center',title: '序号'},
                    {field: 'wjm', title: '文件名', width: '30%'},
                    {field: 'scrq', title: '上传日期', width: '15%', align: 'center'},
                    {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为数据渲染完的回调

                console.log('currTable1渲染弯沉')
                console.log(dataHtwj)
            }
        });

        //文件上传
        upload.render({
            elem: '#upLoad1' //绑定元素
            , url: AjaxUtil.ctx + 'fileupload/upload'
            , methd: 'post'
            , accept: 'file'
            , multiple: true // 允许批量上传
            , data: {}
            , done: function (res) {
                if (0 === res.code) {
                    var curData = {
                        "wjm": res.data.fileName,
                        "scrq": res.data.fileDate,
                        "Url": res.data.fileUrl,
                        "sm": res.data.sm
                    };
                    dataHtwj.push(curData);
                    currTable1.reload();
                    layer.msg('"'+res.data.fileName+'"'+'上传成功!', { icon: 1 });
                } else
                    layer.alert("上传文件出现错误！");
            }
            , error: function () {
                layer.alert("上传文件出现错误！");
            }
            , before: function (res) {
                let fileType = this.fileType;
                this.data.fileType = fileType;
            }
        });
        $("button[lay-filter='deleteFile1']").click(function () {
            if (dataHtwj.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 < dataHtwj.length; i++) {
                var item = dataHtwj[i];
                if (item.LAY_CHECKED) {//条件：选中
                    dataHtwj.splice(i, 1);//移除后后造成数组下标索引发生变化，所以下面需要i--
                    i--;
                }
            }
            //刷新表格
            currTable1.reload();
        });
        //双击（合同文件）
        table.on('rowDouble(currentTableFilter1)', function (obj) {
            window.open(obj.data.Url);
        });


        //验收资料
        var currTable2 = table.render({
            elem: '#currentTableId2',
            data: dataYszl,
            cols: [
                [
                    {type: "checkbox", align: 'center'},
                    {type: 'numbers', align: 'center',title: '序号'},
                    {field: 'wjm', title: '文件名', width: '30%'},
                    {field: 'scrq', title: '上传日期', width: '15%', align: 'center'},
                    {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为数据渲染完的回调
                console.log('currTable2渲染弯沉')
            }
        });

        //文件上传
        upload.render({
            elem: '#upLoad2' //绑定元素
            , url: AjaxUtil.ctx + 'fileupload/upload'
            , methd: 'post'
            , accept: 'file'
            , data: {}
            , done: function (res) {
                if (0 === res.code) {
                    var curData = {
                        "wjm": res.data.fileName,
                        "scrq": res.data.fileDate,
                        "Url": res.data.fileUrl,
                        "sm": res.data.sm
                    };
                    dataYszl.push(curData);
                    currTable2.reload();
                    layer.msg('"'+res.data.fileName+'"'+'上传成功!', { icon: 1 });
                } else
                    layer.alert("上传文件出现错误！");
            }
            , error: function () {
                layer.alert("上传文件出现错误！");
            }
            , before: function (res) {
                let fileType = this.fileType;
                this.data.fileType = fileType;
            }
        });
        $("button[lay-filter='deleteFile2']").click(function () {
            if (dataYszl.length == 0)
                return;

            var checkStatus = table.checkStatus('currentTableId2')
                , data = checkStatus.data;
            if (data == null || data.length === 0) {
                Message.warning("请选择要删除的文件！", 1000);
                return;
            }
            for (var i = 0; i < dataYszl.length; i++) {
                var item = dataYszl[i];
                if (item.LAY_CHECKED) {//条件：选中
                    dataYszl.splice(i, 1);//移除后后造成数组下标索引发生变化，所以下面需要i--
                    i--;
                }
            }
            //刷新表格
            currTable2.reload();
        });
        $("button[lay-filter='deleteFile1']").click(function () {
            if (dataHtwj.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 < dataHtwj.length; i++) {
                var item = dataHtwj[i];
                if (item.LAY_CHECKED) {//条件：选中
                    dataHtwj.splice(i, 1);//移除后后造成数组下标索引发生变化，所以下面需要i--
                    i--;
                }
            }
            //刷新表格
            currTable1.reload();
        });
        //双击（验收资料）
        table.on('rowDouble(currentTableFilter2)', function (obj) {
            window.open(obj.data.Url);
        });

        // 监听确认按钮
        form.on('submit(saveBtn)', function (data) {
            const  htje = document.getElementById('htje').value;
            var selectElement = document.getElementById("fkjh");
            var selectedText = selectElement.options[selectElement.selectedIndex].text.split('/');
            const bcfkje = parseFloat(document.getElementById('bcfkje').value);
           /* const fysq = document.getElementById('fysq').value;*/
            var fkje;
            var bzje;
            console.log(selectedText[1].replace(/\s+/g, ''))
            console.log(selectedText[2].replace(/\s+/g, ''))
            if (bcfkje > selectedText[1].replace(/\s+/g, '')){
                layer.msg('本次付款金额，不能大于付款计划金额！',{icon:2});
                return ;
            }
            if (bcfkje+parseFloat(selectedText[2].replace(/\s+/g, ''))>selectedText[1].replace(/\s+/g, '')){
                layer.msg('该付款计划下已申请付款金额加上本次付款金额，大于付款计划金额！',{icon:2});
                return ;
            }
/*            $.ajax({
                url: AjaxUtil.ctx + 'staPayapproval/getYFKJE/'+fysq,
                type: "post",
                async: false,
                dataType: "json",
                success: function (result) {
                    console.log(result);
                    fkje = result.fkje
                    bzje = result.bzje
                    }
                })
            if ( (fkje+bcfkje) > bzje){
                Message.warning('该报账下付款申请已申请总金额已超出报账金额!',2000);
                return ;
            }*/
            //合同文件
            var dataWB_Htwj = [];
            for (const item of dataHtwj) {
                var dfWb = {
                    "id": item.id,
                    "wjm": item.wjm,
                    "Url": item.Url,
                    "scrq": item.scrq,
                    "sm": item.sm
                };
                dataWB_Htwj.push(dfWb);
            }
            $("#htwj").val(JSON.stringify(dataWB_Htwj));
            data.field.htwj = JSON.stringify(dataWB_Htwj);
            console.log(data.field);

            //验收资料
            var dataWB_Yszl = [];
            for (const item of dataYszl) {
                var dfWb = {
                    "id": item.id,
                    "wjm": item.wjm,
                    "Url": item.Url,
                    "scrq": item.scrq,
                    "sm": item.sm
                };
                dataWB_Yszl.push(dfWb);
            }
            $("#yszl").val(JSON.stringify(dataWB_Yszl));
            data.field.yszl = JSON.stringify(dataWB_Yszl);
            console.log(data.field);

            var index = layer.load(0, {shade: 0.1});
            AjaxUtil.post({
                url: AjaxUtil.ctx + "staPayapproval/doAdd",
                data: data.field,
                success: function (res) {
                    if (res.code == 0) {
                        layer.msg(res.message,{icon:1},function () {
                            parent.setUpdateFlag();
                            layer.close(index);
                        });
                    } else {
                        layer.msg(res.message,{icon:2});
                        return ;
                    }
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                },
                error: function (error) {
                    Message.error(error.message, 1000)
                }
            });

            return false;
        });

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

    function setTravelExpense(expense) {
        travelExpense = expense;
    }

    function getTravelExpense() {
        return travelExpense;
    }

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