|
|
@@ -102,6 +102,14 @@
|
|
|
});
|
|
|
// getRandom();
|
|
|
|
|
|
+
|
|
|
+ // 初始化现有tbody
|
|
|
+ initExistingTbodys();
|
|
|
+ // 监听动态生成的tbody
|
|
|
+ setupDOMObserver();
|
|
|
+ // 覆盖上传回调
|
|
|
+ overrideUploadCallback();
|
|
|
+
|
|
|
laydate.render({
|
|
|
elem: '#invoiceDate', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎,因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
|
|
|
event: 'focus', //响应事件。如果没有传入event,则按照默认的click
|
|
|
@@ -309,9 +317,6 @@
|
|
|
"</table>" +
|
|
|
"</td></tr>")
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- console.log("parentIndex",index)
|
|
|
$.ajax({
|
|
|
type : "POST",
|
|
|
url:"${ctx}/workReimbursementNew/workReimbursementNew/formByAccount",
|
|
|
@@ -353,6 +358,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+ // 初始化页面已存在的tbody
|
|
|
+ function initExistingTbodys() {
|
|
|
+ $('tbody[id^="workAccountList_"]:not(.sortable-initialized)').each(function() {
|
|
|
+ initTbodySortable($(this));
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 监听DOM变化
|
|
|
+ function setupDOMObserver() {
|
|
|
+ const tableContainer = document.getElementById('contentTable');
|
|
|
+ if (!tableContainer) return;
|
|
|
+
|
|
|
+ const observer = new MutationObserver(function(mutations) {
|
|
|
+ mutations.forEach(function(mutation) {
|
|
|
+ $(mutation.addedNodes).find('tbody[id^="workAccountList_"]:not(.sortable-initialized)')
|
|
|
+ .each(function() {
|
|
|
+ setTimeout(() => {
|
|
|
+ initTbodySortable($(this));
|
|
|
+ }, 200);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ observer.observe(tableContainer, {
|
|
|
+ childList: true,
|
|
|
+ subtree: true
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 覆盖上传回调
|
|
|
+ function overrideUploadCallback() {
|
|
|
+ const originalUploadFunc = window.newInsertTitleInvoiceReimbursement;
|
|
|
+ if (originalUploadFunc) {
|
|
|
+ window.newInsertTitleInvoiceReimbursement = function(rowId, fileInput) {
|
|
|
+ originalUploadFunc(rowId, fileInput);
|
|
|
+ setTimeout(() => {
|
|
|
+ const $newTbody = $(`#${rowId}`).closest('table').find('tbody[id^="workAccountList_"]:not(.sortable-initialized)');
|
|
|
+ if ($newTbody.length) {
|
|
|
+ initTbodySortable($newTbody);
|
|
|
+ }
|
|
|
+ }, 500);
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 初始化单个tbody的拖拽
|
|
|
+ function initTbodySortable($tbody) {
|
|
|
+ if ($tbody.hasClass('sortable-initialized')) return;
|
|
|
+ $tbody.addClass('sortable-initialized');
|
|
|
+
|
|
|
+ // 用自定义数据属性标记是否正在拖拽(替代instance方法)
|
|
|
+ $tbody.data('isSorting', false);
|
|
|
+
|
|
|
+ $tbody.sortable({
|
|
|
+ items: 'tr:not(.summary-row)',
|
|
|
+ helper: fixHelperModified,
|
|
|
+ stop: function() {
|
|
|
+ updateIndependentIndex($tbody);
|
|
|
+ // 拖拽结束,标记为false
|
|
|
+ $tbody.data('isSorting', false);
|
|
|
+ },
|
|
|
+ update: function() {
|
|
|
+ syncSortOrder($tbody);
|
|
|
+ },
|
|
|
+ containment: $tbody,
|
|
|
+ appendTo: 'body',
|
|
|
+ zIndex: 10000,
|
|
|
+ cancel: '',
|
|
|
+ handle: '',
|
|
|
+ start: function() {
|
|
|
+ console.log('拖拽开始');
|
|
|
+ // 拖拽开始,标记为true
|
|
|
+ $tbody.data('isSorting', true);
|
|
|
+ }
|
|
|
+ }).disableSelection();
|
|
|
+
|
|
|
+ // 处理只读input的点击事件(用自定义数据属性判断)
|
|
|
+ $tbody.find('input[readonly]').on('mousedown', function(e) {
|
|
|
+ if (e.which !== 1) return; // 只处理左键
|
|
|
+
|
|
|
+ const $tr = $(this).closest('tr:not(.summary-row)');
|
|
|
+ if ($tr.length && !$tbody.data('isSorting')) { // 这里替换instance判断
|
|
|
+ // 手动触发tr的mousedown,模拟拖拽
|
|
|
+ $tr.trigger('mousedown', [e]);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保持拖拽时单元格宽度
|
|
|
+ function fixHelperModified(e, tr) {
|
|
|
+ const $originals = tr.children();
|
|
|
+ const $helper = tr.clone();
|
|
|
+ $helper.children().each(function(index) {
|
|
|
+ $(this).width($originals.eq(index).width());
|
|
|
+ });
|
|
|
+ return $helper;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 核心优化:每个tbody独立计算序号(从1开始)
|
|
|
+ function updateIndependentIndex($currentTbody) {
|
|
|
+ // 强制确认当前tbody是否有效
|
|
|
+ if (!$currentTbody || !$currentTbody.length) {
|
|
|
+ console.error("错误:未找到有效的tbody元素");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取tbody的id(兜底处理)
|
|
|
+ const tbodyId = $currentTbody.attr('id') || "匿名tbody";
|
|
|
+
|
|
|
+ // 遍历可拖拽行
|
|
|
+ const $rows = $currentTbody.find('tr:not(.summary-row)');
|
|
|
+ if (!$rows.length) {
|
|
|
+ console.log("[Input统计] tbody[" + tbodyId + "] 内没有可拖拽的行");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ $rows.each(function(rowIndex) {
|
|
|
+ const rowNum = rowIndex + 1;
|
|
|
+ if (isNaN(rowNum)) {
|
|
|
+ console.warn("[警告] tbody[" + tbodyId + "] 行索引异常:" + rowIndex);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const newIndex = rowIndex; // 根据需求调整是否+1
|
|
|
+
|
|
|
+ // 1. 更新序号td
|
|
|
+ const $indexTd = $(this).find('td').eq(2);
|
|
|
+ if ($indexTd.length) {
|
|
|
+ $indexTd.text(newIndex);
|
|
|
+ } else {
|
|
|
+ console.warn("[警告] tbody[" + tbodyId + "] 第" + rowNum + "行未找到第三个td");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 处理第一个td中的input
|
|
|
+ const $firstTd = $(this).find('td').eq(0);
|
|
|
+ if (!$firstTd.length) {
|
|
|
+ console.warn("[警告] tbody[" + tbodyId + "] 第" + rowNum + "行未找到第一个td");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const $allInputsInTd = $firstTd.find('input');
|
|
|
+ const totalInputs = $allInputsInTd.length;
|
|
|
+
|
|
|
+
|
|
|
+ const targetInputIndex = 14; // 第15个input(0开始)
|
|
|
+ if (totalInputs > targetInputIndex) {
|
|
|
+ const $targetInput = $allInputsInTd.eq(targetInputIndex);
|
|
|
+ $targetInput.val(newIndex);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 同步排序数据
|
|
|
+ function syncSortOrder($tbody) {
|
|
|
+ $tbody.find('tr:not(.summary-row)').each(function(index) {
|
|
|
+ const sortIndex = index;
|
|
|
+ const $row = $(this);
|
|
|
+
|
|
|
+ const $idInput = $row.find('input[name*="reimbursementElectronicInvoiceVATTaxes"][name*=".id"]');
|
|
|
+ if ($idInput.length) {
|
|
|
+ const idName = $idInput.attr('name');
|
|
|
+ const sortName = idName.replace('.id', '.sort');
|
|
|
+ let $sortInput = $row.find(`input[name="${sortName}"]`);
|
|
|
+
|
|
|
+ if ($sortInput.length) {
|
|
|
+ $sortInput.val(sortIndex);
|
|
|
+ } else {
|
|
|
+ $row.find('td:first').append(`
|
|
|
+ <input type="hidden" name="${sortName}" value="${sortIndex}">
|
|
|
+ `);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 插入行数据
|
|
|
* @param tbodyId
|
|
|
@@ -392,6 +576,7 @@
|
|
|
"<input id='reimbursementElectronicInvoiceVATTaxes" + trLength +"_fileSize' name='workAccountList[" + parentIndex + "].reimbursementElectronicInvoiceVATTaxes[" + trLength +"].fileSize' type='hidden' value='" + data.fileSize +"'/>"+
|
|
|
"<input id='reimbursementElectronicInvoiceVATTaxes" + trLength +"_divIdType' name='workAccountList[" + parentIndex + "].reimbursementElectronicInvoiceVATTaxes[" + trLength +"].divIdType' type='hidden' value='" + data.divIdType +"'/>" +
|
|
|
"<input id='reimbursementElectronicInvoiceVATTaxes" + trLength +"_parentId' name='workAccountList[" + parentIndex + "].reimbursementElectronicInvoiceVATTaxes[" + trLength +"].parentId' type='hidden' value='" + data.parentId + "'/>" +
|
|
|
+ "<input id='reimbursementElectronicInvoiceVATTaxes" + trLength +"_indexNumber' name='workAccountList[" + parentIndex + "].reimbursementElectronicInvoiceVATTaxes[" + trLength +"].indexNumber' type='hidden' value='" + data.indexNumber + "'/>" +
|
|
|
"</td>"+
|
|
|
|
|
|
<%--序号--%>
|
|
|
@@ -510,7 +695,6 @@
|
|
|
"reimbursementId": $("#wId").val()
|
|
|
},
|
|
|
success:function(data){
|
|
|
- console.log(data)
|
|
|
if(!data.success){
|
|
|
decideFlag = true
|
|
|
parent.layer.msg(data.message, {icon: 5});
|
|
|
@@ -918,6 +1102,7 @@
|
|
|
"<input id='reimbursementElectronicInvoiceVATTaxes" + trLength +"_fileSize' name='workAccountList[" + parentIndex + "].reimbursementElectronicInvoiceVATTaxes[" + trLength +"].fileSize' type='hidden' value=''/>"+
|
|
|
"<input id='reimbursementElectronicInvoiceVATTaxes" + trLength +"_divIdType' name='workAccountList[" + parentIndex + "].reimbursementElectronicInvoiceVATTaxes[" + trLength +"].divIdType' type='hidden' value=''/>" +
|
|
|
"<input id='reimbursementElectronicInvoiceVATTaxes" + trLength +"_parentId' name='workAccountList[" + parentIndex + "].reimbursementElectronicInvoiceVATTaxes[" + trLength +"].parentId' type='hidden' value='" + tbodyId + "'/>" +
|
|
|
+ "<input id='reimbursementElectronicInvoiceVATTaxes" + trLength +"_indexNumber' name='workAccountList[" + parentIndex + "].reimbursementElectronicInvoiceVATTaxes[" + trLength +"].indexNumber' type='hidden' value=''/>" +
|
|
|
"</td>"+
|
|
|
|
|
|
<%--序号--%>
|
|
|
@@ -1145,8 +1330,6 @@
|
|
|
|
|
|
// 处理文件上传
|
|
|
async function handleFileNewUpload(file, size, trlen,inputId,parentIndex) {
|
|
|
- console.log("inputId",inputId)
|
|
|
- console.log("parentIndex",parentIndex)
|
|
|
|
|
|
const $tbody = $(inputId);
|
|
|
|
|
|
@@ -1385,10 +1568,6 @@
|
|
|
|
|
|
// 数电发票删除 - 隐藏行版本(保留DOM,只隐藏)
|
|
|
function delRowNew(obj, prefix, parentIndex) {
|
|
|
- console.log("===== 开始执行delRowNew函数 =====");
|
|
|
- console.log("当前删除按钮元素:", obj);
|
|
|
- console.log("prefix参数:", prefix);
|
|
|
- console.log("parentIndex参数:", parentIndex);
|
|
|
|
|
|
// 获取相关元素
|
|
|
var $idInput = $(prefix + "_id");
|
|
|
@@ -1401,39 +1580,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');
|
|
|
@@ -1444,24 +1616,20 @@
|
|
|
//对数据进行重新处理
|
|
|
updateSummaryRow("#" + tbodyId)
|
|
|
|
|
|
- console.log("查找的tbodyId:", 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; // 继续下一行
|
|
|
}
|
|
|
|
|
|
@@ -1469,16 +1637,13 @@
|
|
|
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(8);
|
|
|
@@ -1487,12 +1652,10 @@
|
|
|
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");
|
|
|
@@ -1500,15 +1663,11 @@
|
|
|
|
|
|
$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中)
|
|
|
@@ -2564,7 +2723,6 @@
|
|
|
}
|
|
|
|
|
|
var idc = $("#workAccountList" + rowIndex + "_id").val();
|
|
|
- console.log("idc", idc);
|
|
|
|
|
|
// 1. 校验idc有效性,避免查找无效元素
|
|
|
if (!idc || idc.trim() === "") {
|
|
|
@@ -2618,7 +2776,6 @@
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- console.log('数电票可报销的最大额度:', maxMoney.toFixed(2));
|
|
|
|
|
|
|
|
|
// 4. 计算当前行的金额(单行汇总)
|
|
|
@@ -2641,7 +2798,6 @@
|
|
|
totalAllInvoice += invoice;
|
|
|
totalAllSum += rowSum;
|
|
|
|
|
|
- console.log("计算汇总金额",eInvoice)
|
|
|
});
|
|
|
|
|
|
// 7. 重新计算总报销费用(传入所有行的非数电票总金额)
|