提交 4b392f21 authored 作者: kxjia's avatar kxjia

Tb2.vue 修改

上级 deef9285
...@@ -517,6 +517,19 @@ function collectAllFields(content, fields = []) { ...@@ -517,6 +517,19 @@ function collectAllFields(content, fields = []) {
collectAllFields(item.extraFields[key], fields); collectAllFields(item.extraFields[key], fields);
} }
} }
if (item.formType === 'AttachTable' && item.gridOptions && item.gridOptions.datas) {
for (const data of item.gridOptions.datas) {
for (const key in data) {
if (data[key] && typeof data[key] === 'object' && data[key].field) {
fields.push({ field: data[key].field, formType: data[key].formType });
if (data[key].otherField) {
fields.push({ field: data[key].otherField, formType: 'input' });
}
}
}
}
}
} }
return fields; return fields;
......
...@@ -528,20 +528,41 @@ const getFormData = () => { ...@@ -528,20 +528,41 @@ const getFormData = () => {
} }
const setFormData = (dataVale) => { const setFormData = (dataVale) => {
console.log('MultiColumnTable setFormData called, dataVale:', dataVale);
tableData.value = dataVale.map(row => { tableData.value = dataVale.map(row => {
const newRow = { ...row } const newRow = { ...row }
props.fields.forEach(field => { props.fields.forEach(field => {
if(field.formType === 'table') { if(field.formType === 'table') {
field.gridOptions.data = JSON.parse(row[field.field]) const fieldWithGrid = field as any;
fieldWithGrid.gridOptions.data = JSON.parse(row[field.field])
} else if(field.formType === 'AttachTable') { } else if(field.formType === 'AttachTable') {
const key = `${field.field}_${dataVale.indexOf(row)}`; const key = `${field.field}_${dataVale.indexOf(row)}`;
const child = attchTableRefs.value[key]; const child = attchTableRefs.value[key];
console.log('MultiColumnTable AttachTable - key:', key, 'child:', child, 'row:', row);
if (child && child.setFormData) { if (child && child.setFormData) {
child.setFormData(dataVale) const tableData = {};
const fieldWithGrid = field as any;
console.log('MultiColumnTable AttachTable - fieldWithGrid:', fieldWithGrid);
if (fieldWithGrid.gridOptions && fieldWithGrid.gridOptions.datas) {
console.log('MultiColumnTable AttachTable - gridOptions.datas:', fieldWithGrid.gridOptions.datas);
fieldWithGrid.gridOptions.datas.forEach((dataRow: any, rowIndex: number) => {
console.log(`MultiColumnTable AttachTable - dataRow[${rowIndex}]:`, dataRow);
Object.values(dataRow).forEach((cellValue: any, cellIndex: number) => {
console.log(`MultiColumnTable AttachTable - cellValue[${cellIndex}]:`, cellValue);
if (cellValue && typeof cellValue === 'object' && cellValue.field) {
console.log(`MultiColumnTable AttachTable - found field: ${cellValue.field}, value in row:`, row[cellValue.field]);
tableData[cellValue.field] = row[cellValue.field];
}
});
});
}
console.log('MultiColumnTable AttachTable - final tableData:', tableData);
child.setFormData(tableData);
} }
} else if (field.formType === 'combinaform') { } else if (field.formType === 'combinaform') {
if (field.childs && Array.isArray(field.childs)) { const fieldWithChilds = field as any;
field.childs.forEach(child => { if (fieldWithChilds.childs && Array.isArray(fieldWithChilds.childs)) {
fieldWithChilds.childs.forEach((child: any) => {
if (child.formType === 'checkbox' && !Array.isArray(newRow[child.field])) { if (child.formType === 'checkbox' && !Array.isArray(newRow[child.field])) {
newRow[child.field] = [] newRow[child.field] = []
} }
...@@ -569,7 +590,7 @@ const gridEvents: VxeGridListeners = { ...@@ -569,7 +590,7 @@ const gridEvents: VxeGridListeners = {
toolbarButtonClick(params) { toolbarButtonClick(params) {
if (params.code === "add") { if (params.code === "add") {
const fieldName = params.button.field const fieldName = (params.button as any).field
const fieldConfig = props.fields.find(field => field.field === fieldName) const fieldConfig = props.fields.find(field => field.field === fieldName)
if (fieldConfig && fieldConfig.gridOptions) { if (fieldConfig && fieldConfig.gridOptions) {
const newRow: Record<string, any> = {} const newRow: Record<string, any> = {}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论