1.列表展示合并字段及默认下拉值
$("#experimentDataList").datagrid({
url: '${ctx}/wqm/blueprint/getExperimentsByTosamplenumber',
queryParams: {
matcode: '${matcode}',
itemRevisionId: '${itemRevisionId}'
},
// 图标
iconCls: 'icon-save',
rownumbers: true,
fitColumns: false,
remoteSort: true,
border: true,
fit: true,
// 行背景交换
striped: true,
// 列内容多时自动折至第二行
nowrap: true,
// border: false,
// 主键
idField: 'id',
// 显示的列
columns: [[
{field:'id', title: 'ID', checkbox: true},
{field: 'characteristicDescription', title: '特性描述', align: 'center', width: 150, editor: "text"},
{field: 'measuringSize', title: '测量尺寸文本', align: 'center', width: 120,
formatter: function(value, row, index) {
// ✅ 安全检查:确保 DICT_feature_description 存在且有数据
if (!DICT_feature_description || !Array.isArray(DICT_feature_description)) {
return value; // 字典未加载,显示原始 value
}
// 查找匹配项
for (var i = 0; i < DICT_feature_description.length; i++) {
var item = DICT_feature_description[i];
if (item.value == value) {
return item.label;
}
}
return value; // 没找到就返回原始值
},
editor: {
type: 'combobox',
options: {
url: '${ctx}/sys/dict/listData?type=feature_description',
valueField: 'value',
textField: 'label',
editable: true,
prompt: '输入关键词搜索',
panelHeight: 'auto',
filter: function(q, row) {
var text = (row.label || '').toLowerCase();
return text.indexOf(q.toLowerCase()) >= 0;
}
}
}
},
{field: 'nominalValue', title: '名义值', align: 'center', width: 100,editor: "text"},
{field: 'upperAllowance', title: '上公差', align: 'center', width: 100,editor: "text"},
{field: 'lowerAllowance', title: '下公差', align: 'center', width: 100,editor: "text"},
{field: '区域', title: '区域', align: 'center', width: 100,
formatter: function(value, row) {
const char = row.balloonDrawingFieldCharacter;
const num = row.balloonDrawingFieldNumber;
// 如果任一字段为 null、undefined 或空字符串,则返回空
if (!char || !num) {
return '无';
}
return char + num;
}},
{field: 'remark', title: '备注', align: 'center', width: 150,editor: "text"},
{field: 'checkPlatformName', title: '检验坊', align: 'center', width: 120, editor: {
type: 'combobox', // 使用combobox作为编辑器
options: {
data: [
{value: '通用检验坊', text: '通用检验坊'},
{value: '精测检验坊', text: '精测检验坊'},
{value: '清洁度检验坊', text: '清洁度检验坊'},
{value: '理化检验坊', text: '理化检验坊'},
],
editable: false, // 禁止手动输入,仅允许从下拉列表中选择
panelHeight: 'auto' // 下拉面板的高度自适应内容
}
}},
{field: 'toolType', title: '量检具类型', align: 'center', width: 120,
// formatter: function(value, row, index) {
// // 显示时直接显示 value(因为 textField 和 valueField 都是 toolType)
// return value || '';
// },
editor: {
type: 'combobox',
options: {
url: '${ctx}/wqm/measureTool/findToolType',
valueField: 'toolType',
textField: 'toolType',
editable: true, // ✅ 允许输入,否则无法搜索
prompt: '输入关键词模糊搜索...', // ✅ 提示文字
panelHeight: 'auto',
// 🔍 核心:实现模糊匹配
filter: function(q, row) {
// q: 用户输入的关键词
// row: 每一条数据 { toolType: "卡尺" }
var text = (row.toolType || '').toLowerCase(); // 转小写
return text.indexOf(q.toLowerCase()) >= 0; // 包含匹配
}
}
}
},
{field: 'featureType', title: '特性类型', align: 'center', width: 120,editor: {
type: 'combobox', // 使用combobox作为编辑器
options: {
data: [
{value: '计数型', text: '计数型'},
{value: '计量型', text: '计量型'},
],
editable: false, // 禁止手动输入,仅允许从下拉列表中选择
panelHeight: 'auto' // 下拉面板的高度自适应内容
}
}},
{field: 'frequencyCode', title: '频次类型', align: 'center', width: 120,editor: {
type: 'combobox',
options: {
url: '${ctx}/wqm/checkFrequency/findCheckFrequency', // 假设这是获取选项的API路径
valueField: 'frequencyCode',
textField: 'frequencyName',
editable: false,
panelHeight: 'auto'
}
}},
// {field: 'file', title: '作业指导书', align: 'center', width: 200, editor: {
// type: 'fileupload',
// options: {
// onChange: function(file, callback) {
// // 文件选择后触发上传
// uploadFile(this, file, callback);
// }
// // 可选:onDelete: function() { ... }
// }
// }},
{field: 'taskTime', title: '工时(min)', align: 'center', width: 120,editor: "text"},
{field: 'unqualifiedConclusion', title: '不合格处理方式', align: 'center', width: 120,editor: {
type: 'combobox', // 使用combobox作为编辑器
options: {
data: [
{value: '退货', text: '退货'},
{value: '销毁', text: '销毁'},
],
value: '退货',
editable: false, // 禁止手动输入,仅允许从下拉列表中选择
panelHeight: 'auto' // 下拉面板的高度自适应内容
}
}},
{field: 'featureGroup', title: '特性组', align: 'center', width: 120, editor: {
type: 'numberbox', // 使用 numberbox 作为编辑器
options: {
min: 1, // 最小值为 1
max: 9, // 最大值为 9
precision: 0, // 精度为 0,即只允许整数
editable: true, // 允许输入(默认为 true,可省略)
prompt: '输入1-9的数字' // 可选提示信息
}
}}
]],
onLoadSuccess: function (data){
markerArr = [];//重置所有标记的集合
allData = data.rows;//记录所有特性的初始数据
$("#experimentDataList").datagrid('clearSelections');//清除行选中
featureId = "";
numFlag++;
pdfjsLib.GlobalWorkerOptions.workerSrc =
'${ctxStatic}/common/pdf.worker.min.js';
showPdfContainer();//加载pdf文件
// 在 beginEdit 前,先处理默认值
const rows = data.rows;
for (let i = 0; i < rows.length; i++) {
const row = rows[i];
// 如果 unqualifiedConclusion 为空,设置为 '退货'
if (!row.unqualifiedConclusion || row.unqualifiedConclusion.trim() === '') {
row.unqualifiedConclusion = '退货';
// 更新表格数据(否则编辑器拿不到)
$('#experimentDataList').datagrid('updateRow', {
index: i,
row: row
});
}
// 开始编辑
$('#experimentDataList').datagrid('beginEdit', i);
}
},
onSelect: function(index, row){
changeSelectRow();
},
onUnselect: function(index, row){
changeSelectRow();
},
toolbar: [
{text: '新增', iconCls: 'icon-add', handler: function () {
const datagrid = $('#experimentDataList');
const rowsNum = datagrid.datagrid('getRows').length;
const newIndex = rowsNum; // 新增行的索引
// 添加新行(注意这里不需要为所有字段提供值)
datagrid.datagrid('appendRow', {});
// console.log("After appending a new row, rows count:", datagrid.datagrid('getRows').length);
// 开始编辑新添加的行
datagrid.datagrid('beginEdit', newIndex);
}
}, '-',
{ text: '删除', iconCls: 'icon-remove', handler: function () {
let selectedRows = $("#experimentDataList").datagrid('getChecked');
if (selectedRows.length > 0) {
$.each(selectedRows, function(index, row){
$("#experimentDataList").datagrid('deleteRow', $("#experimentDataList").datagrid('getRowIndex', row));
});
} else {
$.messager.alert('提示', '请选择要删除的行!', 'warning');
}
}
},
// '-',
// { text: '图纸标记', iconCls: 'icon-edit', handler: function () {
// let selectedRows = $("#experimentDataList").datagrid('getChecked');
// if (!selectedRows || selectedRows.length <= 0) {
// $.messager.alert('提示', '请选择要标记的特性!', 'warning');
// return;
// } else if(selectedRows.length>1) {
// $.messager.alert('提示', '只能选择一条特性记录!', 'warning');
// return;
// }
// let featureData = selectedRows[0];
// if(featureData.xCoordinate && featureData.yCoordinate){
// let scale = $("#scale").val();
// marker.originalX = featureData.xCoordinate;
// marker.originalY = featureData.yCoordinate;
// if(!featureData.radius){
// featureData.radius = 20;
// }
// marker.originalRadius = featureData.radius;
// marker.x = marker.originalX * scale;
// marker.y = marker.originalY * scale;
// marker.radius = marker.originalRadius * scale;
// $("#radius").numberspinner("setValue",marker.radius)
// }else{
// marker = {};
// }
// featureId = featureData.id;
// showPdfContainer();
// }
// },
// '-',
// { text: '隐藏图纸', iconCls: 'icon-cancel', handler: function () {
// $("#pdf-container").hide();
// }
// }
],
});