@ -5,7 +5,7 @@
< / head >
< body class = "white-bg" >
< 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" >
< label class = "col-sm-4 control-label" > 已选择采购计划:< / label >
< div class = "col-sm-7" >
@ -25,30 +25,57 @@
< / div >
< / div >
< 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" >
< input type = "text" class = "form-control" id = "inputWarehouseName" placeholder = "请输入仓库名称" >
< / div >
< / div >
< 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" >
< input type = "text" class = "form-control" id = "inputReceiver" placeholder = "请输入收货人" >
< / div >
< / div >
< 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" >
< input type = "text" class = "form-control" id = "inputPhone" placeholder = "请输入收货电话" >
< / div >
< / div >
< 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" >
< textarea class = "form-control" id = "inputAddressDetails" > < / textarea >
< / 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 >
< th:block th:include = "include :: footer" / >
< th:block th:include = "include :: bootstrap-table-editable-js" / >
@ -59,10 +86,10 @@
var sysUnitClassDatas = [[${@dict.getType('sys_unit_class')}]];
var processMethodDatas = [[${@dict.getType('processMethod')}]];
var loginName = [[${@permission.getPrincipalProperty('loginName')}]];
$("#form-plan-add").validate({focusCleanup: true});
$("#form-plan-purchaseOrder- add").validate({focusCleanup: true});
var purchasePlanChildList = [[${purchasePlanChildList}]];
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);
var materialObj = {
purchasePlanCode: material.purchasePlanCode,
materialCode: material.materialCode,
photoUrl: material.photoUrl,
materialName: material.materialName,
@ -148,136 +176,177 @@
materialList.push(materialObj);
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;
function tableSetup(element, tableId) {
var $totalSection = $(
'< div class = "card mt-8" > ' +
'< div class = "card-body" class = "supplierTotal_' + tableId + '" > ' +
'< div class = "form-row" > ' +
'< label for = "actualPurchaseTotal" class = "col-sm-3" > 实际采购数合计:< / label > ' +
'< div class = "col-sm-8" > ' +
'< input type = "number" name = "materialAmountSum" class = "form-control" id = "materialNoRmbSum_' + tableId + '" readonly > ' +
'< / div > ' +
'< / div > ' +
'< div class = "form-row" > ' +
'< label for = "actualPurchaseTotal" class = "col-sm-3" > 不含税采购总价:< / label > ' +
'< div class = "col-sm-8" > ' +
'< input type = "number" name = "materialNoRmbSum" class = "form-control" id = "materialNoRmbSum_' + tableId + '" readonly > ' +
'< / div > ' +
'< / div > ' +
'< div class = "form-row" > ' +
'< label for = "actualPurchaseTotalTax" class = "col-sm-3" > 含税采购总价:< / label > ' +
'< div class = "col-sm-8" > ' +
'< input type = "number" name = "materialRmbSum" class = "form-control" id = "materialRmbSum_' + tableId + '" readonly > ' +
'< / div > ' +
'< / div > ' +
'< / div > '+
'< / div > ');
element.append($totalSection);
}
$('#' + '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());
// 表格初始化函数保持不变
function tables(tableId, data) {
$('#' + tableId).bootstrapTable({
showExport: false,
showFooter: false,
showSearch: false,
showRefresh: false,
showColumns: false,
showToggle: false,
data: data,
height: 25,
columns: [
{checkbox: false},
{title: '料号', field: 'materialCode'},
{
title: '图片', field: 'photoUrl', formatter: function (value, row, index) {
return $.table.imageView(value);
}
},
{title: '物料名称', field: 'materialName'},
{
title: '物料类型', field: 'materialType', align: 'center', formatter: function (value, row, index) {
return $.table.selectCategoryLabel(materialTypeDatas, value);
}
},
{title: '物料描述', field: 'describe'},
{title: '品牌', field: 'brand'},
{
title: '加工类型', field: 'processMethod', align: 'center', formatter: function (value, row, index) {
return $.table.selectDictLabel(processMethodDatas, value);
}
},
{
title: '单位', field: 'unit', align: 'center', formatter: function (value, row, index) {
return $.table.selectDictLabel(sysUnitClassDatas, value);
}
},
{title: '计划采购数', field: 'planPurchaseNum'},
],
});
}
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) {
var $totalSection = $(
'< div class = "card mt-8" > ' +
'< div class = "card-body" class = "supplierTotal_' + tableId + '" > ' +
'< div class = "form-row" > ' +
'< label for = "actualPurchaseTotal" class = "col-sm-3" > 实际采购数合计:< / label > ' +
'< div class = "col-sm-8" > ' +
'< input type = "number" name = "materialAmountSum" class = "form-control" id = "materialNoRmbSum_' + tableId + '" readonly > ' +
'< / div > ' +
'< / div > ' +
'< div class = "form-row" > ' +
'< label for = "actualPurchaseTotal" class = "col-sm-3" > 不含税采购总价:< / label > ' +
'< div class = "col-sm-8" > ' +
'< input type = "number" name = "materialNoRmbSum" class = "form-control" id = "materialNoRmbSum_' + tableId + '" readonly > ' +
'< / div > ' +
'< / div > ' +
'< div class = "form-row" > ' +
'< label for = "actualPurchaseTotalTax" class = "col-sm-3" > 含税采购总价:< / label > ' +
'< div class = "col-sm-8" > ' +
'< input type = "number" name = "materialRmbSum" class = "form-control" id = "materialRmbSum_' + tableId + '" readonly > ' +
'< / div > ' +
'< / div > ' +
'< / div > '+
'< / div > ');
element.append($totalSection);
}
function tables(tableId, data) {
$('#' + tableId).bootstrapTable({
showExport: false,
showFooter: false,
showSearch: false,
showRefresh: false,
showColumns: false,
showToggle: false,
data: data,
height: 25,
columns: [
{checkbox: false},
{title: '料号', field: 'materialCode'},
{
title: '图片', field: 'photoUrl', formatter: function (value, row, index) {
return $.table.imageView(value);
}
},
{title: '物料名称', field: 'materialName'},
{
title: '物料类型', field: 'materialType', align: 'center', formatter: function (value, row, index) {
return $.table.selectCategoryLabel(materialTypeDatas, value);
}
},
{title: '物料描述', field: 'describe'},
{title: '品牌', field: 'brand'},
{
title: '加工类型', field: 'processMethod', align: 'center', formatter: function (value, row, index) {
return $.table.selectDictLabel(processMethodDatas, value);
}
},
{
title: '单位', field: 'unit', align: 'center', formatter: function (value, row, index) {
return $.table.selectDictLabel(sysUnitClassDatas, value);
}
},
{title: '计划采购数', field: 'planPurchaseNum'},
],
});
}
function submitHandler() {
if ($.validate.form()) {
var purchaseOrder = {
purchaseOrderCode: "", // 这里可能需要生成一个临时的或预设的订单号,实际生产环境应由后端生成
supplierNum: 0,
materialNum: 0,
materialNoRmbSum: 0,
materialRmbSum: 0,
purchaseOrderChildList: []
};
// 遍历每个物料容器
$('.table-materialCode').each(function(index, tableElement) {
console.log(tableElement);
var tableId = tableIdList[index]; // 从table ID中提取tableId
var materialTable = "bootstrap-table_" + tableId;
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);
// 遍历该物料下的供应商信息
var tableId = tableIdList[index];
let materialObj = materialList[index];
if (typeof materialObj === 'undefined') return;
$('#' + 'material-' + tableId).find('.supplier-card').each(function(supplierIndex, supplierCard) {
var supplierQuote = {
supplierCode: $(supplierCard).find('.supplierCode').text().trim(),
supplierName: $(supplierCard).find('.supplierName').text().trim(),
materialNoRmb: parseFloat($(supplierCard).find('.supplierMaterialNoRmb').text().trim()),
materialRmb: parseFloat($(supplierCard).find('.supplierMaterialRmb').text().trim()),
materialNum: $(supplierCard).find('.supplierMaterialNum').val().trim(),
deliveryTime: $(supplierCard).find('.supplierDeliveryTime').val()
};
materialData.purchaseQuoteChildList.push(supplierQuote);
purchaseOrder.supplierNum += 1; // 累加供应商数量
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(),
supplierName: $(supplierCard).find('.supplierName').text().trim(),
materialNoRmb: parseFloat($(supplierCard).find('.supplierMaterialNoRmb').text().trim()),
materialRmb: parseFloat($(supplierCard).find('.supplierMaterialRmb').text().trim()),
materialNum: parseInt($(supplierCard).find('.supplierMaterialNum').val(), 10) || 0,
deliveryTime: $(supplierCard).find('.supplierDeliveryTime').val()
};
purchaseOrder.purchaseQuoteChildList.push(materialData);
});
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
$.ajax({
type: "POST",
url: prefix + "/add", // 这里的prefix应该是之前定义的context路径
data: JSON.stringify(purchaseOrder), // 将构造好的对象转换为JSON字符串
url: prefix + "/add",
data: JSON.stringify(purchaseOrder),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response.code === 200) {
alert("采购订单添加成功!");
// 可以在这里添加更多成功的处理逻辑,如页面跳转等
} else {
alert("采购订单添加失败:" + response.msg);
}
@ -287,6 +356,8 @@
alert("提交过程中发生错误,请重试。");
}
});
// 如果需要在页面加载时初始化合计或重新绑定事件处理器,这部分应放在更合适的位置,不在此函数内
}
}
< / script >