فهرست منبع

报销功能调整

徐滕 3 روز پیش
والد
کامیت
1221e2ae19

+ 43 - 0
src/main/java/com/jeeplus/modules/workreimbursement/utils/DateTimeUtil.java

@@ -0,0 +1,43 @@
+package com.jeeplus.modules.workreimbursement.utils;
+
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.util.Date;
+
+public class DateTimeUtil {
+    // 公共静态常量:目标日期(2025年10月1日)
+    public static final LocalDate TARGET_DATE = LocalDate.of(2025, 10, 1);
+
+    /**
+     * 判断当前日期是否在目标日期(2025年10月1日)之后
+     * @return 如果当前日期在目标日期之后,返回true;否则返回false
+     */
+    public static boolean isAfterOctoberFirst() {
+        // 获取当前日期
+        LocalDate currentDate = LocalDate.now();
+        // 比较当前日期是否在目标日期之后
+        return currentDate.isAfter(TARGET_DATE);
+    }
+
+
+    /**
+     * 判断传入的日期是否在目标日期(2025年10月1日)之后
+     * @param date 需要判断的日期(不能为null)
+     * @return 如果传入日期在目标日期之后,返回true;否则返回false
+     * @throws IllegalArgumentException 如果传入的日期为null
+     */
+    public static boolean isAfterOctoberFirstOnDate(Date date) {
+        // 检查参数是否为null
+        if (date == null) {
+            throw new IllegalArgumentException("传入的日期不能为null");
+        }
+
+        // 将Date转换为LocalDate(使用系统默认时区)
+        LocalDate inputDate = date.toInstant()
+                .atZone(ZoneId.systemDefault())
+                .toLocalDate();
+
+        // 比较日期
+        return inputDate.isAfter(TARGET_DATE);
+    }
+}

+ 184 - 23
src/main/webapp/webpage/modules/workreimbursement/treeForm/all/workReimbursementAllFormAdd.jsp

@@ -259,7 +259,7 @@
                                     "</td>" +
 
                                     "<td>" +
-                                    "<input id='workAccountList" + index + "_eInvoiceMoney' onchange='calculateSum(" + index + ")' style='background-color: #f5f5f5' readonly name='workAccountList[" + index + "].eInvoiceMoney' type='text' value='" + (obj.eInvoiceMoney === null || obj.eInvoiceMoney === undefined ? "" : obj.eInvoiceMoney) + "' placeholder='数电发票金额' maxlength='10'  class='form-control number'/>" +
+                                    "<input id='workAccountList" + index + "_eInvoiceMoney' onchange='calculateSum(" + index + ")' name='workAccountList[" + index + "].eInvoiceMoney' type='text' value='" + (obj.eInvoiceMoney === null || obj.eInvoiceMoney === undefined ? "" : obj.eInvoiceMoney) + "' placeholder='数电发票金额' maxlength='10'  class='form-control number'/>" +
                                     "</td>" +
 
                                     "<td>" +
@@ -301,7 +301,7 @@
                                 var subsetId="workAccountList_"+ obj.id;
 
                                 $("#workAccountList").append("<tr class='"+obj.id+"' style='display: none;'> <td colspan='15' style='padding: 0px;'>" +
-                                    "<table style=\"width: 100%;padding: 0px;margin: 0px;\" class=\"table table-condensed details\">" +
+                                    "<table style=\"width: 100%;padding: 0px;margin: 0px;\" class=\"table table-bordered table-condensed details\">" +
                                     "<tbody id='"+subsetId+"'>" +
                                     "<input type='text' id='"+subsetId+"_len' style='display: none;' name='flags' />"+
                                     "</tbody>" +
@@ -329,6 +329,8 @@
                                         //遍历 添加数据
                                         $.each(result,function(index,obj){
                                             insertReadyData(tbodyId,obj,parentIndex)
+                                            // 新增行后更新汇总行
+                                            updateSummaryRow(tbodyId);
                                         })
                                     }
                                 });
@@ -368,7 +370,7 @@
             const $tbody = $(tbodyId);
 
             // 获取tbody下的所有直接子tr元素
-            var $trs = $tbody.children('tr');
+            var $trs = $tbody.children('tr:not(.summary-row)');
             const trLength = $trs.length;
             //获取子节点有多少行信息
 
@@ -870,7 +872,7 @@
             const $tbody = $(tbodyId);
 
             // 获取tbody下的所有直接子tr元素
-            var $trs = $tbody.children('tr');
+            var $trs = $tbody.children('tr:not(.summary-row)');
             //获取行号
             const trLength = $trs.length;
             //获取子节点有多少行信息
@@ -934,6 +936,70 @@
                 "</tr>";
             $tbody.append(dataHtml);
         }
+
+        // 整合后的汇总行处理方法(使用传统字符串拼接)
+        function updateSummaryRow(tbodyId) {
+            const $tbody = $(tbodyId);
+
+            // 先移除已存在的汇总行(避免重复)
+            $tbody.find('tr.summary-row').remove();
+
+            // 计算价税合计总金额
+            var total = 0; // 价税合计总金额
+            var validRowCount = 0; // 有效行数计数器
+
+            $tbody.find('tr').each(function(index, tr) {
+                // 1. 获取第一个td中的第二个input(判断是否为有效行)
+                var $firstTd = $(tr).find('td').eq(0);
+                var $secondInputInFirstTd = $firstTd.find('input').eq(1);
+                var secondInputValue = $secondInputInFirstTd.val() || '';
+
+                // 2. 判断是否为有效行(仅处理delFlag为0的行)
+                if (secondInputValue.trim() !== '0') {
+                    return true; // 跳过无效行
+                }
+
+                // 3. 有效行:累加行数和金额
+                validRowCount++;
+
+                // 4. 汇总第八个td中第一个input的值(价税合计)
+                var $eighthTd = $(tr).find('td').eq(8);
+                var $targetInput = $eighthTd.find('input:first');
+                var value = $targetInput.val() || '0';
+                var num = parseFloat(value);
+                total += isNaN(num) ? 0 : num;
+            });
+
+            // 格式化总金额为两位小数
+            var totalFormatted = total.toFixed(2);
+
+            // 5. 使用传统字符串拼接创建汇总行HTML(在第7个td中显示汇总值)
+            var summaryHtml = "";
+            summaryHtml += "<tr class='listInfo summary-row' style='background-color: #f5f5f5; font-weight: bold;'>";
+            summaryHtml += "    <td class='hide'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;' colspan='2'>汇总</td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='font-weight: bold; color: black;'>" + totalFormatted + "</td>"; // 第8个td显示汇总值
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "</tr>";
+
+            // 6. 将汇总行添加到tbody末尾(确保在最底部)
+            $tbody.append(summaryHtml);
+
+            return total; // 返回总金额,方便后续使用
+        }
+
+
+
         async function newInsertTitleInvoiceReimbursement(idValue,fileValue) {
             // 将原生DOM元素转换为jQuery对象(关键修复)
             var $idElement = $(idValue);
@@ -1004,6 +1070,8 @@
                                     insertData("#workAccountList_" + idValue.value,data,trlen,parentIndex)
                                     // 检查文件是否已上传
                                     await handleFileNewUpload(file, size, trlen,"#workAccountList_" + idValue.value,parentIndex);
+                                    // 新增行后更新汇总行
+                                    updateSummaryRow("#workAccountList_" + idValue.value);
                                 }
                                 //reimbursementElectronicInvoiceVATTaxesRowIdx++;
                             }
@@ -1361,6 +1429,9 @@
             const tbody = tr ? tr.closest('tbody') : null;
             const tbodyId = tbody ? tbody.getAttribute('id') : null;
 
