@ -5,7 +5,7 @@
< / head >
< / head >
< body class = "white-bg" >
< body class = "white-bg" >
< div class = "wrapper wrapper-content animated fadeInRight ibox-content" >
< div class = "wrapper wrapper-content animated fadeInRight ibox-content" >
< form class = "form-horizontal m" id = "form-plan-add" th:object = "${purchasePlanList}" >
< form class = "form-horizontal m" id = "form-plan-purchaseOrder- add" th:object = "${purchasePlanList}" >
< div class = "col-xs-12" >
< div class = "col-xs-12" >
< label class = "col-sm-4 control-label" > 已选择采购计划:< / label >
< label class = "col-sm-4 control-label" > 已选择采购计划:< / label >
< div class = "col-sm-7" >
< div class = "col-sm-7" >
@ -25,30 +25,57 @@
< / div >
< / div >
< / div >
< / div >
< div class = "form-group" >
< div class = "form-group" >
< label for = "inputWarehouseName" class = "col-sm-2 control -label" > 仓库名称:< / label >
< label for = "inputWarehouseName" class = "col-sm-2 col-form -label" > 仓库名称:< / label >
< div class = "col-sm-4" >
< div class = "col-sm-4" >
< input type = "text" class = "form-control" id = "inputWarehouseName" placeholder = "请输入仓库名称" >
< input type = "text" class = "form-control" id = "inputWarehouseName" placeholder = "请输入仓库名称" >
< / div >
< / div >
< / div >
< / div >
< div class = "form-group" >
< div class = "form-group" >
< label for = "inputReceiver" class = "col-sm-2 control -label" > 收货人:< / label >
< label for = "inputReceiver" class = "col-sm-2 col-form -label" > 收货人:< / label >
< div class = "col-sm-4" >
< div class = "col-sm-4" >
< input type = "text" class = "form-control" id = "inputReceiver" placeholder = "请输入收货人" >
< input type = "text" class = "form-control" id = "inputReceiver" placeholder = "请输入收货人" >
< / div >
< / div >
< / div >
< / div >
< div class = "form-group" >
< div class = "form-group" >
< label for = "inputPhone" class = "col-sm-2 control -label" > 收货电话:< / label >
< label for = "inputPhone" class = "col-sm-2 col-form -label" > 收货电话:< / label >
< div class = "col-sm-4" >
< div class = "col-sm-4" >
< input type = "text" class = "form-control" id = "inputPhone" placeholder = "请输入收货电话" >
< input type = "text" class = "form-control" id = "inputPhone" placeholder = "请输入收货电话" >
< / div >
< / div >
< / div >
< / div >
< div class = "form-group" >
< div class = "form-group" >
< label for = "inputAddressDetails" class = "col-sm-2 control -label" > 详细地址:< / label >
< label for = "inputAddressDetails" class = "col-sm-2 col-form -label" > 详细地址:< / label >
< div class = "col-sm-4" >
< div class = "col-sm-4" >
< textarea class = "form-control" id = "inputAddressDetails" > < / textarea >
< textarea class = "form-control" id = "inputAddressDetails" > < / textarea >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
< div class = "container" >
< div class = "row" > < h4 class = "card-header" > 订单合计:< / h4 > < / div >
< div class = "form-group" >
< label for = "purchaseMaterialSum" class = "col-sm-2 col-form-label" > 物料合计:< / label >
< div class = "col-sm-4" >
< input type = "text" class = "form-control" id = "purchaseMaterialSum" >
< / div >
< / div >
< div class = "form-group" >
< label for = "purchaseSum" class = "col-sm-2 col-form-label" > 采购合计:< / label >
< div class = "col-sm-4" >
< input type = "text" class = "form-control" id = "purchaseSum" >
< / div >
< / div >
< div class = "form-group" >
< label for = "purchaseNoRmbSum" class = "col-sm-2 col-form-label" > 不含税采购总价:< / label >
< div class = "col-sm-4" >
< input type = "text" class = "form-control" id = "purchaseNoRmbSum" >
< / div >
< / div >
< div class = "form-group" >
< label for = "purchaseRmbSum" class = "col-sm-2 col-form-label" > 含税采购总价:< / label >
< div class = "col-sm-4" >
< input type = "text" class = "form-control" id = "purchaseRmbSum" >
< / div >
< / div >
< / div >
< / div >
< / div >
< th:block th:include = "include :: footer" / >
< th:block th:include = "include :: footer" / >
< th:block th:include = "include :: bootstrap-table-editable-js" / >
< th:block th:include = "include :: bootstrap-table-editable-js" / >
@ -59,10 +86,10 @@
var sysUnitClassDatas = [[${@dict.getType('sys_unit_class')}]];
var sysUnitClassDatas = [[${@dict.getType('sys_unit_class')}]];
var processMethodDatas = [[${@dict.getType('processMethod')}]];
var processMethodDatas = [[${@dict.getType('processMethod')}]];
var loginName = [[${@permission.getPrincipalProperty('loginName')}]];
var loginName = [[${@permission.getPrincipalProperty('loginName')}]];
$("#form-plan-add").validate({focusCleanup: true});
$("#form-plan-purchaseOrder- add").validate({focusCleanup: true});
var purchasePlanChildList = [[${purchasePlanChildList}]];
var purchasePlanChildList = [[${purchasePlanChildList}]];
var purchasePlanList = [[${purchasePlanList}]];
var purchasePlanList = [[${purchasePlanList}]];
var formId = $( "# form-plan-add").attr("i d") ;
var formId = "form-plan-purch aseOr der-a dd";
//根据物料物料数量添加物料分类表,自动生成类似的表单对象
//根据物料物料数量添加物料分类表,自动生成类似的表单对象
//初始根据采购计划单,涉及到物料做分类表
//初始根据采购计划单,涉及到物料做分类表
//根据采购计划单,获取物料信息,自动生成物料的供应商分类表
//根据采购计划单,获取物料信息,自动生成物料的供应商分类表
@ -134,6 +161,7 @@
// 将整个物料信息容器添加到页面
// 将整个物料信息容器添加到页面
$('#material').append($tableWrapper);
$('#material').append($tableWrapper);
var materialObj = {
var materialObj = {
purchasePlanCode: material.purchasePlanCode,
materialCode: material.materialCode,
materialCode: material.materialCode,
photoUrl: material.photoUrl,
photoUrl: material.photoUrl,
materialName: material.materialName,
materialName: material.materialName,
@ -148,7 +176,53 @@
materialList.push(materialObj);
materialList.push(materialObj);
tables(materialTable, materialData);
tables(materialTable, materialData);
});
});
// 给实际采购数的输入框绑定事件处理器
$('.supplierMaterialNum').off('keyup').on('keyup', function() {
var tableId = $(this).closest('.table-materialCode').attr('id');
recalculateTotals(tableId); // 重新计算当前物料的合计
calculateGlobalTotals(); // 然后重新计算整个订单的合计
});
});
// 新增函数:重新计算某物料的采购数量合计、不含税采购总价和含税采购总价
function recalculateTotals(tableId) {
var actualPurchaseTotal = 0;
var materialNoRmbTotal = 0;
var materialRmbTotal = 0;
$('#' + 'supplier-' + tableId).find('.supplier-card').each(function(supplierIndex, supplierCard) {
var purchaseNum = parseFloat($(supplierCard).find('.supplierMaterialNum').val()) || 0;
var noRmbPrice = parseFloat($(supplierCard).find('.supplierMaterialNoRmb').text().trim());
var rmbPrice = parseFloat($(supplierCard).find('.supplierMaterialRmb').text().trim());
actualPurchaseTotal += purchaseNum;
materialNoRmbTotal += purchaseNum * noRmbPrice;
materialRmbTotal += purchaseNum * rmbPrice;
});
// 更新合计显示
$('#materialNoRmbSum_' + tableId).val(materialNoRmbTotal.toFixed(2)); // 格式化为两位小数
$('#materialRmbSum_' + tableId).val(materialRmbTotal.toFixed(2));
}
function calculateGlobalTotals() {
var totalMaterialSum = 0;
var totalPurchaseSum = 0;
var totalNoRmbSum = 0;
var totalRmbSum = 0;
tableIdList.forEach(function(tableId) {
var materialNoRmbTotal = parseFloat($('#materialNoRmbSum_' + tableId).val()) || 0;
var materialRmbTotal = parseFloat($('#materialRmbSum_' + tableId).val()) || 0;
totalMaterialSum += materialNoRmbTotal; // 假设物料合计就是不含税采购总价
totalPurchaseSum += materialNoRmbTotal; // 假设采购合计也是不含税采购总价(如果逻辑不同,请相应调整)
totalNoRmbSum += materialNoRmbTotal;
totalRmbSum += materialRmbTotal;
});
// 设置合计值,确保处理NaN
$('#purchaseMaterialSum').val(isNaN(totalMaterialSum) ? '' : totalMaterialSum.toFixed(2));
$('#purchaseSum').val(isNaN(totalPurchaseSum) ? '' : totalPurchaseSum.toFixed(2));
$('#purchaseNoRmbSum').val(isNaN(totalNoRmbSum) ? '' : totalNoRmbSum.toFixed(2));
$('#purchaseRmbSum').val(isNaN(totalRmbSum) ? '' : totalRmbSum.toFixed(2));
}
function tableSetup(element, tableId) {
function tableSetup(element, tableId) {
var $totalSection = $(
var $totalSection = $(
'< div class = "card mt-8" > ' +
'< div class = "card mt-8" > ' +
@ -175,8 +249,6 @@
'< / div > ');
'< / div > ');
element.append($totalSection);
element.append($totalSection);
}
}
// 表格初始化函数保持不变
function tables(tableId, data) {
function tables(tableId, data) {
$('#' + tableId).bootstrapTable({
$('#' + tableId).bootstrapTable({
showExport: false,
showExport: false,
@ -217,67 +289,64 @@
],
],
});
});
}
}
// 提交表单的处理函数
});
function submitHandler() {
function submitHandler() {
if ($.validate.form()) {
if ($.validate.form()) {
var purchaseOrder = {
var purchaseOrder = {
purchaseOrderCode: "", // 这里可能需要生成一个临时的或预设的订单号,实际生产环境应由后端生成
supplierNum: 0,
supplierNum: 0,
materialNum: 0,
materialNum: 0,
materialNoRmbSum: 0,
materialNoRmbSum: 0,
materialRmbSum: 0,
materialRmbSum: 0,
purchaseOrderChildList: []
purchaseOrderChildList: []
};
};
// 遍历每个物料容器
// 遍历每个物料容器
$('.table-materialCode').each(function(index, tableElement) {
$('.table-materialCode').each(function(index, tableElement) {
console.log(tableElement);
var tableId = tableIdList[index];
var tableId = tableIdList[index]; // 从table ID中提取tableId
let materialObj = materialList[index];
var materialTable = "bootstrap-table_" + tableId;
if (typeof materialObj === 'undefined') return;
var data = $('#' + materialTable).bootstrapTable('getData');
var materialData = {
materialCode:'' , // 假设'materialCode'是你要获取的字段名}) , // 确保能正确获取物料编码
materialNum:10,
materialNoRmbSum: 0,
materialRmbSum: 0,
purchaseQuoteChildList: []
};
var materialActualNum = $('#' + 'actualPurchaseNum_' + tableId).val();
var materialNoRmbTotal = $('#' + 'materialNoRmbSum_' + tableId).val();
var materialRmbTotal = $('#' + 'materialRmbSum_' + tableId).val();
materialData.materialNum = parseInt(materialActualNum);
materialData.materialNoRmbSum = parseFloat(materialNoRmbTotal);
materialData.materialRmbSum = parseFloat(materialRmbTotal);
// 遍历该物料下的供应商信息
$('#' + 'material-' + tableId).find('.supplier-card').each(function(supplierIndex, supplierCard) {
$('#' + 'material-' + tableId).find('.supplier-card').each(function(supplierIndex, supplierCard) {
var supplierQuote = {
var materialData = {
purchasePlanCode: materialObj.purchasePlanCode,
materialCode: materialObj.materialCode,
materialName: materialObj.materialName,
materialType: materialObj.materialType,
materialBrand:materialObj.brand,
describe: materialObj.describe,
processMethod:materialObj.processMethod,
unit:materialObj.unit,
supplierCode: $(supplierCard).find('.supplierCode').text().trim(),
supplierCode: $(supplierCard).find('.supplierCode').text().trim(),
supplierName: $(supplierCard).find('.supplierName').text().trim(),
supplierName: $(supplierCard).find('.supplierName').text().trim(),
materialNoRmb: parseFloat($(supplierCard).find('.supplierMaterialNoRmb').text().trim()),
materialNoRmb: parseFloat($(supplierCard).find('.supplierMaterialNoRmb').text().trim()),
materialRmb: parseFloat($(supplierCard).find('.supplierMaterialRmb').text().trim()),
materialRmb: parseFloat($(supplierCard).find('.supplierMaterialRmb').text().trim()),
materialNum: $(supplierCard).find('.supplierMaterialNum').val().trim(),
materialNum: parseInt($(supplierCard).find('.supplierMaterialNum').val(), 10) || 0,
deliveryTime: $(supplierCard).find('.supplierDeliveryTime').val()
deliveryTime: $(supplierCard).find('.supplierDeliveryTime').val()
};
};
materialData.purchaseQuoteChildList.push(supplierQuote);
purchaseOrder.purchaseQuoteChildList.push(materialData);
purchaseOrder.supplierNum += 1; // 累加供应商数量
});
});
purchaseOrder.materialNoRmbSum += parseFloat(materialNoRmbTotal) ;
purchaseOrder.materialRmbSum += parseFloat(materialRmbTotal); // 累加含税总价
purchaseOrder.purchaseOrderChildList.push(materialData);
});
});
// 计算整个订单的合计值,这部分应在遍历完所有物料后执行
let totalMaterialNum = purchaseOrder.materialNum;
let totalNoRmbSum = purchaseOrder.materialNoRmbSum;
let totalRmbSum = purchaseOrder.materialRmbSum;
let totalPurchaseSum = totalNoRmbSum; // 或者根据实际业务逻辑调整
// 将合计值附加到purchaseOrder对象
purchaseOrder.totalMaterialSum = totalMaterialNum;
purchaseOrder.totalPurchaseSum = totalPurchaseSum;
purchaseOrder.totalNoRmbSum = totalNoRmbSum.toFixed(2);
purchaseOrder.totalRmbSum = totalRmbSum.toFixed(2);
// 发送数据到后端API
// 发送数据到后端API
$.ajax({
$.ajax({
type: "POST",
type: "POST",
url: prefix + "/add", // 这里的prefix应该是之前定义的context路径
url: prefix + "/add",
data: JSON.stringify(purchaseOrder), // 将构造好的对象转换为JSON字符串
data: JSON.stringify(purchaseOrder),
contentType: "application/json; charset=utf-8",
contentType: "application/json; charset=utf-8",
dataType: "json",
dataType: "json",
success: function (response) {
success: function (response) {
if (response.code === 200) {
if (response.code === 200) {
alert("采购订单添加成功!");
alert("采购订单添加成功!");
// 可以在这里添加更多成功的处理逻辑,如页面跳转等
} else {
} else {
alert("采购订单添加失败:" + response.msg);
alert("采购订单添加失败:" + response.msg);
}
}
@ -287,6 +356,8 @@
alert("提交过程中发生错误,请重试。");
alert("提交过程中发生错误,请重试。");
}
}
});
});
// 如果需要在页面加载时初始化合计或重新绑定事件处理器,这部分应放在更合适的位置,不在此函数内
}
}
}
}
< / script >
< / script >