@ -6,27 +6,31 @@
< body class = "white-bg" >
< div class = "wrapper wrapper-content animated fadeInRight ibox-content" >
< form class = "form-horizontal m" id = "form-complaintNotice-edit" th:object = "${aftersalesComplaintNotice}" >
< input name = "complaintNoticeId " th:field = "*{complaintNoticeId }" type = "hidden" >
< div class = "form-group" >
< label class = "col-sm-3 control-label" > 客诉单 号:< / label >
< input name = "complaintNoticeCode " th:field = "*{complaintNoticeCode }" type = "hidden" >
< div class = "form-group" >
< label class = "col-sm-4 control-label" > 客户编 号:< / label >
< div class = "col-sm-8" >
< input name = "complaintNoticeCode" th:field = "*{complaintNoticeCode}" class = "form-control" type = "text" >
< select class = "form-control" id = "customerId" name = "customerId" th:field = "*{customerId}" onchange = "loadMakeNos()" required >
<!-- 这里动态生成客户编号选项 -->
< / select >
< / div >
< / div >
< div class = "form-group" >
< label class = "col-sm-3 control-label" > 关联生产单号 :< / label >
< div class = "form-group" >
< label class = "col-sm-4 control-label" > 客户名称 :< / label >
< div class = "col-sm-8" >
< input name = "makeNo" th:field = "*{makeNo }" class = "form-control" type = "text" >
< input name = "customerName" th:field = "*{customerName }" class = "form-control" type = "text" readonly >
< / div >
< / div >
< div class = "form-group" >
< label class = "col-sm-3 control-label" > 用户ID :< / label >
< div class = "form-group" >
< label class = "col-sm-4 control-label" > 生产单号 :< / label >
< div class = "col-sm-8" >
< input name = "userId" th:field = "*{userId}" class = "form-control" type = "text" >
< select class = "form-control" id = "makeNo" name = "makeNo" th:field = "*{makeNo}" required >
<!-- 这里动态生成生产单号选项 -->
< / select >
< / div >
< / div >
< div class = "form-group" >
< label class = "col-sm-3 control-label" > 紧急程度:< / label >
< label class = "col-sm-4 control-label" > 紧急程度:< / label >
< div class = "col-sm-8" >
< select name = "emergencyDegree" class = "form-control m-b" th:with = "type=${@dict.getType('aftersales_emergency_degree')}" >
< option th:each = "dict : ${type}" th:text = "${dict.dictLabel}" th:value = "${dict.dictValue}" th:field = "*{emergencyDegree}" > < / option >
@ -34,75 +38,326 @@
< / div >
< / div >
< div class = "form-group" >
< label class = "col-sm-3 control-label" > 是否结案 :< / label >
< label class = "col-sm-4 control-label" > 备注信息 :< / label >
< div class = "col-sm-8" >
< select name = "closingProcedures" class = "form-control m-b" th:with = "type=${@dict.getType('aftersales_closing_procedures')}" >
< option th:each = "dict : ${type}" th:text = "${dict.dictLabel}" th:value = "${dict.dictValue}" th:field = "*{closingProcedures}" > < / option >
< / select >
< / div >
< / div >
< div class = "form-group" >
< label class = "col-sm-3 control-label" > 客户ID:< / label >
< div class = "col-sm-8" >
< input name = "customerId" th:field = "*{customerId}" class = "form-control" type = "text" >
< / div >
< / div >
< div class = "form-group" >
< label class = "col-sm-3 control-label" > 客户名称:< / label >
< div class = "col-sm-8" >
< input name = "customerName" th:field = "*{customerName}" class = "form-control" type = "text" >
< / div >
< / div >
< div class = "form-group" >
< label class = "col-sm-3 control-label" > 料号:< / label >
< div class = "col-sm-8" >
< input name = "materialNo" th:field = "*{materialNo}" class = "form-control" type = "text" >
< / div >
< / div >
< div class = "form-group" >
< label class = "col-sm-3 control-label" > 物料名称:< / label >
< div class = "col-sm-8" >
< input name = "materialName" th:field = "*{materialName}" class = "form-control" type = "text" >
< / div >
< / div >
< div class = "form-group" >
< label class = "col-sm-3 control-label" > 物料合计:< / label >
< div class = "col-sm-8" >
< input name = "materialSum" th:field = "*{materialSum}" class = "form-control" type = "text" >
< / div >
< / div >
< div class = "form-group" >
< label class = "col-sm-3 control-label" > 数量合计:< / label >
< div class = "col-sm-8" >
< input name = "enterpriseSum" th:field = "*{enterpriseSum}" class = "form-control" type = "text" >
< input name = "remark" th:field = "*{remark}" class = "form-control" type = "text" >
< / div >
< / div >
< div class = "form-group" >
< label class = "col-sm-3 control-label" > 交货数量:< / label >
< div class = "col-sm-8" >
< input name = "deliveryGoodsNum" th:field = "*{deliveryGoodsNum}" class = "form-control" type = "text" >
< / form >
< div class = "container" >
< div class = "form-row" >
< div class = "btn-group-sm" id = "toolbar" role = "group" >
< span > 选择物料< / span >
< a class = "btn btn-success" onclick = "insertRow()" >
< i class = "fa fa-plus" > < / i > 选择物料
< / a >
< / div >
< / div >
< div class = "form-group" >
< label class = "col-sm-3 control-label" > 备注信息:< / label >
< div class = "col-sm-8" >
< input name = "remark" th:field = "*{remark}" class = "form-control" type = "text" >
< div class = "row" >
< div class = "col-sm-12 select-table table-striped" >
< table id = "bootstrap-table" > < / table >
< / div >
< / div >
< / form >
< / div >
< / div >
< th:block th:include = "include :: footer" / >
<!-- 用于可以修改列表字段的插件 -->
< th:block th:include = "include :: bootstrap-table-editable-js" / >
< script th:inline = "javascript" >
var prefix = ctx + "aftersales/complaintNotice";
var removeFlag = [[${@permission.hasPermi('aftersales:complaintNotice:remove')}]];
var aftersalesComplaintNotice = [[${aftersalesComplaintNotice}]];
var prefix = ctx + "aftersales/complaintNotice"
var customerId = [[${aftersalesComplaintNotice.customerId}]]
var makeNo = [[${aftersalesComplaintNotice.makeNo}]]
$("#form-complaintNotice-edit").validate({
focusCleanup: true
});
// 新增提交
function submitHandler() {
if ($.validate.form()) {
$.operate.save(prefix + "/edit", $('#form-complaintNotice-edit').serialize());
// 获取表单数据
// const complaintNoticeData = $("#form-complaintNotice-edit").serializeArray();
// 获取表单数据
const complaintNoticeData = $("#form-complaintNotice-edit").serializeArray().reduce((obj, item) => {
obj[item.name] = item.value;
return obj;
}, {});
// 获取bootstrap-table的数据,这里假设你使用bootstrap-table的API获取所有数据
var table = $('#bootstrap-table').bootstrapTable('getData');
// 将表数据转换成与complaintNoticeData格式一致的数组
var materialDataList = table.map(function(item) {
// 根据实际字段名调整
return {
"materialNo": item.materialNo, // 假设id对应materialId
"materialPhotourl": item.materialPhotourl, // 假设quantity是物料数量字段
"materialName": item.materialName,
"materialType": item.materialType,
"materialUnit": item.materialUnit,
"materialBrand": item.materialBrand,
"materialDescribe": item.materialDescribe,
"snCode": item.snCode,
"complaintProblem": item.complaintProblem,
// "emergencyDegree": item.emergencyDegree,
"adverseReportUrl": item.adverseReportUrl,
// ...其他字段
};
});
// 合并表单数据和表格数据
//const combinedData = Object.assign({}, ...complaintNoticeData.map(item => ({ [item.name]: item.value })), ...materialData);
const combinedData = Object.assign({}, complaintNoticeData, { aftersalesMaterialVOs: materialDataList });
console.log(combinedData)
// 使用 JSON.stringify() 序列化数据
const jsonData = JSON.stringify(combinedData);
// 发送 AJAX 请求到后端接口
$.operate.saveJson(prefix + "/edit", jsonData);
}
//获取客户信息
$(document).ready(function() {
// 初始化时默认加载客户编号列表
loadCustomerIds();
// 监听客户编号下拉框的变化
$('#customerId').on('change', function() {
var selectedCustomerId = $(this).val(); // 获取选中的客户ID
if (selectedCustomerId) {
// 发起Ajax请求获取客户名称
$.ajax({
type: 'GET',
url: ctx +'system/customer/getCustomerNameByEnterpriseCode/' + selectedCustomerId, // 替换为你的实际API路径
dataType: 'json', // 假设返回的数据格式是JSON
success: function(data) {
console.log(data);
// 将获取到的客户名称填充到输入框
if(data.data == null){
// 如果返回的数据有问题,可以给出提示或处理
alert('未能获取到客户名称!');
}
$('input[name="customerName"]').val(data.data.customerName);
},
error: function(jqXHR, textStatus, errorThrown) {
console.error('Error:', textStatus, errorThrown);
alert('查询客户名称时发生错误!');
}
});
} else {
// 如果没有选择客户ID,清空客户名称输入框
$('input[name="customerName"]').val('');
}
});
});
//获取已经选择客户Id相关的生产单号
function loadMakeNos() {
var selectedCustomerId = $('#customerId').val(); // 获取选中的客户ID
if (!selectedCustomerId) {
// 如果没有选中客户,则清空生产单号下拉框并可添加提示信息
$('#makeNo').empty().append('< option value = "" > 请选择客户编号后加载生产单号< / option > ');
return; // 直接返回,不发起请求
}
var makeNoUrl = ctx + 'aftersales/complaintNotice/getMakeNosByCustomerId/' + selectedCustomerId; // 假定的后端接口URL,根据实际调整
$.ajax({
type: 'GET',
url: makeNoUrl,
dataType: 'json',
success: function(data) {
console.log(data);
if (data & & Array.isArray(data)) {
var selectElement = $('#makeNo'); // 获取生产单号下拉框元素
selectElement.empty(); // 清空现有选项
// 添加默认选项(如果需要)
// selectElement.append('< option value = "" > 请选择生产单号< / option > ');
// 遍历返回的数据,添加为下拉框的选项
$.each(data, function(index, item) {
// 假设item有makeNo属性,代表生产单号
selectElement.append('< option value = "' + item.makeNo + '" > ' + item.makeNo + '< / option > ');
});
$("#makeNo").val(makeNo);
} else {
console.error('数据为空.');
// 可能还需要处理UI显示,比如提示无相关生产单号
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.error('Failed to fetch make numbers: ' + textStatus + ', ' + errorThrown);
// 同样考虑UI反馈,如提示加载失败
}
});
}
// 假设的加载客户编号列表函数
function loadCustomerIds() {
var url = ctx + 'system/customer/getCustomers';
$.ajax({
type: 'GET', // 请求类型
url: url, // 后端接口URL
dataType: 'json', // 预期服务器返回的数据类型
success: function(data) {
if (data & & Array.isArray(data)) {
var selectElement = $('#customerId'); // 获取客户编号下拉框元素
// 清空下拉框现有选项
selectElement.empty();
// // 添加默认选项(如果需要)编辑时不需要添加默认选项
// selectElement.append('< option value = "" > 请选择客户编号< / option > ');
// 遍历返回的数据,添加为下拉框的选项
$.each(data, function(index, item) {
// 假设item有id和name两个属性,分别代表客户ID和客户编号
selectElement.append('< option value = "' + item.customerId + '" > ' + item.customerId + '< / option > ');
});
$('#customerId').val(customerId);
loadMakeNos();
} else {
console.error('Data is not an array or is empty.');
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.error('Failed to fetch customer IDs: ' + textStatus + ', ' + errorThrown);
}
});
}
// 点击选择物料按钮
function insertRow() {
var selectedMakeNo = $("#makeNo").val();
if (!selectedMakeNo) {
alert("请先选择生产单号。");
return;
}
var encodedMakeNo = encodeURIComponent(selectedMakeNo);
var url = ctx + 'aftersales/complaintNotice/materialSelect?makeNo=' + encodedMakeNo;
var options = {
title: '选择物料',
url: url,
callBack: doSubmit
};
$.modal.openOptions(options);
}
//物料信息展示列表
$(function() {
var options = {
url: ctx + "aftersales/complaintNotice/getMaterialListByNoticeCode",
queryParams: queryParams,
modalName: "选择物料",
columns: [{
checkbox: true
},
{
title: '料号',
field: 'materialNo',
},
{
title: '图片',
field: 'materialPhotourl',
},
{
title: '物料名称',
field: 'materialName',
},
{
title: '物料类型',
field: 'materialType',
},
{
title: '单位',
field: 'materialUnit',
},
{
title: '品牌',
field: 'materialBrand',
},
{
title: '描述',
field: 'materialDescribe',
},
{
title: 'SN号',
field: 'snCode',
editable: {
type: 'text', // 表示该列可以被编辑为文本
},
},
{
title: '客诉问题',
field: 'complaintProblem',
editable: {
type: 'text', // 表示该列可以被编辑为文本
},
},
{
title: '售后问题',
field: 'adverseReportUrl',
editable: {
type: 'text', // 表示该列可以被编辑为文本
// 可以在这里定义更多编辑行为,比如验证、提交等
},
},
{
title: '操作',
align: 'center',
formatter: function(value, row, index) {
var actions = [];
actions.push('< a class = "btn btn-danger btn-xs" href = "javascript:void(0)" onclick = "removeRow(\'' + row.materialNo + '\')" > < i class = "fa fa-remove" > < / i > 删除< / a > ');
return actions.join('');
}
}
]
};
$.table.init(options);
})
function queryParams(params) {
var curParams = {
// 传递参数查询参数
complaintNoticeCode: aftersalesComplaintNotice.complaintNoticeCode
};
console.log(curParams);
return curParams;
}
function doSubmit(index, layero,uniqueId){
console.log(uniqueId);
var iframeWin = window[layero.find('iframe')[0]['name']];
var rowData = iframeWin.$('#bootstrap-materialSelect-table').bootstrapTable('getSelections')[0];
console.log("rowData: "+rowData);
$("#bootstrap-table").bootstrapTable('insertRow', {
index:1,
row: {
materialNo:rowData.materialNo,
materialPhotourl:rowData.materialPhotourl,
materialName: rowData.materialName,
materialType: rowData.materialType,
materialDescribe: rowData.materialDescribe,
materialBrand: rowData.materialBrand,
materialUnit: rowData.materialUnit,
materialProcessMethod: rowData.materialProcessMethod,
shippedGoodsSum: rowData.shippedGoodsSum,
snCode:"",
complaintProblem:"",
adverseReportUrl:"",
}
})
layer.close(index);
}
// 逻辑删除前端的一行数据
function removeRow(materialNo){
$("#bootstrap-table").bootstrapTable('remove', {
field: 'materialNo',
values: materialNo
})
}
< / script >
< / body >
< / html >