+            //对数据进行重新处理
+            updateSummaryRow("#" + tbodyId)
+
             console.log("查找的tbodyId:", tbodyId);
             if (!tbodyId) {
                 console.error("未找到有效的tbody,终止金额汇总");
@@ -1398,7 +1469,7 @@
                 console.log("第", index + 1, "行有效,累计有效行数:", validRowCount);
 
                 // 汇总第八个td中第一个input的值
-                var $eighthTd = $(tr).find('td').eq(7);
+                var $eighthTd = $(tr).find('td').eq(8);
                 var $targetInput = $eighthTd.find('input:first');
                 var value = $targetInput.val() || '0';
                 var num = parseFloat(value);
@@ -1456,11 +1527,11 @@
 
         // 重新排序行号的函数(只处理未隐藏的行,行号在第二个td中)
         function reorderRowNumbers($table) {
-            // 只选择可见行(排除隐藏行
-            $table.find("tbody tr:not(.hidden)").each(function(index) {
+            // 选择可见行且排除汇总行(.summary-row
+            $table.find("tbody tr:not(.hidden):not(.summary-row)").each(function(index) {
                 var rowNumber = index; // 行号从1开始计数
-                // 更新第二个td中的行号
-                $(this).find("td:nth-child(2)").text(rowNumber);
+                // 更新第二个td中的行号(根据你的需求确认是否是nth-child(3))
+                $(this).find("td:nth-child(3)").text(rowNumber);
             });
         }
 
@@ -2205,7 +2276,7 @@
 
                                         <!-- 费用三列 -->
                                         <td>
-                                            <input id="workAccountList${index.index}_eInvoiceMoney" onchange="calculateSum(${index.index})" style="background-color: #f5f5f5" readonly="readonly" name="workAccountList[${index.index}].eInvoiceMoney" type="text" value="${workAccount.eInvoiceMoney}"  placeholder="数电发票金额" maxlength="10"  class="form-control number "/>
+                                            <input id="workAccountList${index.index}_eInvoiceMoney" onchange="calculateSum(${index.index})" name="workAccountList[${index.index}].eInvoiceMoney" type="text" value="${workAccount.eInvoiceMoney}"  placeholder="数电发票金额" maxlength="10"  class="form-control number "/>
                                         </td>
                                         <td>
                                             <input id="workAccountList${index.index}_invoiceMoney" onchange="calculateSum(${index.index})" name="workAccountList[${index.index}].invoiceMoney" type="text" value="${workAccount.invoiceMoney}"  placeholder="非数电票金额" maxlength="10"  class="form-control number"/>
@@ -2302,7 +2373,7 @@
 
 
                 <td>
-                    <input id="workAccountList{{idx}}_eInvoiceMoney" onchange="calculateSum({{idx}})" readonly="readonly" name="workAccountList[{{idx}}].eInvoiceMoney" type="text" value="{{row.eInvoiceMoney}}" style="background-color: #f5f5f5;" placeholder="数电发票金额" maxlength="10" class="form-control number"/>
+                    <input id="workAccountList{{idx}}_eInvoiceMoney" onchange="calculateSum({{idx}})" name="workAccountList[{{idx}}].eInvoiceMoney" type="text" value="{{row.eInvoiceMoney}}" placeholder="数电发票金额" maxlength="10" class="form-control number"/>
                 </td>
                 <td>
                     <input id="workAccountList{{idx}}_invoiceMoney" onchange="calculateSum({{idx}})" name="workAccountList[{{idx}}].invoiceMoney" type="text" value="{{row.invoiceMoney}}"  placeholder="非数电票金额" maxlength="10" class="form-control number"/>
@@ -2470,7 +2541,6 @@
             var $delFlagInput = $row.find("td:first-child input:eq(1)");
             var isDeleted = $delFlagInput.val() === "1";
             if (isHidden || isDeleted) {
-                console.log("跳过已删除行,id:", $row.attr("id"));
                 return true; // 继续下一行
             }
 
@@ -2478,12 +2548,76 @@
             var rowId = $row.attr("id");
             var rowIndex = rowId.replace("workAccountList", ""); // 提取数字部分
             if (!rowIndex) {
-                console.log("无法解析行索引,跳过行:", rowId);
                 return true;
             }
 
+            var idc = $("#workAccountList" + rowIndex + "_id").val();
+            console.log("idc", idc);
+
+            // 1. 校验idc有效性,避免查找无效元素
+            if (!idc || idc.trim() === "") {
+                console.error("idc为空或无效,无法继续计算");
+                return;
+            }
+
+            // 1. 查找class包含idc的目标tr(这一步不变)
+            const $targetTr = $('tr.' + idc);
+
+            // 2. 按「tr → 第一个td → table → tbody」的路径查找,补充table层级
+            // 关键变化:增加 .find('table'),匹配td下的表格
+            const $targetTbody = $targetTr
+                .find('td:first')       // 第一步:找到tr下的第一个td
+                .find('table')          // 第二步:找到这个td下的table
+                .find('tbody#workAccountList_' + idc);  // 第三步:找到table下的目标tbody
+
+            // 2. 校验tr和tbody是否存在
+            if ($targetTr.length === 0) {
+                console.error("未找到class为" + idc + "的tr元素");
+                return;
+            }
+
+            // (后续的有效性校验、遍历计算逻辑不变,可参考之前优化后的代码)
+            // 新增:校验tbody是否找到(避免后续逻辑报错)
+            if ($targetTbody.length === 0) {
+                console.error("在tr." + idc + "的第一个td中,未找到class为workAccountList_" + idc + "的tbody");
+                return;
+            }
+
+            //数电票可报销的最大额度
+            let maxMoney = 0;
+            // 3. 遍历tr时排除汇总行,避免重复计算
+            $targetTbody.find('tr:not(.summary-row)').each(function() {
+                const $tr = $(this);
+                const $secondInput = $tr.find('td:first input:eq(1)');
+                const inputValue = $secondInput.val() || '';
+
+                if (inputValue.trim() === '0') {
+                    const $eighthTd = $tr.find('td:eq(8)');
+                    // 4. 校验第九个td是否存在,避免空元素处理
+                    if ($eighthTd.length === 0) {
+                        console.warn("当前tr缺少第九个td,跳过", $tr);
+                        return true;
+                    }
+                    const eighthValue = $eighthTd.find('input').val() || '0';
+                    const num = parseFloat(eighthValue);
+                    if (!isNaN(num)) {
+                        maxMoney += num;
+                    }
+                }
+            });
+
+            console.log('数电票可报销的最大额度:', maxMoney.toFixed(2));
+
+
             // 4. 计算当前行的金额(单行汇总)
             var eInvoice = parseFloat($("#workAccountList" + rowIndex + "_eInvoiceMoney").val() || 0);
+
+            if(eInvoice>parseFloat(maxMoney.toFixed(2))){
+                $("#workAccountList" + rowIndex + "_eInvoiceMoney").val(maxMoney)
+                eInvoice = maxMoney
+                parent.layer.msg("该报销单数电票报销最大额度为:" + maxMoney.toFixed(2) + "!", {icon: 5});
+            }
+
             var invoice = parseFloat($("#workAccountList" + rowIndex + "_invoiceMoney").val() || 0);
             var rowSum = eInvoice + invoice;
 
@@ -2494,7 +2628,8 @@
             totalAllEInvoice += eInvoice;
             totalAllInvoice += invoice;
             totalAllSum += rowSum;
-            console.log("行" + rowIndex + "汇总:", rowSum, "累计总金额:", totalAllSum);
+
+            console.log("计算汇总金额",eInvoice)
         });
 
         // 7. 重新计算总报销费用(传入所有行的非数电票总金额)
@@ -2506,17 +2641,43 @@
 
     // (保留原calculateTotalMoney函数,确保它能处理所有行的总金额)
     function calculateTotalMoney(invoiceTotal) {
-        var total = 0;
-        // 遍历所有数电发票行的汇总金额(已排除删除行)
-        $("input[name$='.sumMoney']").each(function() {
-            var $sumInput = $(this);
-            var $currentTr = $sumInput.closest("tr");
-            var isHidden = $currentTr.hasClass("hidden");
-            var $delFlagInput = $currentTr.find("td:first-child input:eq(1)");
+        var total = 0; // 用于存储总和
+        // 找到id为workAccountList的tbody
+        const $targetTbody = $('tbody#workAccountList');
+        // 检查tbody是否存在
+        if ($targetTbody.length === 0) {
+            console.error("未找到id为workAccountList的tbody");
+            return 0;
+        }
+        let totalSum = 0; // 用于存储总和
+        // 遍历tbody下的所有行
+        $("tr[id^='workAccountList']").each(function() {
+            var $row = $(this);
+
+            // 2. 排除已删除的行(隐藏或标记删除)
+            var isHidden = $row.hasClass("hidden");
+            var $delFlagInput = $row.find("td:first-child input:eq(1)");
             var isDeleted = $delFlagInput.val() === "1";
+            if (isHidden || isDeleted) {
+                return true; // 继续下一行
+            }
 
-            if (!isHidden && !isDeleted) {
-                total += parseFloat($sumInput.val() || 0);
+            // 3. 提取当前行的索引(从行id中解析,如"workAccountList2" → 2)
+            var rowId = $row.attr("id");
+            var rowIndex = rowId.replace("workAccountList", ""); // 提取数字部分
+            if (!rowIndex) {
+                return true;
+            }
+
+
+            // 4. 计算当前行的金额(单行汇总)
+            var eInvoice = parseFloat($("#workAccountList" + rowIndex + "_eInvoiceMoney").val() || 0);
+
+            // 累加金额(排除非数字值)
+            if (!isNaN(eInvoice)) {
+                total += eInvoice;
+            } else {
+                console.warn("第九个td中的值不是有效的数字:", amountValue, ",行:", $tr);
             }
         });
 

+ 68 - 2
src/main/webapp/webpage/modules/workreimbursement/treeForm/all/workReimbursementAllFormDetail.jsp

@@ -247,7 +247,7 @@
                                 var subsetId="workAccountList_"+ obj.id;
 
                                 $("#workAccountList").append("<tr class='"+obj.id+"' style='display: none;'> <td colspan='15' style='padding: 0px;'>" +
-                                    "<table style=\"width: 100%;padding: 0px;margin: 0px;\" class=\"table  table-condensed details\">" +
+                                    "<table style=\"width: 100%;padding: 0px;margin: 0px;\" class=\"table table-bordered table-condensed details\">" +
                                     "<tbody id='"+subsetId+"'>" +
                                     "<input type='text' id='"+subsetId+"_len' style='display: none;' name='flags' />"+
                                     "</tbody>" +
@@ -274,6 +274,8 @@
                                         $.each(result,function(index,obj){
                                             console.log()
                                             insertReadyData(tbodyId,obj,parentIndex)
+                                            // 新增行后更新汇总行
+                                            updateSummaryRow(tbodyId);
                                         })
 
                                         // 生成allDataNewList数组(核心修复)
@@ -318,6 +320,70 @@
             }
         });
 
+        // 整合后的汇总行处理方法(使用传统字符串拼接)
+        function updateSummaryRow(tbodyId) {
+            const $tbody = $(tbodyId);
+
+            // 先移除已存在的汇总行(避免重复)
+            $tbody.find('tr.summary-row').remove();
+
+            // 计算价税合计总金额
+            var total = 0; // 价税合计总金额
+            var validRowCount = 0; // 有效行数计数器
+
+            $tbody.find('tr').each(function(index, tr) {
+                // 1. 获取第一个td中的第二个input(判断是否为有效行)
+                var $firstTd = $(tr).find('td').eq(0);
+                var $secondInputInFirstTd = $firstTd.find('input').eq(1);
+                var secondInputValue = $secondInputInFirstTd.val() || '';
+
+                // 2. 判断是否为有效行(仅处理delFlag为0的行)
+                if (secondInputValue.trim() !== '0') {
+                    return true; // 跳过无效行
+                }
+
+                // 3. 有效行:累加行数和金额
+                validRowCount++;
+
+                // 4. 汇总第八个td中第一个input的值(价税合计)
+                var $eighthTd = $(tr).find('td').eq(8);
+                var $targetInput = $eighthTd.find('input:first');
+                var value = $targetInput.val() || '0';
+                var num = parseFloat(value);
+                total += isNaN(num) ? 0 : num;
+            });
+
+            // 格式化总金额为两位小数
+            var totalFormatted = total.toFixed(2);
+
+            // 5. 使用传统字符串拼接创建汇总行HTML(在第7个td中显示汇总值)
+            var summaryHtml = "";
+            summaryHtml += "<tr class='listInfo summary-row' style='background-color: #f5f5f5; font-weight: bold;'>";
+            summaryHtml += "    <td class='hide'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;' colspan='2'>汇总</td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='font-weight: bold; color: black;'>" + totalFormatted + "</td>"; // 第8个td显示汇总值
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "</tr>";
+
+            // 6. 将汇总行添加到tbody末尾(确保在最底部)
+            $tbody.append(summaryHtml);
+
+            return total; // 返回总金额,方便后续使用
+        }
+
+
+
         function initConfirmIdNewList() {
             confirmIdNewList = allDataNewList.filter(item => item.vatTaxStatus === '1').map(item => item.id);
         }
@@ -443,7 +509,7 @@
             const $tbody = $(tbodyId);
 
             // 获取tbody下的所有直接子tr元素
-            var $trs = $tbody.children('tr');
+            var $trs = $tbody.children('tr:not(.summary-row)');
             const trLength = $trs.length;
             //获取子节点有多少行信息
 

+ 183 - 22
src/main/webapp/webpage/modules/workreimbursement/treeForm/all/workReimbursementAllModifyApply.jsp

@@ -259,7 +259,7 @@
                                     "</td>" +
 
                                     "<td>" +
-                                    "<input id='workAccountList" + index + "_eInvoiceMoney' onchange='calculateSum(" + index + ")' style='background-color: #f5f5f5' readonly name='workAccountList[" + index + "].eInvoiceMoney' type='text' value='" + (obj.eInvoiceMoney === null || obj.eInvoiceMoney === undefined ? "" : obj.eInvoiceMoney) + "' placeholder='数电发票金额' maxlength='10'  class='form-control number'/>" +
+                                    "<input id='workAccountList" + index + "_eInvoiceMoney' onchange='calculateSum(" + index + ")' name='workAccountList[" + index + "].eInvoiceMoney' type='text' value='" + (obj.eInvoiceMoney === null || obj.eInvoiceMoney === undefined ? "" : obj.eInvoiceMoney) + "' placeholder='数电发票金额' maxlength='10'  class='form-control number'/>" +
                                     "</td>" +
 
                                     "<td>" +
@@ -328,6 +328,8 @@
                                             //遍历 添加数据
                                             $.each(result,function(index,obj){
                                                 insertReadyData(tbodyId,obj,parentIndex)
+                                                // 新增行后更新汇总行
+                                                updateSummaryRow(tbodyId);
                                             })
 
                                             // 生成allDataNewList数组(核心修复)
@@ -393,7 +395,7 @@
             const $tbody = $(tbodyId);
 
             // 获取tbody下的所有直接子tr元素
-            var $trs = $tbody.children('tr');
+            var $trs = $tbody.children('tr:not(.summary-row)');
             const trLength = $trs.length;
             //获取子节点有多少行信息
 
@@ -846,7 +848,7 @@
             const $tbody = $(tbodyId);
 
             // 获取tbody下的所有直接子tr元素
-            var $trs = $tbody.children('tr');
+            var $trs = $tbody.children('tr:not(.summary-row)');
             //获取行号
             const trLength = $trs.length;
             //获取子节点有多少行信息
@@ -911,6 +913,70 @@
                 "</tr>";
             $tbody.append(dataHtml);
         }
+
+        // 整合后的汇总行处理方法(使用传统字符串拼接)
+        function updateSummaryRow(tbodyId) {
+            const $tbody = $(tbodyId);
+
+            // 先移除已存在的汇总行(避免重复)
+            $tbody.find('tr.summary-row').remove();
+
+            // 计算价税合计总金额
+            var total = 0; // 价税合计总金额
+            var validRowCount = 0; // 有效行数计数器
+
+            $tbody.find('tr').each(function(index, tr) {
+                // 1. 获取第一个td中的第二个input(判断是否为有效行)
+                var $firstTd = $(tr).find('td').eq(0);
+                var $secondInputInFirstTd = $firstTd.find('input').eq(1);
+                var secondInputValue = $secondInputInFirstTd.val() || '';
+
+                // 2. 判断是否为有效行(仅处理delFlag为0的行)
+                if (secondInputValue.trim() !== '0') {
+                    return true; // 跳过无效行
+                }
+
+                // 3. 有效行:累加行数和金额
+                validRowCount++;
+
+                // 4. 汇总第八个td中第一个input的值(价税合计)
+                var $eighthTd = $(tr).find('td').eq(8);
+                var $targetInput = $eighthTd.find('input:first');
+                var value = $targetInput.val() || '0';
+                var num = parseFloat(value);
+                total += isNaN(num) ? 0 : num;
+            });
+
+            // 格式化总金额为两位小数
+            var totalFormatted = total.toFixed(2);
+
+            // 5. 使用传统字符串拼接创建汇总行HTML(在第7个td中显示汇总值)
+            var summaryHtml = "";
+            summaryHtml += "<tr class='listInfo summary-row' style='background-color: #f5f5f5; font-weight: bold;'>";
+            summaryHtml += "    <td class='hide'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;' colspan='2'>汇总</td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='font-weight: bold; color: black;'>" + totalFormatted + "</td>"; // 第8个td显示汇总值
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "</tr>";
+
+            // 6. 将汇总行添加到tbody末尾(确保在最底部)
+            $tbody.append(summaryHtml);
+
+            return total; // 返回总金额,方便后续使用
+        }
+
+
+
         async function newInsertTitleInvoiceReimbursement(idValue,fileValue) {
             // 将原生DOM元素转换为jQuery对象(关键修复)
             var $idElement = $(idValue);
@@ -981,6 +1047,8 @@
                                     insertData("#workAccountList_" + idValue.value,data,trlen,parentIndex)
                                     // 检查文件是否已上传
                                     await handleFileNewUpload(file, size, trlen,"#workAccountList_" + idValue.value,parentIndex);
+                                    // 新增行后更新汇总行
+                                    updateSummaryRow("#workAccountList_" + idValue.value);
                                 }
                                 //reimbursementElectronicInvoiceVATTaxesRowIdx++;
                             }
@@ -1340,6 +1408,9 @@
             const tbody = tr ? tr.closest('tbody') : null;
             const tbodyId = tbody ? tbody.getAttribute('id') : null;
 
+            //对数据进行重新处理
+            updateSummaryRow("#" + tbodyId)
+
             console.log("查找的tbodyId:", tbodyId);
             if (!tbodyId) {
                 console.error("未找到有效的tbody,终止金额汇总");
@@ -1377,7 +1448,7 @@
                 console.log("第", index + 1, "行有效,累计有效行数:", validRowCount);
 
                 // 汇总第八个td中第一个input的值
-                var $eighthTd = $(tr).find('td').eq(7);
+                var $eighthTd = $(tr).find('td').eq(8);
                 var $targetInput = $eighthTd.find('input:first');
                 var value = $targetInput.val() || '0';
                 var num = parseFloat(value);
@@ -1435,11 +1506,11 @@
 
         // 重新排序行号的函数(只处理未隐藏的行,行号在第二个td中)
         function reorderRowNumbers($table) {
-            // 只选择可见行(排除隐藏行
-            $table.find("tbody tr:not(.hidden)").each(function(index) {
+            // 选择可见行且排除汇总行(.summary-row
+            $table.find("tbody tr:not(.hidden):not(.summary-row)").each(function(index) {
                 var rowNumber = index; // 行号从1开始计数
-                // 更新第二个td中的行号
-                $(this).find("td:nth-child(2)").text(rowNumber);
+                // 更新第二个td中的行号(根据你的需求确认是否是nth-child(3))
+                $(this).find("td:nth-child(3)").text(rowNumber);
             });
         }
 
@@ -2190,7 +2261,7 @@
 
                                         <!-- 费用三列 -->
                                         <td>
-                                            <input id="workAccountList${index.index}_eInvoiceMoney" onchange="calculateSum(${index.index})" style="background-color: #f5f5f5" readonly="readonly" name="workAccountList[${index.index}].eInvoiceMoney" type="text" value="${workAccount.eInvoiceMoney}"  placeholder="数电发票金额" maxlength="10"  class="form-control number"/>
+                                            <input id="workAccountList${index.index}_eInvoiceMoney" onchange="calculateSum(${index.index})" name="workAccountList[${index.index}].eInvoiceMoney" type="text" value="${workAccount.eInvoiceMoney}"  placeholder="数电发票金额" maxlength="10"  class="form-control number"/>
                                         </td>
                                         <td>
                                             <input id="workAccountList${index.index}_invoiceMoney" onchange="calculateSum(${index.index})" name="workAccountList[${index.index}].invoiceMoney" type="text" value="${workAccount.invoiceMoney}"  placeholder="非数电票金额" maxlength="10"  class="form-control number"/>
@@ -2287,7 +2358,7 @@
 
 
                 <td>
-                    <input id="workAccountList{{idx}}_eInvoiceMoney" onchange="calculateSum({{idx}})" readonly="readonly" name="workAccountList[{{idx}}].eInvoiceMoney" type="text" value="{{row.eInvoiceMoney}}" style="background-color: #f5f5f5;" placeholder="数电发票金额" maxlength="10" class="form-control number"/>
+                    <input id="workAccountList{{idx}}_eInvoiceMoney" onchange="calculateSum({{idx}})" name="workAccountList[{{idx}}].eInvoiceMoney" type="text" value="{{row.eInvoiceMoney}}" placeholder="数电发票金额" maxlength="10" class="form-control number"/>
                 </td>
                 <td>
                     <input id="workAccountList{{idx}}_invoiceMoney" onchange="calculateSum({{idx}})" name="workAccountList[{{idx}}].invoiceMoney" type="text" value="{{row.invoiceMoney}}"  placeholder="非数电票金额" maxlength="10" class="form-control number"/>
@@ -2455,7 +2526,6 @@
             var $delFlagInput = $row.find("td:first-child input:eq(1)");
             var isDeleted = $delFlagInput.val() === "1";
             if (isHidden || isDeleted) {
-                console.log("跳过已删除行,id:", $row.attr("id"));
                 return true; // 继续下一行
             }
 
@@ -2463,12 +2533,76 @@
             var rowId = $row.attr("id");
             var rowIndex = rowId.replace("workAccountList", ""); // 提取数字部分
             if (!rowIndex) {
-                console.log("无法解析行索引,跳过行:", rowId);
                 return true;
             }
 
+            var idc = $("#workAccountList" + rowIndex + "_id").val();
+            console.log("idc", idc);
+
+            // 1. 校验idc有效性,避免查找无效元素
+            if (!idc || idc.trim() === "") {
+                console.error("idc为空或无效,无法继续计算");
+                return;
+            }
+
+            // 1. 查找class包含idc的目标tr(这一步不变)
+            const $targetTr = $('tr.' + idc);
+
+            // 2. 按「tr → 第一个td → table → tbody」的路径查找,补充table层级
+            // 关键变化:增加 .find('table'),匹配td下的表格
+            const $targetTbody = $targetTr
+                .find('td:first')       // 第一步:找到tr下的第一个td
+                .find('table')          // 第二步:找到这个td下的table
+                .find('tbody#workAccountList_' + idc);  // 第三步:找到table下的目标tbody
+
+            // 2. 校验tr和tbody是否存在
+            if ($targetTr.length === 0) {
+                console.error("未找到class为" + idc + "的tr元素");
+                return;
+            }
+
+            // (后续的有效性校验、遍历计算逻辑不变,可参考之前优化后的代码)
+            // 新增:校验tbody是否找到(避免后续逻辑报错)
+            if ($targetTbody.length === 0) {
+                console.error("在tr." + idc + "的第一个td中,未找到class为workAccountList_" + idc + "的tbody");
+                return;
+            }
+
+            //数电票可报销的最大额度
+            let maxMoney = 0;
+            // 3. 遍历tr时排除汇总行,避免重复计算
+            $targetTbody.find('tr:not(.summary-row)').each(function() {
+                const $tr = $(this);
+                const $secondInput = $tr.find('td:first input:eq(1)');
+                const inputValue = $secondInput.val() || '';
+
+                if (inputValue.trim() === '0') {
+                    const $eighthTd = $tr.find('td:eq(8)');
+                    // 4. 校验第九个td是否存在,避免空元素处理
+                    if ($eighthTd.length === 0) {
+                        console.warn("当前tr缺少第九个td,跳过", $tr);
+                        return true;
+                    }
+                    const eighthValue = $eighthTd.find('input').val() || '0';
+                    const num = parseFloat(eighthValue);
+                    if (!isNaN(num)) {
+                        maxMoney += num;
+                    }
+                }
+            });
+
+            console.log('数电票可报销的最大额度:', maxMoney.toFixed(2));
+
+
             // 4. 计算当前行的金额(单行汇总)
             var eInvoice = parseFloat($("#workAccountList" + rowIndex + "_eInvoiceMoney").val() || 0);
+
+            if(eInvoice>parseFloat(maxMoney.toFixed(2))){
+                $("#workAccountList" + rowIndex + "_eInvoiceMoney").val(maxMoney)
+                eInvoice = maxMoney
+                parent.layer.msg("该报销单数电票报销最大额度为:" + maxMoney.toFixed(2) + "!", {icon: 5});
+            }
+
             var invoice = parseFloat($("#workAccountList" + rowIndex + "_invoiceMoney").val() || 0);
             var rowSum = eInvoice + invoice;
 
@@ -2479,7 +2613,8 @@
             totalAllEInvoice += eInvoice;
             totalAllInvoice += invoice;
             totalAllSum += rowSum;
-            console.log("行" + rowIndex + "汇总:", rowSum, "累计总金额:", totalAllSum);
+
+            console.log("计算汇总金额",eInvoice)
         });
 
         // 7. 重新计算总报销费用(传入所有行的非数电票总金额)
@@ -2491,17 +2626,43 @@
 
     // (保留原calculateTotalMoney函数,确保它能处理所有行的总金额)
     function calculateTotalMoney(invoiceTotal) {
-        var total = 0;
-        // 遍历所有数电发票行的汇总金额(已排除删除行)
-        $("input[name$='.sumMoney']").each(function() {
-            var $sumInput = $(this);
-            var $currentTr = $sumInput.closest("tr");
-            var isHidden = $currentTr.hasClass("hidden");
-            var $delFlagInput = $currentTr.find("td:first-child input:eq(1)");
+        var total = 0; // 用于存储总和
+        // 找到id为workAccountList的tbody
+        const $targetTbody = $('tbody#workAccountList');
+        // 检查tbody是否存在
+        if ($targetTbody.length === 0) {
+            console.error("未找到id为workAccountList的tbody");
+            return 0;
+        }
+        let totalSum = 0; // 用于存储总和
+        // 遍历tbody下的所有行
+        $("tr[id^='workAccountList']").each(function() {
+            var $row = $(this);
+
+            // 2. 排除已删除的行(隐藏或标记删除)
+            var isHidden = $row.hasClass("hidden");
+            var $delFlagInput = $row.find("td:first-child input:eq(1)");
             var isDeleted = $delFlagInput.val() === "1";
+            if (isHidden || isDeleted) {
+                return true; // 继续下一行
+            }
 
-            if (!isHidden && !isDeleted) {
-                total += parseFloat($sumInput.val() || 0);
+            // 3. 提取当前行的索引(从行id中解析,如"workAccountList2" → 2)
+            var rowId = $row.attr("id");
+            var rowIndex = rowId.replace("workAccountList", ""); // 提取数字部分
+            if (!rowIndex) {
+                return true;
+            }
+
+
+            // 4. 计算当前行的金额(单行汇总)
+            var eInvoice = parseFloat($("#workAccountList" + rowIndex + "_eInvoiceMoney").val() || 0);
+
+            // 累加金额(排除非数字值)
+            if (!isNaN(eInvoice)) {
+                total += eInvoice;
+            } else {
+                console.warn("第九个td中的值不是有效的数字:", amountValue, ",行:", $tr);
             }
         });
 

+ 69 - 2
src/main/webapp/webpage/modules/workreimbursement/treeForm/new/workReimbursementNewAudit.jsp

@@ -247,7 +247,7 @@
                                 var subsetId="workAccountList_"+ obj.id;
 
                                 $("#workAccountList").append("<tr class='"+obj.id+"' style='display: none;'> <td colspan='15' style='padding: 0px;'>" +
-                                    "<table style=\"width: 100%;padding: 0px;margin: 0px;\" class=\"table  table-condensed details\">" +
+                                    "<table style=\"width: 100%;padding: 0px;margin: 0px;\" class=\"table  table-bordered table-condensed details\">" +
                                     "<tbody id='"+subsetId+"'>" +
                                     "<input type='text' id='"+subsetId+"_len' style='display: none;' name='flags' />"+
                                     "</tbody>" +
@@ -274,6 +274,8 @@
                                             //遍历 添加数据
                                             $.each(result,function(index,obj){
                                                 insertReadyData(tbodyId,obj,parentIndex)
+                                                // 新增行后更新汇总行
+                                                updateSummaryRow(tbodyId);
                                             })
 
                                             // 生成allDataNewList数组(核心修复)
@@ -326,6 +328,71 @@
             }
         });
 
+        // 整合后的汇总行处理方法(使用传统字符串拼接)
+        function updateSummaryRow(tbodyId) {
+            const $tbody = $(tbodyId);
+
+            // 先移除已存在的汇总行(避免重复)
+            $tbody.find('tr.summary-row').remove();
+
+            // 计算价税合计总金额
+            var total = 0; // 价税合计总金额
+            var validRowCount = 0; // 有效行数计数器
+
+            $tbody.find('tr').each(function(index, tr) {
+                // 1. 获取第一个td中的第二个input(判断是否为有效行)
+                var $firstTd = $(tr).find('td').eq(0);
+                var $secondInputInFirstTd = $firstTd.find('input').eq(1);
+                var secondInputValue = $secondInputInFirstTd.val() || '';
+
+                // 2. 判断是否为有效行(仅处理delFlag为0的行)
+                if (secondInputValue.trim() !== '0') {
+                    return true; // 跳过无效行
+                }
+
+                // 3. 有效行:累加行数和金额
+                validRowCount++;
+
+                // 4. 汇总第八个td中第一个input的值(价税合计)
+                var $eighthTd = $(tr).find('td').eq(8);
+                var $targetInput = $eighthTd.find('input:first');
+                var value = $targetInput.val() || '0';
+                var num = parseFloat(value);
+                total += isNaN(num) ? 0 : num;
+            });
+
+            // 格式化总金额为两位小数
+            var totalFormatted = total.toFixed(2);
+
+            // 5. 使用传统字符串拼接创建汇总行HTML(在第7个td中显示汇总值)
+            var summaryHtml = "";
+            summaryHtml += "<tr class='listInfo summary-row' style='background-color: #f5f5f5; font-weight: bold;'>";
+            summaryHtml += "    <td class='hide'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;' colspan='2'>汇总</td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='font-weight: bold; color: black;'>" + totalFormatted + "</td>"; // 第8个td显示汇总值
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "</tr>";
+
+            // 6. 将汇总行添加到tbody末尾(确保在最底部)
+            $tbody.append(summaryHtml);
+
+            return total; // 返回总金额,方便后续使用
+        }
+
+
+
+
         function initConfirmIdNewList() {
             confirmIdNewList = allDataNewList.filter(item => item.vatTaxStatus === '1').map(item => item.id);
         }
@@ -459,7 +526,7 @@
             const $tbody = $(tbodyId);
 
             // 获取tbody下的所有直接子tr元素
-            var $trs = $tbody.children('tr');
+            var $trs = $tbody.children('tr:not(.summary-row)');
             const trLength = $trs.length;
             //获取子节点有多少行信息
 

+ 187 - 47
src/main/webapp/webpage/modules/workreimbursement/treeForm/new/workReimbursementNewFormAdd.jsp

@@ -259,7 +259,7 @@
                                     "</td>" +
 
                                     "<td>" +
-                                    "<input id='workAccountList" + index + "_eInvoiceMoney' onchange='calculateSum(" + index + ")' style='background-color: #f5f5f5' readonly name='workAccountList[" + index + "].eInvoiceMoney' type='text' value='" + (obj.eInvoiceMoney === null || obj.eInvoiceMoney === undefined ? "" : obj.eInvoiceMoney) + "' placeholder='数电发票金额' maxlength='10'  class='form-control number'/>" +
+                                    "<input id='workAccountList" + index + "_eInvoiceMoney' onchange='calculateSum(" + index + ")' name='workAccountList[" + index + "].eInvoiceMoney' type='text' value='" + (obj.eInvoiceMoney === null || obj.eInvoiceMoney === undefined ? "" : obj.eInvoiceMoney) + "' placeholder='数电发票金额' maxlength='10'  class='form-control number'/>" +
                                     "</td>" +
 
                                     "<td>" +
@@ -311,7 +311,6 @@
 
 
 
-                                console.log("parentIndex",index)
                                 $.ajax({
                                     type : "POST",
                                     url:"${ctx}/workReimbursementNew/workReimbursementNew/formByAccount",
@@ -329,7 +328,10 @@
                                         //遍历 添加数据
                                         $.each(result,function(index,obj){
                                             insertReadyData(tbodyId,obj,parentIndex)
+                                            // 新增行后更新汇总行
+                                            updateSummaryRow(tbodyId);
                                         })
+
                                     }
                                 });
 
@@ -368,7 +370,7 @@
             const $tbody = $(tbodyId);
 
             // 获取tbody下的所有直接子tr元素
-            var $trs = $tbody.children('tr');
+            var $trs = $tbody.children('tr:not(.summary-row)');
             const trLength = $trs.length;
             //获取子节点有多少行信息
 
@@ -508,7 +510,6 @@
                             "reimbursementId": $("#wId").val()
                         },
                         success:function(data){
-                            console.log(data)
                             if(!data.success){
                                 decideFlag = true
                                 parent.layer.msg(data.message, {icon: 5});
@@ -691,7 +692,6 @@
             }
             var idx1 = $("#workAccountList tr[id^='workAccountList']").length + 1;
 
-            console.log("添加行下标:",idx1)
             if(list == '#workAccountList'){
 
                 tpl = tpl.replace("workAccountList[0].financialSubjects","workAccountList["+idx1+"].financialSubjects");
@@ -871,7 +871,7 @@
             const $tbody = $(tbodyId);
 
             // 获取tbody下的所有直接子tr元素
-            var $trs = $tbody.children('tr');
+            var $trs = $tbody.children('tr:not(.summary-row)');
             //获取行号
             const trLength = $trs.length;
             //获取子节点有多少行信息
@@ -935,6 +935,69 @@
                 "</tr>";
             $tbody.append(dataHtml);
         }
+
+        // 整合后的汇总行处理方法(使用传统字符串拼接)
+        function updateSummaryRow(tbodyId) {
+            const $tbody = $(tbodyId);
+
+            // 先移除已存在的汇总行(避免重复)
+            $tbody.find('tr.summary-row').remove();
+
+            // 计算价税合计总金额
+            var total = 0; // 价税合计总金额
+            var validRowCount = 0; // 有效行数计数器
+
+            $tbody.find('tr').each(function(index, tr) {
+                // 1. 获取第一个td中的第二个input(判断是否为有效行)
+                var $firstTd = $(tr).find('td').eq(0);
+                var $secondInputInFirstTd = $firstTd.find('input').eq(1);
+                var secondInputValue = $secondInputInFirstTd.val() || '';
+
+                // 2. 判断是否为有效行(仅处理delFlag为0的行)
+                if (secondInputValue.trim() !== '0') {
+                    return true; // 跳过无效行
+                }
+
+                // 3. 有效行:累加行数和金额
+                validRowCount++;
+
+                // 4. 汇总第八个td中第一个input的值(价税合计)
+                var $eighthTd = $(tr).find('td').eq(8);
+                var $targetInput = $eighthTd.find('input:first');
+                var value = $targetInput.val() || '0';
+                var num = parseFloat(value);
+                total += isNaN(num) ? 0 : num;
+            });
+
+            // 格式化总金额为两位小数
+            var totalFormatted = total.toFixed(2);
+
+            // 5. 使用传统字符串拼接创建汇总行HTML(在第7个td中显示汇总值)
+            var summaryHtml = "";
+            summaryHtml += "<tr class='listInfo summary-row' style='background-color: #f5f5f5; font-weight: bold;'>";
+            summaryHtml += "    <td class='hide'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;' colspan='2'>汇总</td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='font-weight: bold; color: black;'>" + totalFormatted + "</td>"; // 第8个td显示汇总值
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "</tr>";
+
+            // 6. 将汇总行添加到tbody末尾(确保在最底部)
+            $tbody.append(summaryHtml);
+
+            return total; // 返回总金额,方便后续使用
+        }
+
+
         async function newInsertTitleInvoiceReimbursement(idValue,fileValue) {
             // 将原生DOM元素转换为jQuery对象(关键修复)
             var $idElement = $(idValue);
@@ -1005,10 +1068,14 @@
                                     insertData("#workAccountList_" + idValue.value,data,trlen,parentIndex)
                                     // 检查文件是否已上传
                                     await handleFileNewUpload(file, size, trlen,"#workAccountList_" + idValue.value,parentIndex);
+
+                                    // 新增行后更新汇总行
+                                    updateSummaryRow("#workAccountList_" + idValue.value);
                                 }
                                 //reimbursementElectronicInvoiceVATTaxesRowIdx++;
                             }
 
+
                         }
                     } catch (error) {
                         console.error('文件上传失败', error);
@@ -1066,8 +1133,6 @@
 
         // 处理文件上传
         async function handleFileNewUpload(file, size, trlen,inputId,parentIndex) {
-            console.log("inputId",inputId)
-            console.log("parentIndex",parentIndex)
 
             const $tbody = $(inputId);
 
@@ -1323,39 +1388,32 @@
             var $targetInput = $currentRow.find("td:first-child input:eq(1)");
             if ($targetInput.length > 0) {
                 $targetInput.val("1");
-                console.log("已将删除标记设为1");
             }
 
             // 隐藏当前行
             $currentRow.addClass("hidden");
-            console.log("已隐藏当前行");
 
             // 处理父表格显示状态(根据可见行数量)
             if ($parentTable.length > 0) {
                 // 筛选非空且未隐藏的行
                 var visibleRows = $parentTable.find("tr:not(:empty):not(.hidden)");
-                console.log("父表格可见行数:", visibleRows.length);
 
                 // 控制表格显示/隐藏
                 if (visibleRows.length === 0) {
                     $parentTable.hide();
-                    console.log("父表格已隐藏(无可见行)");
                 } else {
                     $parentTable.show();
-                    console.log("父表格已显示");
                 }
 
                 // 隐藏关联行(如果有idValue)
                 if (idValue) {
                     var targetTrClass = idValue;
                     $parentTable.find("tr." + targetTrClass).addClass("hidden");
-                    console.log("已隐藏关联行(class: " + targetTrClass + ")");
                 }
             }
 
             // 重新排序行号
             reorderRowNumbers($parentTable);
-            console.log("已重新排序行号");
 
             // 查找当前行所在的tbody并获取其id
             const td = obj.closest('td');
@@ -1363,24 +1421,23 @@
             const tbody = tr ? tr.closest('tbody') : null;
             const tbodyId = tbody ? tbody.getAttribute('id') : null;
 
-            console.log("查找的tbodyId:", tbodyId);
+            //对数据进行重新处理
+            updateSummaryRow("#" + tbodyId)
+
             if (!tbodyId) {
                 console.error("未找到有效的tbody,终止金额汇总");
                 return;
             }
 
             // 汇总金额和有效行数(核心修复:选择器添加#前缀)
-            console.log("开始汇总金额,目标tbody选择器: #", tbodyId);
             var total = 0;
             var validRowCount = 0;
 
             // 修复选择器:通过# + tbodyId定位元素
             $("#" + tbodyId).find('tr').each(function(index, tr) {
-                console.log("正在处理第", index + 1, "行");
 
                 // 验证行是否可见(非隐藏)
                 if ($(tr).hasClass("hidden")) {
-                    console.log("第", index + 1, "行是隐藏行,跳过");
                     return true; // 继续下一行
                 }
 
@@ -1388,30 +1445,25 @@
                 var $firstTd = $(tr).find('td').eq(0);
                 var $secondInput = $firstTd.find('input').eq(1);
                 var secondInputValue = $secondInput.val() || '';
-                console.log("第", index + 1, "行的删除标记值:", secondInputValue.trim());
 
                 if (secondInputValue.trim() !== '0') {
-                    console.log("第", index + 1, "行不符合条件,跳过");
                     return true; // 继续下一行
                 }
 
                 // 累加有效行数
                 validRowCount++;
-                console.log("第", index + 1, "行有效,累计有效行数:", validRowCount);
 
                 // 汇总第八个td中第一个input的值
-                var $eighthTd = $(tr).find('td').eq(7);
+                var $eighthTd = $(tr).find('td').eq(8);
                 var $targetInput = $eighthTd.find('input:first');
                 var value = $targetInput.val() || '0';
                 var num = parseFloat(value);
                 var addAmount = isNaN(num) ? 0 : num;
                 total += addAmount;
-                console.log("第", index + 1, "行金额:", addAmount, "当前累计总金额:", total);
             });
 
             // 处理汇总结果(保留两位小数)
             total = total.toFixed(2) * 1;
-            console.log("最终汇总金额:", total, "有效行数:", validRowCount);
 
             // 更新数电发票金额和数量输入框
             var $eInvoiceMoney = $("#workAccountList" + parentIndex + "_eInvoiceMoney");
@@ -1419,15 +1471,12 @@
 
             $eInvoiceMoney.val(total);
             $eInvoiceBills.val(validRowCount);
-            console.log("已更新金额输入框:", $eInvoiceMoney.val(), "数量输入框:", $eInvoiceBills.val());
 
             // 调用汇总方法(修复变量重复声明问题)
             var sumResult = calculateSum(parentIndex);
             var billResult = billSum(parentIndex);
-            console.log("calculateSum结果:", sumResult);
-            console.log("billSum结果:", billResult);
 
-            console.log("===== delRowNew函数执行结束 =====");
+
         }
 
         // 重新排序行号的函数(只处理未隐藏的行,行号在第二个td中)
@@ -1458,11 +1507,11 @@
 
         // 重新排序行号的函数(只处理未隐藏的行,行号在第二个td中)
         function reorderRowNumbers($table) {
-            // 只选择可见行(排除隐藏行
-            $table.find("tbody tr:not(.hidden)").each(function(index) {
+            // 选择可见行且排除汇总行(.summary-row
+            $table.find("tbody tr:not(.hidden):not(.summary-row)").each(function(index) {
                 var rowNumber = index; // 行号从1开始计数
-                // 更新第二个td中的行号
-                $(this).find("td:nth-child(2)").text(rowNumber);
+                // 更新第二个td中的行号(根据你的需求确认是否是nth-child(3))
+                $(this).find("td:nth-child(3)").text(rowNumber);
             });
         }
 
@@ -2207,7 +2256,7 @@
 
                                 <!-- 费用三列 -->
                                 <td>
-                                    <input id="workAccountList${index.index}_eInvoiceMoney" onchange="calculateSum(${index.index})" style="background-color: #f5f5f5" readonly="readonly" name="workAccountList[${index.index}].eInvoiceMoney" type="text" value="${workAccount.eInvoiceMoney}"  placeholder="数电发票金额" maxlength="10"  class="form-control number "/>
+                                    <input id="workAccountList${index.index}_eInvoiceMoney" onchange="calculateSum(${index.index})" name="workAccountList[${index.index}].eInvoiceMoney" type="text" value="${workAccount.eInvoiceMoney}"  placeholder="数电发票金额" maxlength="10"  class="form-control number "/>
                                 </td>
                                 <td>
                                     <input id="workAccountList${index.index}_invoiceMoney" onchange="calculateSum(${index.index})" name="workAccountList[${index.index}].invoiceMoney" type="text" value="${workAccount.invoiceMoney}"  placeholder="非数电票金额" maxlength="10"  class="form-control number"/>
@@ -2304,7 +2353,7 @@
 
 
                 <td>
-                    <input id="workAccountList{{idx}}_eInvoiceMoney" onchange="calculateSum({{idx}})" readonly="readonly" name="workAccountList[{{idx}}].eInvoiceMoney" type="text" value="{{row.eInvoiceMoney}}" style="background-color: #f5f5f5;" placeholder="数电发票金额" maxlength="10" class="form-control number"/>
+                    <input id="workAccountList{{idx}}_eInvoiceMoney" onchange="calculateSum({{idx}})" name="workAccountList[{{idx}}].eInvoiceMoney" type="text" value="{{row.eInvoiceMoney}}" placeholder="数电发票金额" maxlength="10" class="form-control number"/>
                 </td>
                 <td>
                     <input id="workAccountList{{idx}}_invoiceMoney" onchange="calculateSum({{idx}})" name="workAccountList[{{idx}}].invoiceMoney" type="text" value="{{row.invoiceMoney}}"  placeholder="非数电票金额" maxlength="10" class="form-control number"/>
@@ -2472,7 +2521,6 @@
             var $delFlagInput = $row.find("td:first-child input:eq(1)");
             var isDeleted = $delFlagInput.val() === "1";
             if (isHidden || isDeleted) {
-                console.log("跳过已删除行,id:", $row.attr("id"));
                 return true; // 继续下一行
             }
 
@@ -2480,12 +2528,76 @@
             var rowId = $row.attr("id");
             var rowIndex = rowId.replace("workAccountList", ""); // 提取数字部分
             if (!rowIndex) {
-                console.log("无法解析行索引,跳过行:", rowId);
                 return true;
             }
 
+            var idc = $("#workAccountList" + rowIndex + "_id").val();
+            console.log("idc", idc);
+
+            // 1. 校验idc有效性,避免查找无效元素
+            if (!idc || idc.trim() === "") {
+                console.error("idc为空或无效,无法继续计算");
+                return;
+            }
+
+            // 1. 查找class包含idc的目标tr(这一步不变)
+            const $targetTr = $('tr.' + idc);
+
+            // 2. 按「tr → 第一个td → table → tbody」的路径查找,补充table层级
+            // 关键变化:增加 .find('table'),匹配td下的表格
+            const $targetTbody = $targetTr
+                .find('td:first')       // 第一步:找到tr下的第一个td
+                .find('table')          // 第二步:找到这个td下的table
+                .find('tbody#workAccountList_' + idc);  // 第三步:找到table下的目标tbody
+
+            // 2. 校验tr和tbody是否存在
+            if ($targetTr.length === 0) {
+                console.error("未找到class为" + idc + "的tr元素");
+                return;
+            }
+
+            // (后续的有效性校验、遍历计算逻辑不变,可参考之前优化后的代码)
+            // 新增:校验tbody是否找到(避免后续逻辑报错)
+            if ($targetTbody.length === 0) {
+                console.error("在tr." + idc + "的第一个td中,未找到class为workAccountList_" + idc + "的tbody");
+                return;
+            }
+
+            //数电票可报销的最大额度
+            let maxMoney = 0;
+            // 3. 遍历tr时排除汇总行,避免重复计算
+            $targetTbody.find('tr:not(.summary-row)').each(function() {
+                const $tr = $(this);
+                const $secondInput = $tr.find('td:first input:eq(1)');
+                const inputValue = $secondInput.val() || '';
+
+                if (inputValue.trim() === '0') {
+                    const $eighthTd = $tr.find('td:eq(8)');
+                    // 4. 校验第九个td是否存在,避免空元素处理
+                    if ($eighthTd.length === 0) {
+                        console.warn("当前tr缺少第九个td,跳过", $tr);
+                        return true;
+                    }
+                    const eighthValue = $eighthTd.find('input').val() || '0';
+                    const num = parseFloat(eighthValue);
+                    if (!isNaN(num)) {
+                        maxMoney += num;
+                    }
+                }
+            });
+
+            console.log('数电票可报销的最大额度:', maxMoney.toFixed(2));
+
+
             // 4. 计算当前行的金额(单行汇总)
             var eInvoice = parseFloat($("#workAccountList" + rowIndex + "_eInvoiceMoney").val() || 0);
+
+            if(eInvoice>parseFloat(maxMoney.toFixed(2))){
+                $("#workAccountList" + rowIndex + "_eInvoiceMoney").val(maxMoney)
+                eInvoice = maxMoney
+                parent.layer.msg("该报销单数电票报销最大额度为:" + maxMoney.toFixed(2) + "!", {icon: 5});
+            }
+
             var invoice = parseFloat($("#workAccountList" + rowIndex + "_invoiceMoney").val() || 0);
             var rowSum = eInvoice + invoice;
 
@@ -2496,7 +2608,8 @@
             totalAllEInvoice += eInvoice;
             totalAllInvoice += invoice;
             totalAllSum += rowSum;
-            console.log("行" + rowIndex + "汇总:", rowSum, "累计总金额:", totalAllSum);
+
+            console.log("计算汇总金额",eInvoice)
         });
 
         // 7. 重新计算总报销费用(传入所有行的非数电票总金额)
@@ -2508,17 +2621,43 @@
 
     // (保留原calculateTotalMoney函数,确保它能处理所有行的总金额)
     function calculateTotalMoney(invoiceTotal) {
-        var total = 0;
-        // 遍历所有数电发票行的汇总金额(已排除删除行)
-        $("input[name$='.sumMoney']").each(function() {
-            var $sumInput = $(this);
-            var $currentTr = $sumInput.closest("tr");
-            var isHidden = $currentTr.hasClass("hidden");
-            var $delFlagInput = $currentTr.find("td:first-child input:eq(1)");
+        var total = 0; // 用于存储总和
+        // 找到id为workAccountList的tbody
+        const $targetTbody = $('tbody#workAccountList');
+        // 检查tbody是否存在
+        if ($targetTbody.length === 0) {
+            console.error("未找到id为workAccountList的tbody");
+            return 0;
+        }
+        let totalSum = 0; // 用于存储总和
+        // 遍历tbody下的所有行
+        $("tr[id^='workAccountList']").each(function() {
+            var $row = $(this);
+
+            // 2. 排除已删除的行(隐藏或标记删除)
+            var isHidden = $row.hasClass("hidden");
+            var $delFlagInput = $row.find("td:first-child input:eq(1)");
             var isDeleted = $delFlagInput.val() === "1";
+            if (isHidden || isDeleted) {
+                return true; // 继续下一行
+            }
+
+            // 3. 提取当前行的索引(从行id中解析,如"workAccountList2" → 2)
+            var rowId = $row.attr("id");
+            var rowIndex = rowId.replace("workAccountList", ""); // 提取数字部分
+            if (!rowIndex) {
+                return true;
+            }
+
 
-            if (!isHidden && !isDeleted) {
-                total += parseFloat($sumInput.val() || 0);
+            // 4. 计算当前行的金额(单行汇总)
+            var eInvoice = parseFloat($("#workAccountList" + rowIndex + "_eInvoiceMoney").val() || 0);
+
+            // 累加金额(排除非数字值)
+            if (!isNaN(eInvoice)) {
+                total += eInvoice;
+            } else {
+                console.warn("第九个td中的值不是有效的数字:", amountValue, ",行:", $tr);
             }
         });
 
@@ -2528,6 +2667,7 @@
         // 设置总金额
         $("#moneys").val(total.toFixed(2));
     }
+
     // 计算每行的汇总金额
     function billSum(rowIndex) {
         // 获取数电发票金额

+ 180 - 22
src/main/webapp/webpage/modules/workreimbursement/treeForm/new/workReimbursementNewModifyApply.jsp

@@ -259,7 +259,7 @@
                                     "</td>" +
 
                                     "<td>" +
-                                    "<input id='workAccountList" + index + "_eInvoiceMoney' onchange='calculateSum(" + index + ")' style='background-color: #f5f5f5' readonly name='workAccountList[" + index + "].eInvoiceMoney' type='text' value='" + (obj.eInvoiceMoney === null || obj.eInvoiceMoney === undefined ? "" : obj.eInvoiceMoney) + "' placeholder='数电发票金额' maxlength='10'  class='form-control number'/>" +
+                                    "<input id='workAccountList" + index + "_eInvoiceMoney' onchange='calculateSum(" + index + ")' name='workAccountList[" + index + "].eInvoiceMoney' type='text' value='" + (obj.eInvoiceMoney === null || obj.eInvoiceMoney === undefined ? "" : obj.eInvoiceMoney) + "' placeholder='数电发票金额' maxlength='10'  class='form-control number'/>" +
                                     "</td>" +
 
                                     "<td>" +
@@ -328,6 +328,8 @@
                                             //遍历 添加数据
                                             $.each(result,function(index,obj){
                                                 insertReadyData(tbodyId,obj,parentIndex)
+                                                // 新增行后更新汇总行
+                                                updateSummaryRow(tbodyId);
                                             })
 
                                             // 生成allDataNewList数组(核心修复)
@@ -393,7 +395,7 @@
             const $tbody = $(tbodyId);
 
             // 获取tbody下的所有直接子tr元素
-            var $trs = $tbody.children('tr');
+            var $trs = $tbody.children('tr:not(.summary-row)');
             const trLength = $trs.length;
             //获取子节点有多少行信息
 
@@ -846,7 +848,7 @@
             const $tbody = $(tbodyId);
 
             // 获取tbody下的所有直接子tr元素
-            var $trs = $tbody.children('tr');
+            var $trs = $tbody.children('tr:not(.summary-row)');
             //获取行号
             const trLength = $trs.length;
             //获取子节点有多少行信息
@@ -911,6 +913,67 @@
                 "</tr>";
             $tbody.append(dataHtml);
         }
+        // 整合后的汇总行处理方法(使用传统字符串拼接)
+        function updateSummaryRow(tbodyId) {
+            const $tbody = $(tbodyId);
+
+            // 先移除已存在的汇总行(避免重复)
+            $tbody.find('tr.summary-row').remove();
+
+            // 计算价税合计总金额
+            var total = 0; // 价税合计总金额
+            var validRowCount = 0; // 有效行数计数器
+
+            $tbody.find('tr').each(function(index, tr) {
+                // 1. 获取第一个td中的第二个input(判断是否为有效行)
+                var $firstTd = $(tr).find('td').eq(0);
+                var $secondInputInFirstTd = $firstTd.find('input').eq(1);
+                var secondInputValue = $secondInputInFirstTd.val() || '';
+
+                // 2. 判断是否为有效行(仅处理delFlag为0的行)
+                if (secondInputValue.trim() !== '0') {
+                    return true; // 跳过无效行
+                }
+
+                // 3. 有效行:累加行数和金额
+                validRowCount++;
+
+                // 4. 汇总第八个td中第一个input的值(价税合计)
+                var $eighthTd = $(tr).find('td').eq(8);
+                var $targetInput = $eighthTd.find('input:first');
+                var value = $targetInput.val() || '0';
+                var num = parseFloat(value);
+                total += isNaN(num) ? 0 : num;
+            });
+
+            // 格式化总金额为两位小数
+            var totalFormatted = total.toFixed(2);
+
+            // 5. 使用传统字符串拼接创建汇总行HTML(在第7个td中显示汇总值)
+            var summaryHtml = "";
+            summaryHtml += "<tr class='listInfo summary-row' style='background-color: #f5f5f5; font-weight: bold;'>";
+            summaryHtml += "    <td class='hide'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;' colspan='2'>汇总</td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='font-weight: bold; color: black;'>" + totalFormatted + "</td>"; // 第8个td显示汇总值
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "</tr>";
+
+            // 6. 将汇总行添加到tbody末尾(确保在最底部)
+            $tbody.append(summaryHtml);
+
+            return total; // 返回总金额,方便后续使用
+        }
+
         async function newInsertTitleInvoiceReimbursement(idValue,fileValue) {
             // 将原生DOM元素转换为jQuery对象(关键修复)
             var $idElement = $(idValue);
@@ -981,6 +1044,8 @@
                                     insertData("#workAccountList_" + idValue.value,data,trlen,parentIndex)
                                     // 检查文件是否已上传
                                     await handleFileNewUpload(file, size, trlen,"#workAccountList_" + idValue.value,parentIndex);
+                                    // 新增行后更新汇总行
+                                    updateSummaryRow("#workAccountList_" + idValue.value);
                                 }
                                 //reimbursementElectronicInvoiceVATTaxesRowIdx++;
                             }
@@ -1340,6 +1405,9 @@
             const tbody = tr ? tr.closest('tbody') : null;
             const tbodyId = tbody ? tbody.getAttribute('id') : null;
 
+            //对数据进行重新处理
+            updateSummaryRow("#" + tbodyId)
+
             console.log("查找的tbodyId:", tbodyId);
             if (!tbodyId) {
                 console.error("未找到有效的tbody,终止金额汇总");
@@ -1377,7 +1445,7 @@
                 console.log("第", index + 1, "行有效,累计有效行数:", validRowCount);
 
                 // 汇总第八个td中第一个input的值
-                var $eighthTd = $(tr).find('td').eq(7);
+                var $eighthTd = $(tr).find('td').eq(8);
                 var $targetInput = $eighthTd.find('input:first');
                 var value = $targetInput.val() || '0';
                 var num = parseFloat(value);
@@ -1435,11 +1503,11 @@
 
         // 重新排序行号的函数(只处理未隐藏的行,行号在第二个td中)
         function reorderRowNumbers($table) {
-            // 只选择可见行(排除隐藏行
-            $table.find("tbody tr:not(.hidden)").each(function(index) {
+            // 选择可见行且排除汇总行(.summary-row
+            $table.find("tbody tr:not(.hidden):not(.summary-row)").each(function(index) {
                 var rowNumber = index; // 行号从1开始计数
-                // 更新第二个td中的行号
-                $(this).find("td:nth-child(2)").text(rowNumber);
+                // 更新第二个td中的行号(根据你的需求确认是否是nth-child(3))
+                $(this).find("td:nth-child(3)").text(rowNumber);
             });
         }
 
@@ -2190,7 +2258,7 @@
 
                                         <!-- 费用三列 -->
                                         <td>
-                                            <input id="workAccountList${index.index}_eInvoiceMoney" onchange="calculateSum(${index.index})" style="background-color: #f5f5f5" readonly="readonly" name="workAccountList[${index.index}].eInvoiceMoney" type="text" value="${workAccount.eInvoiceMoney}"  placeholder="数电发票金额" maxlength="10"  class="form-control number"/>
+                                            <input id="workAccountList${index.index}_eInvoiceMoney" onchange="calculateSum(${index.index})" name="workAccountList[${index.index}].eInvoiceMoney" type="text" value="${workAccount.eInvoiceMoney}"  placeholder="数电发票金额" maxlength="10"  class="form-control number"/>
                                         </td>
                                         <td>
                                             <input id="workAccountList${index.index}_invoiceMoney" onchange="calculateSum(${index.index})" name="workAccountList[${index.index}].invoiceMoney" type="text" value="${workAccount.invoiceMoney}"  placeholder="非数电票金额" maxlength="10"  class="form-control number"/>
@@ -2287,7 +2355,7 @@
 
 
                 <td>
-                    <input id="workAccountList{{idx}}_eInvoiceMoney" onchange="calculateSum({{idx}})" readonly="readonly" name="workAccountList[{{idx}}].eInvoiceMoney" type="text" value="{{row.eInvoiceMoney}}" style="background-color: #f5f5f5;" placeholder="数电发票金额" maxlength="10" class="form-control number"/>
+                    <input id="workAccountList{{idx}}_eInvoiceMoney" onchange="calculateSum({{idx}})" name="workAccountList[{{idx}}].eInvoiceMoney" type="text" value="{{row.eInvoiceMoney}}" placeholder="数电发票金额" maxlength="10" class="form-control number"/>
                 </td>
                 <td>
                     <input id="workAccountList{{idx}}_invoiceMoney" onchange="calculateSum({{idx}})" name="workAccountList[{{idx}}].invoiceMoney" type="text" value="{{row.invoiceMoney}}"  placeholder="非数电票金额" maxlength="10" class="form-control number"/>
@@ -2455,7 +2523,6 @@
             var $delFlagInput = $row.find("td:first-child input:eq(1)");
             var isDeleted = $delFlagInput.val() === "1";
             if (isHidden || isDeleted) {
-                console.log("跳过已删除行,id:", $row.attr("id"));
                 return true; // 继续下一行
             }
 
@@ -2463,12 +2530,76 @@
             var rowId = $row.attr("id");
             var rowIndex = rowId.replace("workAccountList", ""); // 提取数字部分
             if (!rowIndex) {
-                console.log("无法解析行索引,跳过行:", rowId);
                 return true;
             }
 
+            var idc = $("#workAccountList" + rowIndex + "_id").val();
+            console.log("idc", idc);
+
+            // 1. 校验idc有效性,避免查找无效元素
+            if (!idc || idc.trim() === "") {
+                console.error("idc为空或无效,无法继续计算");
+                return;
+            }
+
+            // 1. 查找class包含idc的目标tr(这一步不变)
+            const $targetTr = $('tr.' + idc);
+
+            // 2. 按「tr → 第一个td → table → tbody」的路径查找,补充table层级
+            // 关键变化:增加 .find('table'),匹配td下的表格
+            const $targetTbody = $targetTr
+                .find('td:first')       // 第一步:找到tr下的第一个td
+                .find('table')          // 第二步:找到这个td下的table
+                .find('tbody#workAccountList_' + idc);  // 第三步:找到table下的目标tbody
+
+            // 2. 校验tr和tbody是否存在
+            if ($targetTr.length === 0) {
+                console.error("未找到class为" + idc + "的tr元素");
+                return;
+            }
+
+            // (后续的有效性校验、遍历计算逻辑不变,可参考之前优化后的代码)
+            // 新增:校验tbody是否找到(避免后续逻辑报错)
+            if ($targetTbody.length === 0) {
+                console.error("在tr." + idc + "的第一个td中,未找到class为workAccountList_" + idc + "的tbody");
+                return;
+            }
+
+            //数电票可报销的最大额度
+            let maxMoney = 0;
+            // 3. 遍历tr时排除汇总行,避免重复计算
+            $targetTbody.find('tr:not(.summary-row)').each(function() {
+                const $tr = $(this);
+                const $secondInput = $tr.find('td:first input:eq(1)');
+                const inputValue = $secondInput.val() || '';
+
+                if (inputValue.trim() === '0') {
+                    const $eighthTd = $tr.find('td:eq(8)');
+                    // 4. 校验第九个td是否存在,避免空元素处理
+                    if ($eighthTd.length === 0) {
+                        console.warn("当前tr缺少第九个td,跳过", $tr);
+                        return true;
+                    }
+                    const eighthValue = $eighthTd.find('input').val() || '0';
+                    const num = parseFloat(eighthValue);
+                    if (!isNaN(num)) {
+                        maxMoney += num;
+                    }
+                }
+            });
+
+            console.log('数电票可报销的最大额度:', maxMoney.toFixed(2));
+
+
             // 4. 计算当前行的金额(单行汇总)
             var eInvoice = parseFloat($("#workAccountList" + rowIndex + "_eInvoiceMoney").val() || 0);
+
+            if(eInvoice>parseFloat(maxMoney.toFixed(2))){
+                $("#workAccountList" + rowIndex + "_eInvoiceMoney").val(maxMoney)
+                eInvoice = maxMoney
+                parent.layer.msg("该报销单数电票报销最大额度为:" + maxMoney.toFixed(2) + "!", {icon: 5});
+            }
+
             var invoice = parseFloat($("#workAccountList" + rowIndex + "_invoiceMoney").val() || 0);
             var rowSum = eInvoice + invoice;
 
@@ -2479,7 +2610,8 @@
             totalAllEInvoice += eInvoice;
             totalAllInvoice += invoice;
             totalAllSum += rowSum;
-            console.log("行" + rowIndex + "汇总:", rowSum, "累计总金额:", totalAllSum);
+
+            console.log("计算汇总金额",eInvoice)
         });
 
         // 7. 重新计算总报销费用(传入所有行的非数电票总金额)
@@ -2491,17 +2623,43 @@
 
     // (保留原calculateTotalMoney函数,确保它能处理所有行的总金额)
     function calculateTotalMoney(invoiceTotal) {
-        var total = 0;
-        // 遍历所有数电发票行的汇总金额(已排除删除行)
-        $("input[name$='.sumMoney']").each(function() {
-            var $sumInput = $(this);
-            var $currentTr = $sumInput.closest("tr");
-            var isHidden = $currentTr.hasClass("hidden");
-            var $delFlagInput = $currentTr.find("td:first-child input:eq(1)");
+        var total = 0; // 用于存储总和
+        // 找到id为workAccountList的tbody
+        const $targetTbody = $('tbody#workAccountList');
+        // 检查tbody是否存在
+        if ($targetTbody.length === 0) {
+            console.error("未找到id为workAccountList的tbody");
+            return 0;
+        }
+        let totalSum = 0; // 用于存储总和
+        // 遍历tbody下的所有行
+        $("tr[id^='workAccountList']").each(function() {
+            var $row = $(this);
+
+            // 2. 排除已删除的行(隐藏或标记删除)
+            var isHidden = $row.hasClass("hidden");
+            var $delFlagInput = $row.find("td:first-child input:eq(1)");
             var isDeleted = $delFlagInput.val() === "1";
+            if (isHidden || isDeleted) {
+                return true; // 继续下一行
+            }
+
+            // 3. 提取当前行的索引(从行id中解析,如"workAccountList2" → 2)
+            var rowId = $row.attr("id");
+            var rowIndex = rowId.replace("workAccountList", ""); // 提取数字部分
+            if (!rowIndex) {
+                return true;
+            }
+
 
-            if (!isHidden && !isDeleted) {
-                total += parseFloat($sumInput.val() || 0);
+            // 4. 计算当前行的金额(单行汇总)
+            var eInvoice = parseFloat($("#workAccountList" + rowIndex + "_eInvoiceMoney").val() || 0);
+
+            // 累加金额(排除非数字值)
+            if (!isNaN(eInvoice)) {
+                total += eInvoice;
+            } else {
+                console.warn("第九个td中的值不是有效的数字:", amountValue, ",行:", $tr);
             }
         });
 

+ 185 - 25
src/main/webapp/webpage/modules/workreimbursement/treeForm/replenish/workReimbursementReplenishAudit.jsp

@@ -259,7 +259,7 @@
 										"</td>" +
 
 										"<td>" +
-										"<input id='workAccountList" + index + "_eInvoiceMoney' onchange='calculateSum(" + index + ")' style='background-color: #f5f5f5' readonly name='workAccountList[" + index + "].eInvoiceMoney' type='text' value='" + (obj.eInvoiceMoney === null || obj.eInvoiceMoney === undefined ? "" : obj.eInvoiceMoney) + "' placeholder='数电发票金额' maxlength='10'  class='form-control number'/>" +
+										"<input id='workAccountList" + index + "_eInvoiceMoney' onchange='calculateSum(" + index + ")' name='workAccountList[" + index + "].eInvoiceMoney' type='text' value='" + (obj.eInvoiceMoney === null || obj.eInvoiceMoney === undefined ? "" : obj.eInvoiceMoney) + "' placeholder='数电发票金额' maxlength='10'  class='form-control number'/>" +
 										"</td>" +
 
 										"<td>" +
@@ -301,7 +301,7 @@
 								var subsetId="workAccountList_"+ obj.id;
 
 								$("#workAccountList").append("<tr class='"+obj.id+"' style='display: none;'> <td colspan='15' style='padding: 0px;'>" +
-										"<table style=\"width: 100%;padding: 0px;margin: 0px;\" class=\"table  table-condensed details\">" +
+										"<table style=\"width: 100%;padding: 0px;margin: 0px;\" class=\"table table-bordered table-condensed details\">" +
 										"<tbody id='"+subsetId+"'>" +
 										"<input type='text' id='"+subsetId+"_len' style='display: none;' name='flags' />"+
 										"</tbody>" +
@@ -328,6 +328,8 @@
 											//遍历 添加数据
 											$.each(result,function(index,obj){
 												insertReadyData(tbodyId,obj,parentIndex)
+												// 新增行后更新汇总行
+												updateSummaryRow(tbodyId);
 											})
 
 											// 生成allDataNewList数组(核心修复)
@@ -373,6 +375,68 @@
 			//根据报销单信息去查询每个报销单下数电发票信息
 		});
 
+		// 整合后的汇总行处理方法(使用传统字符串拼接)
+		function updateSummaryRow(tbodyId) {
+			const $tbody = $(tbodyId);
+
+			// 先移除已存在的汇总行(避免重复)
+			$tbody.find('tr.summary-row').remove();
+
+			// 计算价税合计总金额
+			var total = 0; // 价税合计总金额
+			var validRowCount = 0; // 有效行数计数器
+
+			$tbody.find('tr').each(function(index, tr) {
+				// 1. 获取第一个td中的第二个input(判断是否为有效行)
+				var $firstTd = $(tr).find('td').eq(0);
+				var $secondInputInFirstTd = $firstTd.find('input').eq(1);
+				var secondInputValue = $secondInputInFirstTd.val() || '';
+
+				// 2. 判断是否为有效行(仅处理delFlag为0的行)
+				if (secondInputValue.trim() !== '0') {
+					return true; // 跳过无效行
+				}
+
+				// 3. 有效行:累加行数和金额
+				validRowCount++;
+
+				// 4. 汇总第八个td中第一个input的值(价税合计)
+				var $eighthTd = $(tr).find('td').eq(8);
+				var $targetInput = $eighthTd.find('input:first');
+				var value = $targetInput.val() || '0';
+				var num = parseFloat(value);
+				total += isNaN(num) ? 0 : num;
+			});
+
+			// 格式化总金额为两位小数
+			var totalFormatted = total.toFixed(2);
+
+			// 5. 使用传统字符串拼接创建汇总行HTML(在第7个td中显示汇总值)
+			var summaryHtml = "";
+			summaryHtml += "<tr class='listInfo summary-row' style='background-color: #f5f5f5; font-weight: bold;'>";
+			summaryHtml += "    <td class='hide'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;' colspan='2'>汇总</td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='font-weight: bold; color: black;'>" + totalFormatted + "</td>"; // 第8个td显示汇总值
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "</tr>";
+
+			// 6. 将汇总行添加到tbody末尾(确保在最底部)
+			$tbody.append(summaryHtml);
+
+			return total; // 返回总金额,方便后续使用
+		}
+
 
 
 		/**
@@ -393,7 +457,7 @@
 			const $tbody = $(tbodyId);
 
 			// 获取tbody下的所有直接子tr元素
-			var $trs = $tbody.children('tr');
+			var $trs = $tbody.children('tr:not(.summary-row)');
 			const trLength = $trs.length;
 			//获取子节点有多少行信息
 
@@ -812,8 +876,8 @@
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:100px;padding:0px\"><font color=\"red\">*</font>税额</th>"+
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:100px;padding:0px\"><font color=\"red\">*</font>价税合计</th>"+
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:150px;padding:0px\"><font color=\"red\">*</font>开票日期</th>"+
-					"<th style=\"text-align: center; background-color:#F5F5F5; padding:0px\"><font color=\"red\">*</font>开票单位</th>"+
-					"<th style=\"text-align: center; background-color:#F5F5F5; width:200px; max-width:200px; vertical-align: middle; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;;padding:0px\">文件预览</th>"+
+					"<th style=\"text-align: center; background-color:#F5F5F5; width:250px;padding:0px\"><font color=\"red\">*</font>开票单位</th>"+
+					"<th style=\"text-align: center; background-color:#F5F5F5; width:250px; vertical-align: middle; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;;padding:0px\">文件预览</th>"+
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:80px;padding:0px\">上传人</th>"+
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:110px;padding:0px\">上传时间</th>"+
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:200px;padding:0px\">操作</th>"+
@@ -846,7 +910,7 @@
 			const $tbody = $(tbodyId);
 
 			// 获取tbody下的所有直接子tr元素
-			var $trs = $tbody.children('tr');
+			var $trs = $tbody.children('tr:not(.summary-row)');
 			//获取行号
 			const trLength = $trs.length;
 			//获取子节点有多少行信息
@@ -981,6 +1045,8 @@
 									insertData("#workAccountList_" + idValue.value,data,trlen,parentIndex)
 									// 检查文件是否已上传
 									await handleFileNewUpload(file, size, trlen,"#workAccountList_" + idValue.value,parentIndex);
+									// 新增行后更新汇总行
+									updateSummaryRow("#workAccountList_" + idValue.value);
 								}
 								//reimbursementElectronicInvoiceVATTaxesRowIdx++;
 							}
@@ -1340,6 +1406,9 @@
 			const tbody = tr ? tr.closest('tbody') : null;
 			const tbodyId = tbody ? tbody.getAttribute('id') : null;
 
+			//对数据进行重新处理
+			updateSummaryRow("#" + tbodyId)
+
 			console.log("查找的tbodyId:", tbodyId);
 			if (!tbodyId) {
 				console.error("未找到有效的tbody,终止金额汇总");
@@ -1377,7 +1446,7 @@
 				console.log("第", index + 1, "行有效,累计有效行数:", validRowCount);
 
 				// 汇总第八个td中第一个input的值
-				var $eighthTd = $(tr).find('td').eq(7);
+				var $eighthTd = $(tr).find('td').eq(8);
 				var $targetInput = $eighthTd.find('input:first');
 				var value = $targetInput.val() || '0';
 				var num = parseFloat(value);
@@ -1435,11 +1504,11 @@
 
 		// 重新排序行号的函数(只处理未隐藏的行,行号在第二个td中)
 		function reorderRowNumbers($table) {
-			// 只选择可见行(排除隐藏行
-			$table.find("tbody tr:not(.hidden)").each(function(index) {
+			// 选择可见行且排除汇总行(.summary-row
+			$table.find("tbody tr:not(.hidden):not(.summary-row)").each(function(index) {
 				var rowNumber = index; // 行号从1开始计数
-				// 更新第二个td中的行号
-				$(this).find("td:nth-child(2)").text(rowNumber);
+				// 更新第二个td中的行号(根据你的需求确认是否是nth-child(3))
+				$(this).find("td:nth-child(3)").text(rowNumber);
 			});
 		}
 
@@ -2186,7 +2255,7 @@
 
                                         <!-- 费用三列 -->
                                         <td>
-                                            <input id="workAccountList${index.index}_eInvoiceMoney" onchange="calculateSum(${index.index})" style="background-color: #f5f5f5" readonly="readonly" name="workAccountList[${index.index}].eInvoiceMoney" type="text" value="${workAccount.eInvoiceMoney}"  placeholder="数电发票金额" maxlength="10"  class="form-control number"/>
+                                            <input id="workAccountList${index.index}_eInvoiceMoney" onchange="calculateSum(${index.index})" name="workAccountList[${index.index}].eInvoiceMoney" type="text" value="${workAccount.eInvoiceMoney}"  placeholder="数电发票金额" maxlength="10"  class="form-control number"/>
                                         </td>
                                         <td>
                                             <input id="workAccountList${index.index}_invoiceMoney" onchange="calculateSum(${index.index})" name="workAccountList[${index.index}].invoiceMoney" type="text" value="${workAccount.invoiceMoney}"  placeholder="非数电票金额" maxlength="10"  class="form-control number"/>
@@ -2283,7 +2352,7 @@
 
 
                 <td>
-                    <input id="workAccountList{{idx}}_eInvoiceMoney" onchange="calculateSum({{idx}})" readonly="readonly" name="workAccountList[{{idx}}].eInvoiceMoney" type="text" value="{{row.eInvoiceMoney}}" style="background-color: #f5f5f5;" placeholder="数电发票金额" maxlength="10" class="form-control number"/>
+                    <input id="workAccountList{{idx}}_eInvoiceMoney" onchange="calculateSum({{idx}})" name="workAccountList[{{idx}}].eInvoiceMoney" type="text" value="{{row.eInvoiceMoney}}" placeholder="数电发票金额" maxlength="10" class="form-control number"/>
                 </td>
                 <td>
                     <input id="workAccountList{{idx}}_invoiceMoney" onchange="calculateSum({{idx}})" name="workAccountList[{{idx}}].invoiceMoney" type="text" value="{{row.invoiceMoney}}"  placeholder="非数电票金额" maxlength="10" class="form-control number"/>
@@ -2461,7 +2530,6 @@
 			var $delFlagInput = $row.find("td:first-child input:eq(1)");
 			var isDeleted = $delFlagInput.val() === "1";
 			if (isHidden || isDeleted) {
-				console.log("跳过已删除行,id:", $row.attr("id"));
 				return true; // 继续下一行
 			}
 
@@ -2469,12 +2537,76 @@
 			var rowId = $row.attr("id");
 			var rowIndex = rowId.replace("workAccountList", ""); // 提取数字部分
 			if (!rowIndex) {
-				console.log("无法解析行索引,跳过行:", rowId);
 				return true;
 			}
 
+			var idc = $("#workAccountList" + rowIndex + "_id").val();
+			console.log("idc", idc);
+
+			// 1. 校验idc有效性,避免查找无效元素
+			if (!idc || idc.trim() === "") {
+				console.error("idc为空或无效,无法继续计算");
+				return;
+			}
+
+			// 1. 查找class包含idc的目标tr(这一步不变)
+			const $targetTr = $('tr.' + idc);
+
+			// 2. 按「tr → 第一个td → table → tbody」的路径查找,补充table层级
+			// 关键变化:增加 .find('table'),匹配td下的表格
+			const $targetTbody = $targetTr
+					.find('td:first')       // 第一步:找到tr下的第一个td
+					.find('table')          // 第二步:找到这个td下的table
+					.find('tbody#workAccountList_' + idc);  // 第三步:找到table下的目标tbody
+
+			// 2. 校验tr和tbody是否存在
+			if ($targetTr.length === 0) {
+				console.error("未找到class为" + idc + "的tr元素");
+				return;
+			}
+
+			// (后续的有效性校验、遍历计算逻辑不变,可参考之前优化后的代码)
+			// 新增:校验tbody是否找到(避免后续逻辑报错)
+			if ($targetTbody.length === 0) {
+				console.error("在tr." + idc + "的第一个td中,未找到class为workAccountList_" + idc + "的tbody");
+				return;
+			}
+
+			//数电票可报销的最大额度
+			let maxMoney = 0;
+			// 3. 遍历tr时排除汇总行,避免重复计算
+			$targetTbody.find('tr:not(.summary-row)').each(function() {
+				const $tr = $(this);
+				const $secondInput = $tr.find('td:first input:eq(1)');
+				const inputValue = $secondInput.val() || '';
+
+				if (inputValue.trim() === '0') {
+					const $eighthTd = $tr.find('td:eq(8)');
+					// 4. 校验第九个td是否存在,避免空元素处理
+					if ($eighthTd.length === 0) {
+						console.warn("当前tr缺少第九个td,跳过", $tr);
+						return true;
+					}
+					const eighthValue = $eighthTd.find('input').val() || '0';
+					const num = parseFloat(eighthValue);
+					if (!isNaN(num)) {
+						maxMoney += num;
+					}
+				}
+			});
+
+			console.log('数电票可报销的最大额度:', maxMoney.toFixed(2));
+
+
 			// 4. 计算当前行的金额(单行汇总)
 			var eInvoice = parseFloat($("#workAccountList" + rowIndex + "_eInvoiceMoney").val() || 0);
+
+			if(eInvoice>parseFloat(maxMoney.toFixed(2))){
+				$("#workAccountList" + rowIndex + "_eInvoiceMoney").val(maxMoney)
+				eInvoice = maxMoney
+				parent.layer.msg("该报销单数电票报销最大额度为:" + maxMoney.toFixed(2) + "!", {icon: 5});
+			}
+
 			var invoice = parseFloat($("#workAccountList" + rowIndex + "_invoiceMoney").val() || 0);
 			var rowSum = eInvoice + invoice;
 
@@ -2485,7 +2617,8 @@
 			totalAllEInvoice += eInvoice;
 			totalAllInvoice += invoice;
 			totalAllSum += rowSum;
-			console.log("行" + rowIndex + "汇总:", rowSum, "累计总金额:", totalAllSum);
+
+			console.log("计算汇总金额",eInvoice)
 		});
 
 		// 7. 重新计算总报销费用(传入所有行的非数电票总金额)
@@ -2497,17 +2630,43 @@
 
 	// (保留原calculateTotalMoney函数,确保它能处理所有行的总金额)
 	function calculateTotalMoney(invoiceTotal) {
-		var total = 0;
-		// 遍历所有数电发票行的汇总金额(已排除删除行)
-		$("input[name$='.sumMoney']").each(function() {
-			var $sumInput = $(this);
-			var $currentTr = $sumInput.closest("tr");
-			var isHidden = $currentTr.hasClass("hidden");
-			var $delFlagInput = $currentTr.find("td:first-child input:eq(1)");
+		var total = 0; // 用于存储总和
+		// 找到id为workAccountList的tbody
+		const $targetTbody = $('tbody#workAccountList');
+		// 检查tbody是否存在
+		if ($targetTbody.length === 0) {
+			console.error("未找到id为workAccountList的tbody");
+			return 0;
+		}
+		let totalSum = 0; // 用于存储总和
+		// 遍历tbody下的所有行
+		$("tr[id^='workAccountList']").each(function() {
+			var $row = $(this);
+
+			// 2. 排除已删除的行(隐藏或标记删除)
+			var isHidden = $row.hasClass("hidden");
+			var $delFlagInput = $row.find("td:first-child input:eq(1)");
 			var isDeleted = $delFlagInput.val() === "1";
+			if (isHidden || isDeleted) {
+				return true; // 继续下一行
+			}
 
-			if (!isHidden && !isDeleted) {
-				total += parseFloat($sumInput.val() || 0);
+			// 3. 提取当前行的索引(从行id中解析,如"workAccountList2" → 2)
+			var rowId = $row.attr("id");
+			var rowIndex = rowId.replace("workAccountList", ""); // 提取数字部分
+			if (!rowIndex) {
+				return true;
+			}
+
+
+			// 4. 计算当前行的金额(单行汇总)
+			var eInvoice = parseFloat($("#workAccountList" + rowIndex + "_eInvoiceMoney").val() || 0);
+
+			// 累加金额(排除非数字值)
+			if (!isNaN(eInvoice)) {
+				total += eInvoice;
+			} else {
+				console.warn("第九个td中的值不是有效的数字:", amountValue, ",行:", $tr);
 			}
 		});
 
@@ -2517,6 +2676,7 @@
 		// 设置总金额
 		$("#moneys").val(total.toFixed(2));
 	}
+
 	// 计算每行的汇总金额
 	function billSum(rowIndex) {
 		// 获取数电发票金额

+ 70 - 4
src/main/webapp/webpage/modules/workreimbursement/treeForm/replenish/workReimbursementReplenishCwAudit.jsp

@@ -247,7 +247,7 @@
 								var subsetId="workAccountList_"+ obj.id;
 
 								$("#workAccountList").append("<tr class='"+obj.id+"' style='display: none;'> <td colspan='15' style='padding: 0px;'>" +
-										"<table style=\"width: 100%;padding: 0px;margin: 0px;\" class=\"table  table-condensed details\">" +
+										"<table style=\"width: 100%;padding: 0px;margin: 0px;\" class=\"table table-bordered table-condensed details\">" +
 										"<tbody id='"+subsetId+"'>" +
 										"<input type='text' id='"+subsetId+"_len' style='display: none;' name='flags' />"+
 										"</tbody>" +
@@ -274,6 +274,8 @@
 											//遍历 添加数据
 											$.each(result,function(index,obj){
 												insertReadyData(tbodyId,obj,parentIndex)
+												// 新增行后更新汇总行
+												updateSummaryRow(tbodyId);
 											})
 
 											// 生成allDataNewList数组(核心修复)
@@ -326,6 +328,70 @@
 			}
 		});
 
+		// 整合后的汇总行处理方法(使用传统字符串拼接)
+		function updateSummaryRow(tbodyId) {
+			const $tbody = $(tbodyId);
+
+			// 先移除已存在的汇总行(避免重复)
+			$tbody.find('tr.summary-row').remove();
+
+			// 计算价税合计总金额
+			var total = 0; // 价税合计总金额
+			var validRowCount = 0; // 有效行数计数器
+
+			$tbody.find('tr').each(function(index, tr) {
+				// 1. 获取第一个td中的第二个input(判断是否为有效行)
+				var $firstTd = $(tr).find('td').eq(0);
+				var $secondInputInFirstTd = $firstTd.find('input').eq(1);
+				var secondInputValue = $secondInputInFirstTd.val() || '';
+
+				// 2. 判断是否为有效行(仅处理delFlag为0的行)
+				if (secondInputValue.trim() !== '0') {
+					return true; // 跳过无效行
+				}
+
+				// 3. 有效行:累加行数和金额
+				validRowCount++;
+
+				// 4. 汇总第八个td中第一个input的值(价税合计)
+				var $eighthTd = $(tr).find('td').eq(8);
+				var $targetInput = $eighthTd.find('input:first');
+				var value = $targetInput.val() || '0';
+				var num = parseFloat(value);
+				total += isNaN(num) ? 0 : num;
+			});
+
+			// 格式化总金额为两位小数
+			var totalFormatted = total.toFixed(2);
+
+			// 5. 使用传统字符串拼接创建汇总行HTML(在第7个td中显示汇总值)
+			var summaryHtml = "";
+			summaryHtml += "<tr class='listInfo summary-row' style='background-color: #f5f5f5; font-weight: bold;'>";
+			summaryHtml += "    <td class='hide'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;' colspan='2'>汇总</td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='font-weight: bold; color: black;'>" + totalFormatted + "</td>"; // 第8个td显示汇总值
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "</tr>";
+
+			// 6. 将汇总行添加到tbody末尾(确保在最底部)
+			$tbody.append(summaryHtml);
+
+			return total; // 返回总金额,方便后续使用
+		}
+
+
+
 		function initConfirmIdNewList() {
 			confirmIdNewList = allDataNewList.filter(item => item.vatTaxStatus === '1').map(item => item.id);
 		}
@@ -420,8 +486,8 @@
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:100px;padding:0px\"><font color=\"red\">*</font>税额</th>"+
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:100px;padding:0px\"><font color=\"red\">*</font>价税合计</th>"+
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:150px;padding:0px\"><font color=\"red\">*</font>开票日期</th>"+
-					"<th style=\"text-align: center; background-color:#F5F5F5; padding:0px\"><font color=\"red\">*</font>开票单位</th>"+
-					"<th style=\"text-align: center; background-color:#F5F5F5; width:200px; max-width:200px; vertical-align: middle; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;;padding:0px\">文件预览</th>"+
+					"<th style=\"text-align: center; background-color:#F5F5F5; width:250px;padding:0px\"><font color=\"red\">*</font>开票单位</th>"+
+					"<th style=\"text-align: center; background-color:#F5F5F5; width:250px; vertical-align: middle; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;;padding:0px\">文件预览</th>"+
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:80px;padding:0px\">上传人</th>"+
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:100px;padding:0px\">上传时间</th>"+
 					// 嵌入服务器端生成的列(此时ticketConfirmTh是干净的<th>标签)
@@ -459,7 +525,7 @@
 			const $tbody = $(tbodyId);
 
 			// 获取tbody下的所有直接子tr元素
-			var $trs = $tbody.children('tr');
+			var $trs = $tbody.children('tr:not(.summary-row)');
 			const trLength = $trs.length;
 			//获取子节点有多少行信息
 

+ 70 - 4
src/main/webapp/webpage/modules/workreimbursement/treeForm/specific/workReimbursementSpecificAudit.jsp

@@ -247,7 +247,7 @@
 								var subsetId="workAccountList_"+ obj.id;
 
 								$("#workAccountList").append("<tr class='"+obj.id+"' style='display: none;'> <td colspan='15' style='padding: 0px;'>" +
-										"<table style=\"width: 100%;padding: 0px;margin: 0px;\" class=\"table table-condensed details\">" +
+										"<table style=\"width: 100%;padding: 0px;margin: 0px;\" class=\"table table-bordered table-condensed details\">" +
 										"<tbody id='"+subsetId+"'>" +
 										"<input type='text' id='"+subsetId+"_len' style='display: none;' name='flags' />"+
 										"</tbody>" +
@@ -274,6 +274,8 @@
 											//遍历 添加数据
 											$.each(result,function(index,obj){
 												insertReadyData(tbodyId,obj,parentIndex)
+												// 新增行后更新汇总行
+												updateSummaryRow(tbodyId);
 											})
 
 											// 生成allDataNewList数组(核心修复)
@@ -326,6 +328,70 @@
 			}
 		});
 
+		// 整合后的汇总行处理方法(使用传统字符串拼接)
+		function updateSummaryRow(tbodyId) {
+			const $tbody = $(tbodyId);
+
+			// 先移除已存在的汇总行(避免重复)
+			$tbody.find('tr.summary-row').remove();
+
+			// 计算价税合计总金额
+			var total = 0; // 价税合计总金额
+			var validRowCount = 0; // 有效行数计数器
+
+			$tbody.find('tr').each(function(index, tr) {
+				// 1. 获取第一个td中的第二个input(判断是否为有效行)
+				var $firstTd = $(tr).find('td').eq(0);
+				var $secondInputInFirstTd = $firstTd.find('input').eq(1);
+				var secondInputValue = $secondInputInFirstTd.val() || '';
+
+				// 2. 判断是否为有效行(仅处理delFlag为0的行)
+				if (secondInputValue.trim() !== '0') {
+					return true; // 跳过无效行
+				}
+
+				// 3. 有效行:累加行数和金额
+				validRowCount++;
+
+				// 4. 汇总第八个td中第一个input的值(价税合计)
+				var $eighthTd = $(tr).find('td').eq(8);
+				var $targetInput = $eighthTd.find('input:first');
+				var value = $targetInput.val() || '0';
+				var num = parseFloat(value);
+				total += isNaN(num) ? 0 : num;
+			});
+
+			// 格式化总金额为两位小数
+			var totalFormatted = total.toFixed(2);
+
+			// 5. 使用传统字符串拼接创建汇总行HTML(在第7个td中显示汇总值)
+			var summaryHtml = "";
+			summaryHtml += "<tr class='listInfo summary-row' style='background-color: #f5f5f5; font-weight: bold;'>";
+			summaryHtml += "    <td class='hide'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;' colspan='2'>汇总</td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='font-weight: bold; color: black;'>" + totalFormatted + "</td>"; // 第8个td显示汇总值
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "    <td style='text-align: center;'></td>";
+			summaryHtml += "</tr>";
+
+			// 6. 将汇总行添加到tbody末尾(确保在最底部)
+			$tbody.append(summaryHtml);
+
+			return total; // 返回总金额,方便后续使用
+		}
+
+
+
 		function initConfirmIdNewList() {
 			confirmIdNewList = allDataNewList.filter(item => item.vatTaxStatus === '1').map(item => item.id);
 		}
@@ -420,8 +486,8 @@
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:100px;padding:0px\"><font color=\"red\">*</font>税额</th>"+
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:100px;padding:0px\"><font color=\"red\">*</font>价税合计</th>"+
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:150px;padding:0px\"><font color=\"red\">*</font>开票日期</th>"+
-					"<th style=\"text-align: center; background-color:#F5F5F5; padding:0px\"><font color=\"red\">*</font>开票单位</th>"+
-					"<th style=\"text-align: center; background-color:#F5F5F5; width:200px; max-width:200px; vertical-align: middle; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;;padding:0px\">文件预览</th>"+
+					"<th style=\"text-align: center; background-color:#F5F5F5; width:200px;padding:0px\"><font color=\"red\">*</font>开票单位</th>"+
+					"<th style=\"text-align: center; background-color:#F5F5F5; width:300px; vertical-align: middle; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;;padding:0px\">文件预览</th>"+
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:80px;padding:0px\">上传人</th>"+
 					"<th style=\"text-align: center; background-color:#F5F5F5; width:100px;padding:0px\">上传时间</th>"+
 					// 嵌入服务器端生成的列(此时ticketConfirmTh是干净的<th>标签)
@@ -459,7 +525,7 @@
 			const $tbody = $(tbodyId);
 
 			// 获取tbody下的所有直接子tr元素
-			var $trs = $tbody.children('tr');
+			var $trs = $tbody.children('tr:not(.summary-row)');
 			const trLength = $trs.length;
 			//获取子节点有多少行信息
 

+ 184 - 23
src/main/webapp/webpage/modules/workreimbursement/treeForm/specific/workReimbursementSpecificModifyApply.jsp

@@ -259,7 +259,7 @@
                                     "</td>" +
 
                                     "<td>" +
-                                    "<input id='workAccountList" + index + "_eInvoiceMoney' onchange='calculateSum(" + index + ")' style='background-color: #f5f5f5' readonly name='workAccountList[" + index + "].eInvoiceMoney' type='text' value='" + (obj.eInvoiceMoney === null || obj.eInvoiceMoney === undefined ? "" : obj.eInvoiceMoney) + "' placeholder='数电发票金额' maxlength='10'  class='form-control number'/>" +
+                                    "<input id='workAccountList" + index + "_eInvoiceMoney' onchange='calculateSum(" + index + ")' name='workAccountList[" + index + "].eInvoiceMoney' type='text' value='" + (obj.eInvoiceMoney === null || obj.eInvoiceMoney === undefined ? "" : obj.eInvoiceMoney) + "' placeholder='数电发票金额' maxlength='10'  class='form-control number'/>" +
                                     "</td>" +
 
                                     "<td>" +
@@ -301,7 +301,7 @@
                                 var subsetId="workAccountList_"+ obj.id;
 
                                 $("#workAccountList").append("<tr class='"+obj.id+"' style='display: none;'> <td colspan='15' style='padding: 0px;'>" +
-                                    "<table style=\"width: 100%;padding: 0px;margin: 0px;\" class=\"table  table-condensed details\">" +
+                                    "<table style=\"width: 100%;padding: 0px;margin: 0px;\" class=\"table table-bordered table-condensed details\">" +
                                     "<tbody id='"+subsetId+"'>" +
                                     "<input type='text' id='"+subsetId+"_len' style='display: none;' name='flags' />"+
                                     "</tbody>" +
@@ -328,6 +328,8 @@
                                             //遍历 添加数据
                                             $.each(result,function(index,obj){
                                                 insertReadyData(tbodyId,obj,parentIndex)
+                                                // 新增行后更新汇总行
+                                                updateSummaryRow(tbodyId);
                                             })
 
                                             // 生成allDataNewList数组(核心修复)
@@ -393,7 +395,7 @@
             const $tbody = $(tbodyId);
 
             // 获取tbody下的所有直接子tr元素
-            var $trs = $tbody.children('tr');
+            var $trs = $tbody.children('tr:not(.summary-row)');
             const trLength = $trs.length;
             //获取子节点有多少行信息
 
@@ -856,7 +858,7 @@
             const $tbody = $(tbodyId);
 
             // 获取tbody下的所有直接子tr元素
-            var $trs = $tbody.children('tr');
+            var $trs = $tbody.children('tr:not(.summary-row)');
             //获取行号
             const trLength = $trs.length;
             //获取子节点有多少行信息
@@ -921,6 +923,70 @@
                 "</tr>";
             $tbody.append(dataHtml);
         }
+
+        // 整合后的汇总行处理方法(使用传统字符串拼接)
+        function updateSummaryRow(tbodyId) {
+            const $tbody = $(tbodyId);
+
+            // 先移除已存在的汇总行(避免重复)
+            $tbody.find('tr.summary-row').remove();
+
+            // 计算价税合计总金额
+            var total = 0; // 价税合计总金额
+            var validRowCount = 0; // 有效行数计数器
+
+            $tbody.find('tr').each(function(index, tr) {
+                // 1. 获取第一个td中的第二个input(判断是否为有效行)
+                var $firstTd = $(tr).find('td').eq(0);
+                var $secondInputInFirstTd = $firstTd.find('input').eq(1);
+                var secondInputValue = $secondInputInFirstTd.val() || '';
+
+                // 2. 判断是否为有效行(仅处理delFlag为0的行)
+                if (secondInputValue.trim() !== '0') {
+                    return true; // 跳过无效行
+                }
+
+                // 3. 有效行:累加行数和金额
+                validRowCount++;
+
+                // 4. 汇总第八个td中第一个input的值(价税合计)
+                var $eighthTd = $(tr).find('td').eq(8);
+                var $targetInput = $eighthTd.find('input:first');
+                var value = $targetInput.val() || '0';
+                var num = parseFloat(value);
+                total += isNaN(num) ? 0 : num;
+            });
+
+            // 格式化总金额为两位小数
+            var totalFormatted = total.toFixed(2);
+
+            // 5. 使用传统字符串拼接创建汇总行HTML(在第7个td中显示汇总值)
+            var summaryHtml = "";
+            summaryHtml += "<tr class='listInfo summary-row' style='background-color: #f5f5f5; font-weight: bold;'>";
+            summaryHtml += "    <td class='hide'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;' colspan='2'>汇总</td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='font-weight: bold; color: black;'>" + totalFormatted + "</td>"; // 第8个td显示汇总值
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "    <td style='text-align: center;'></td>";
+            summaryHtml += "</tr>";
+
+            // 6. 将汇总行添加到tbody末尾(确保在最底部)
+            $tbody.append(summaryHtml);
+
+            return total; // 返回总金额,方便后续使用
+        }
+
+
+
         async function newInsertTitleInvoiceReimbursement(idValue,fileValue) {
             // 将原生DOM元素转换为jQuery对象(关键修复)
             var $idElement = $(idValue);
@@ -991,6 +1057,8 @@
                                     insertData("#workAccountList_" + idValue.value,data,trlen,parentIndex)
                                     // 检查文件是否已上传
                                     await handleFileNewUpload(file, size, trlen,"#workAccountList_" + idValue.value,parentIndex);
+                                    // 新增行后更新汇总行
+                                    updateSummaryRow("#workAccountList_" + idValue.value);
                                 }
                                 //reimbursementElectronicInvoiceVATTaxesRowIdx++;
                             }
@@ -1350,6 +1418,9 @@
             const tbody = tr ? tr.closest('tbody') : null;
             const tbodyId = tbody ? tbody.getAttribute('id') : null;
 
+            //对数据进行重新处理
+            updateSummaryRow("#" + tbodyId)
+
             console.log("查找的tbodyId:", tbodyId);
             if (!tbodyId) {
                 console.error("未找到有效的tbody,终止金额汇总");
@@ -1387,7 +1458,7 @@
                 console.log("第", index + 1, "行有效,累计有效行数:", validRowCount);
 
                 // 汇总第八个td中第一个input的值
-                var $eighthTd = $(tr).find('td').eq(7);
+                var $eighthTd = $(tr).find('td').eq(8);
                 var $targetInput = $eighthTd.find('input:first');
                 var value = $targetInput.val() || '0';
                 var num = parseFloat(value);
@@ -1445,11 +1516,11 @@
 
         // 重新排序行号的函数(只处理未隐藏的行,行号在第二个td中)
         function reorderRowNumbers($table) {
-            // 只选择可见行(排除隐藏行
-            $table.find("tbody tr:not(.hidden)").each(function(index) {
+            // 选择可见行且排除汇总行(.summary-row
+            $table.find("tbody tr:not(.hidden):not(.summary-row)").each(function(index) {
                 var rowNumber = index; // 行号从1开始计数
-                // 更新第二个td中的行号
-                $(this).find("td:nth-child(2)").text(rowNumber);
+                // 更新第二个td中的行号(根据你的需求确认是否是nth-child(3))
+                $(this).find("td:nth-child(3)").text(rowNumber);
             });
         }
 
@@ -2200,7 +2271,7 @@
 
                                         <!-- 费用三列 -->
                                         <td>
-                                            <input id="workAccountList${index.index}_eInvoiceMoney" onchange="calculateSum(${index.index})" style="background-color: #f5f5f5" readonly="readonly" name="workAccountList[${index.index}].eInvoiceMoney" type="text" value="${workAccount.eInvoiceMoney}"  placeholder="数电发票金额" maxlength="10"  class="form-control number"/>
+                                            <input id="workAccountList${index.index}_eInvoiceMoney" onchange="calculateSum(${index.index})" name="workAccountList[${index.index}].eInvoiceMoney" type="text" value="${workAccount.eInvoiceMoney}"  placeholder="数电发票金额" maxlength="10"  class="form-control number"/>
                                         </td>
                                         <td>
                                             <input id="workAccountList${index.index}_invoiceMoney" onchange="calculateSum(${index.index})" name="workAccountList[${index.index}].invoiceMoney" type="text" value="${workAccount.invoiceMoney}"  placeholder="非数电票金额" maxlength="10"  class="form-control number"/>
@@ -2297,7 +2368,7 @@
 
 
                 <td>
-                    <input id="workAccountList{{idx}}_eInvoiceMoney" onchange="calculateSum({{idx}})" readonly="readonly" name="workAccountList[{{idx}}].eInvoiceMoney" type="text" value="{{row.eInvoiceMoney}}" style="background-color: #f5f5f5;" placeholder="数电发票金额" maxlength="10" class="form-control number"/>
+                    <input id="workAccountList{{idx}}_eInvoiceMoney" onchange="calculateSum({{idx}})" name="workAccountList[{{idx}}].eInvoiceMoney" type="text" value="{{row.eInvoiceMoney}}" placeholder="数电发票金额" maxlength="10" class="form-control number"/>
                 </td>
                 <td>
                     <input id="workAccountList{{idx}}_invoiceMoney" onchange="calculateSum({{idx}})" name="workAccountList[{{idx}}].invoiceMoney" type="text" value="{{row.invoiceMoney}}"  placeholder="非数电票金额" maxlength="10" class="form-control number"/>
@@ -2465,7 +2536,6 @@
             var $delFlagInput = $row.find("td:first-child input:eq(1)");
             var isDeleted = $delFlagInput.val() === "1";
             if (isHidden || isDeleted) {
-                console.log("跳过已删除行,id:", $row.attr("id"));
                 return true; // 继续下一行
             }
 
@@ -2473,12 +2543,76 @@
             var rowId = $row.attr("id");
             var rowIndex = rowId.replace("workAccountList", ""); // 提取数字部分
             if (!rowIndex) {
-                console.log("无法解析行索引,跳过行:", rowId);
                 return true;
             }
 
+            var idc = $("#workAccountList" + rowIndex + "_id").val();
+            console.log("idc", idc);
+
+            // 1. 校验idc有效性,避免查找无效元素
+            if (!idc || idc.trim() === "") {
+                console.error("idc为空或无效,无法继续计算");
+                return;
+            }
+
+            // 1. 查找class包含idc的目标tr(这一步不变)
+            const $targetTr = $('tr.' + idc);
+
+            // 2. 按「tr → 第一个td → table → tbody」的路径查找,补充table层级
+            // 关键变化:增加 .find('table'),匹配td下的表格
+            const $targetTbody = $targetTr
+                .find('td:first')       // 第一步:找到tr下的第一个td
+                .find('table')          // 第二步:找到这个td下的table
+                .find('tbody#workAccountList_' + idc);  // 第三步:找到table下的目标tbody
+
+            // 2. 校验tr和tbody是否存在
+            if ($targetTr.length === 0) {
+                console.error("未找到class为" + idc + "的tr元素");
+                return;
+            }
+
+            // (后续的有效性校验、遍历计算逻辑不变,可参考之前优化后的代码)
+            // 新增:校验tbody是否找到(避免后续逻辑报错)
+            if ($targetTbody.length === 0) {
+                console.error("在tr." + idc + "的第一个td中,未找到class为workAccountList_" + idc + "的tbody");
+                return;
+            }
+
+            //数电票可报销的最大额度
+            let maxMoney = 0;
+            // 3. 遍历tr时排除汇总行,避免重复计算
+            $targetTbody.find('tr:not(.summary-row)').each(function() {
+                const $tr = $(this);
+                const $secondInput = $tr.find('td:first input:eq(1)');
+                const inputValue = $secondInput.val() || '';
+
+                if (inputValue.trim() === '0') {
+                    const $eighthTd = $tr.find('td:eq(8)');
+                    // 4. 校验第九个td是否存在,避免空元素处理
+                    if ($eighthTd.length === 0) {
+                        console.warn("当前tr缺少第九个td,跳过", $tr);
+                        return true;
+                    }
+                    const eighthValue = $eighthTd.find('input').val() || '0';
+                    const num = parseFloat(eighthValue);
+                    if (!isNaN(num)) {
+                        maxMoney += num;
+                    }
+                }
+            });
+
+            console.log('数电票可报销的最大额度:', maxMoney.toFixed(2));
+
+
             // 4. 计算当前行的金额(单行汇总)
             var eInvoice = parseFloat($("#workAccountList" + rowIndex + "_eInvoiceMoney").val() || 0);
+
+            if(eInvoice>parseFloat(maxMoney.toFixed(2))){
+                $("#workAccountList" + rowIndex + "_eInvoiceMoney").val(maxMoney)
+                eInvoice = maxMoney
+                parent.layer.msg("该报销单数电票报销最大额度为:" + maxMoney.toFixed(2) + "!", {icon: 5});
+            }
+
             var invoice = parseFloat($("#workAccountList" + rowIndex + "_invoiceMoney").val() || 0);
             var rowSum = eInvoice + invoice;
 
@@ -2489,7 +2623,8 @@
             totalAllEInvoice += eInvoice;
             totalAllInvoice += invoice;
             totalAllSum += rowSum;
-            console.log("行" + rowIndex + "汇总:", rowSum, "累计总金额:", totalAllSum);
+
+            console.log("计算汇总金额",eInvoice)
         });
 
         // 7. 重新计算总报销费用(传入所有行的非数电票总金额)
@@ -2501,17 +2636,43 @@
 
     // (保留原calculateTotalMoney函数,确保它能处理所有行的总金额)
     function calculateTotalMoney(invoiceTotal) {
-        var total = 0;
-        // 遍历所有数电发票行的汇总金额(已排除删除行)
-        $("input[name$='.sumMoney']").each(function() {
-            var $sumInput = $(this);
-            var $currentTr = $sumInput.closest("tr");
-            var isHidden = $currentTr.hasClass("hidden");
-            var $delFlagInput = $currentTr.find("td:first-child input:eq(1)");
+        var total = 0; // 用于存储总和
+        // 找到id为workAccountList的tbody
+        const $targetTbody = $('tbody#workAccountList');
+        // 检查tbody是否存在
+        if ($targetTbody.length === 0) {
+            console.error("未找到id为workAccountList的tbody");
+            return 0;
+        }
+        let totalSum = 0; // 用于存储总和
+        // 遍历tbody下的所有行
+        $("tr[id^='workAccountList']").each(function() {
+            var $row = $(this);
+
+            // 2. 排除已删除的行(隐藏或标记删除)
+            var isHidden = $row.hasClass("hidden");
+            var $delFlagInput = $row.find("td:first-child input:eq(1)");
             var isDeleted = $delFlagInput.val() === "1";
+            if (isHidden || isDeleted) {
+                return true; // 继续下一行
+            }
 
-            if (!isHidden && !isDeleted) {
-                total += parseFloat($sumInput.val() || 0);
+            // 3. 提取当前行的索引(从行id中解析,如"workAccountList2" → 2)
+            var rowId = $row.attr("id");
+            var rowIndex = rowId.replace("workAccountList", ""); // 提取数字部分
+            if (!rowIndex) {
+                return true;
+            }
+
+
+            // 4. 计算当前行的金额(单行汇总)
+            var eInvoice = parseFloat($("#workAccountList" + rowIndex + "_eInvoiceMoney").val() || 0);
+
+            // 累加金额(排除非数字值)
+            if (!isNaN(eInvoice)) {
+                total += eInvoice;
+            } else {
+                console.warn("第九个td中的值不是有效的数字:", amountValue, ",行:", $tr);
             }
         });