@ -80,7 +80,7 @@
< div class = "col-sm-12" >
< div class = "col-sm-12" >
< button type = "button" class = "btn btn-blue btn-sm" onclick = "processadd()" > < i class = "fa fa-plus" > 增加< / i > < / button >
< button type = "button" class = "btn btn-blue btn-sm" onclick = "processadd()" > < i class = "fa fa-plus" > 增加< / i > < / button >
< div class = "col-sm-12 select-table table-striped" >
< div class = "col-sm-12 select-table table-striped" >
< table id = "bootstrap-table" > < / table >
< table id = "bootstrap-table-process " > < / table >
< / div >
< / div >
< / div >
< / div >
< / div >
< / div >
@ -115,51 +115,58 @@
};
};
function submitHandler() {
function submitHandler() {
if ($.validate.form()) {
var url = prefix + "/edit";
var url = prefix + "/edit";
var outsourceQuote = {
};
if ($.validate.form()) {
if ($.validate.form()) {
var outsourceQuoteChildList = [];
// 获取表单数据
// 获取表单数据
const outsourceQuoteData = $("#form-outsource_quote-edit").serializeArray().reduce((obj, item) => {
const outsourceQuoteData = $("#form-outsource_quote-edit").serializeArray().reduce((obj, item) => {
obj[item.name] = item.value;
obj[item.name] = item.value;
return obj;
return obj;
}, {});
}, {});
// console.log(outsourceQuoteData);
console.log(outsourceQuoteData);
outsourceQuote = {
outsourceQuoteId: outsourceQuoteData.outsourceQuoteId,
outsourceQuoteCode: outsourceQuoteData.outsourceQuoteCode,
supplierQuoteCode: outsourceQuoteData.supplierCode,
supplierName: outsourceQuoteData.supplierName,
pricingDate: outsourceQuoteData.pricingDate,
taxRate: outsourceQuoteData.taxRate,
remark: outsourceQuoteData.remark,
processAmount: 0,
outsourceQuoteChildList: []
}
// 获取bootstrap-table的数据,这里假设你使用bootstrap-table的API获取所有数据
// 获取bootstrap-table的数据,这里假设你使用bootstrap-table的API获取所有数据
var rows = $('#bootstrap-table').bootstrapTable('getData');
var rows = $('#bootstrap-table-process').bootstrapTable('getData');
// console.log(JSON.stringify(rows));
// 检查表格数据是否为空
// 检查表格数据是否为空
if (rows.length === 0) {
if (rows.length === 0) {
$.modal.alertWarning("请至少添加一条委外工序再保存!");
$.modal.alertWarning("请至少添加一条委外工序再保存!");
return;
return;
}
}else{
// 将表数据转换成与qualityReportData格式一致的数组
console.log(rows);
var outsourceQuoteChildList = rows.map(function (item) {
outsourceQuote.processAmount = rows.length;
// 根据实际字段名调整
var unit = getUnit();
return {
var noRmb = getNoRmb();
"outsourceProcessCode": item.outsourceProcessCode,
var rmb = getRmb();
"outsourceProcessNo": item.outsourceProcessNo,
for(var i=0;i< rows.length ; i + + ) {
"chargeUnit": item.chargeUnit,
var quoteChild = {
"materialRmb": item.materialRmb,
outsourceProcessCode: rows[i].outsourceProcessCode,
"materialNormb": item.materialNormb,
outsourceProcessNo: rows[i].outsourceProcessNo,
outsourceProcessName: rows[i].outsourceProcessName,
// ...其他字段
chargeUnit:unit[i],
materialNormb: noRmb[i],
materialRmb: rmb[i],
};
};
});
outsourceQuote.outsourceQuoteChildList.push(quoteChild);
const combinedData = Object.assign({}, outsourceQuoteData,
{
outsourceQuoteChildList: outsourceQuoteChildList,
},
);
// 合并表单数据和表格数据
// const combinedData = Object.assign({}, ...complaintNoticeData.array(item => ({ [item.name]: item.value })), ...materialData);
console.log(combinedData)
// 使用 JSON.stringify() 序列化数据
const jsonData = JSON.stringify(combinedData);
// 发送 AJAX 请求到后端接口
saveJson(prefix + "/edit", jsonData);
}
}
console.log(outsourceQuote);
}
}
};
saveJson(prefix + "/edit", JSON.stringify(outsourceQuote));
}
}
function processadd() {
function processadd() {
var url = prefix + "/processadd";
var url = prefix + "/processadd";
var options = {
var options = {
@ -175,61 +182,130 @@
// // 这里取到的是多行的
// // 这里取到的是多行的
var rowData = layero.find("iframe")[0].contentWindow.getSelections();
var rowData = layero.find("iframe")[0].contentWindow.getSelections();
//判断是否重复
//判断是否重复
var rows = $("#bootstrap-table").bootstrapTable('getData').length;
var rows = $("#bootstrap-table-process ").bootstrapTable('getData').length;
if(rows>0){
if(rows>0){
for(var i=0;i< rows ; i + + ) {
for(var i=0;i< rows ; i + + ) {
var data = $("#bootstrap-table").bootstrapTable('getData')[i];
var data = $("#bootstrap-table-process ").bootstrapTable('getData')[i];
for(var j=0;j< rowData.length ; j + + ) {
for(var j=0;j< rowData.length ; j + + ) {
if(data.outsourceProcessCode==rowData[j].outsourceProcessCode ){
if(data.outsourceProcessNo==rowData[j].outsourceProcessNo ){
$.modal.alertError("不能选择已添加过的相同工序");
$.modal.alertError("不能选择已添加过的相同工序");
return;
return;
}
}
insertTable(rowData[i]);
}
}
sub.addRow(rowData[i]);
};
};
}else{
}else{
for(i=0;i< rowData.length ; i + + ) {
for(i=0;i< rowData.length ; i + + ) {
sub.addRow (rowData[i]);
insertTable (rowData[i]);
}
}
}
}
layer.closeAll();
layer.closeAll();
}
}
function insertTable(rowData) {
$("#bootstrap-table-process").bootstrapTable('insertRow', {
index: 1,
row: {
outsourceProcessNo: rowData.outsourceProcessNo,
outsourceProcessCode: rowData.outsourceProcessCode,
outsourceProcessName: rowData.outsourceProcessName,
materialNoRmb: 0.00,
materialRmb: 0.00,
}
});
}
function getUnit(){
var selectElements = $('#bootstrap-table-process').find('select[id^="chargeUnit"]');
// 遍历每个下拉框
var unit = [];
selectElements.each(function() {
// 获取当前下拉框的值
var selectedValue = $(this).val();
unit.push(selectedValue);
});
console.log(unit);
return unit;
}
function getNoRmb(){
var selectElements = $('#bootstrap-table-process').find('input[id^="materialNormb"]');
// 遍历每个下拉框
var noRmb = [];
selectElements.each(function() {
// 获取当前下拉框的值
var selectedValue = $(this).val();
noRmb.push(selectedValue);
});
// console.log(noRmb);
return noRmb;
};
function getRmb(){
var selectElements = $('#bootstrap-table-process').find('input[id^="materialRmb"]');
// 遍历每个输入框
var rmb = [];
selectElements.each(function() {
// 获取当前输入框的值
var selectedValue = $(this).val();
rmb.push(selectedValue);
});
// console.log(rmb);
return rmb;
};
function initTable(data,index){
$("#bootstrap-table-process").bootstrapTable('insertRow', {
index:1,
row: {
outsourceProcessNo: data.outsourceProcessNo,
outsourceProcessCode: data.outsourceProcessCode,
outsourceProcessName: data.outsourceProcessName,
}
});
$('#bootstrap-table-process').find('select[id="chargeUnit'+index+'"]').val(data.chargeUnit);
$('#bootstrap-table-process').find('input[id="materialNormb'+index+'"]').val(data.materialNormb);
$('#bootstrap-table-process').find('input[id="materialRmb'+index+'"]').val(data.materialRmb);
};
$(function() {
$(function() {
var options = {
var options = {
data: [[${outsourceQuote.outsourceQuoteChildList}]],
id: "bootstrap-table-process" ,
pagination: false,
pagination: false,
showSearch: false,
showSearch: false,
showRefresh: false,
showRefresh: false,
showToggle: false,
showToggle: false,
showColumns: false,
showColumns: false,
sidePagination: "client",
sidePagination: "client",
data: [[${outsourceQuote.outsourceQuoteChildList}]],
columns: [
columns: [
{
{
field: 'outsourceProcessId',
field: 'outsourceProcessId',
align: 'center',
align: 'center',
title: '委外工序主键',
title: '委外工序主键',
visible: false,
visible: false,
formatter: function(value, row, index) {
var html = $.common.sprintf("< input class = 'form-control' type = 'text' readonly = 'readonly' name = 'outsourceQuoteChildList[%s].outsourceProcessId' value = '%s' > ", index, value);
return html;
}
},
},
{
{
field: 'outsourceProcessNo',
field: 'outsourceProcessNo',
align: 'center',
align: 'center',
title: '委外工序编号',
title: '委外工序编号',
formatter: function(value, row, index) {
var html = $.common.sprintf("< input class = 'form-control' type = 'text' name = 'outsourceQuoteChildList[%s].outsourceProcessNo' value = '%s' > ", index, value);
return html;
}
},
},
{
{
field: 'outsourceProcessName',
field: 'outsourceProcessName',
align: 'center',
align: 'center',
title: '委外工序名称',
title: '委外工序名称',
},
{
field: 'chargeUnit',
align: 'center',
title: '计价单位',
width: 120,
// overflow: visible,
formatter: function(value, row, index) {
formatter: function(value, row, index) {
var html = $.common.sprintf("< input class = 'form-control' type = 'text' name = 'outsourceQuoteChildList[%s].outsourceProcessName' value = '%s' > ", index, value);
var html = $.common.sprintf("< select class = 'form-control' id = 'chargeUnit" + index + "' data-first-title = '请选择' > " +
"< option value = '' > 请选择< / option > " +
"< option value = '0' > 按重量计< / option > " +
"< option value = '1' > 按数量计< / option > " +
"< option value = '2' > 按面积计< / option > " +
"< / select > ", index, value);
return html;
return html;
}
}
},
},
@ -238,7 +314,7 @@
align: 'center',
align: 'center',
title: '工序的不含税单价(RMB) ',
title: '工序的不含税单价(RMB) ',
formatter: function(value, row, index) {
formatter: function(value, row, index) {
var html = $.common.sprintf("< input class = 'form-control' type = 'text' name = 'outsourceQuoteChildList[%s].materialNormb' value = '%s '> ", index, value);
var html = $.common.sprintf("< input class = 'form-control' type = 'text' id = 'materialNormb" + index + " '> ", index, value);
return html;
return html;
}
}
},
},
@ -247,7 +323,7 @@
align: 'center',
align: 'center',
title: '工序的含税单价(RMB)',
title: '工序的含税单价(RMB)',
formatter: function(value, row, index) {
formatter: function(value, row, index) {
var html = $.common.sprintf("< input class = 'form-control' type = 'text' name = 'outsourceQuoteChildList[%s].materialRmb' value = '%s '> ", index, value);
var html = $.common.sprintf("< input class = 'form-control' type = 'text' id = 'materialRmb" + index + " '> ", index, value);
return html;
return html;
}
}
},
},
@ -260,31 +336,21 @@
}
}
}]
}]
};
};
// console.log(options.data);
$.table.init(options);
$.table.init(options);
var quoteDetail = options.data;
$.each(quoteDetail, function(index, item) {
// 设置下拉框的值
$('#chargeUnit' + index).val(item.chargeUnit);
// 设置不含税单价输入框的值
$('#materialNormb' + index).val(item.materialNormb);
// 设置含税单价输入框的值
$('#materialRmb' + index).val(item.materialRmb);
});
});
});
function addRow() {
var count = $("#" + table.options.id).bootstrapTable('getData').length;
var row = {
index: $.table.serialNumber(count),
outsourceQuoteCode: "",
outsourceProcessNo: "",
outsourceProcessName: "",
remark: "",
taxRate: "",
materialRmb: "",
materialNormb: "",
supplierCode: "",
supplierName: "",
createBy: "",
createTime: "",
updateBy: "",
updateTime: "",
auditStatus: "",
}
sub.addRow(row);
};
< / script >
< / script >
< / body >
< / body >
< / html >
< / html >