提交 0693e358 authored 作者: kxjia's avatar kxjia

AttachTable.vue

上级 0cf23678
...@@ -231,6 +231,7 @@ const getFormData = () => { ...@@ -231,6 +231,7 @@ const getFormData = () => {
} }
const setFormData = (dataVale) => { const setFormData = (dataVale) => {
alert(JSON.stringify(dataVale))
Object.assign(formData, dataVale); Object.assign(formData, dataVale);
} }
......
...@@ -494,7 +494,7 @@ const removeEmptyValues = (obj: Record<string, any>) => { ...@@ -494,7 +494,7 @@ const removeEmptyValues = (obj: Record<string, any>) => {
const getFormData = () => { const getFormData = () => {
console.log(tableData.value)
const cleanedData = tableData.value.map((row) => { const cleanedData = tableData.value.map((row) => {
const cleanedRow: Record<string, any> = {}; const cleanedRow: Record<string, any> = {};
copyNonEmpty(row,cleanedRow) copyNonEmpty(row,cleanedRow)
...@@ -529,48 +529,47 @@ const getFormData = () => { ...@@ -529,48 +529,47 @@ const getFormData = () => {
const setFormData = (dataVale) => { const setFormData = (dataVale) => {
console.log('MultiColumnTable setFormData called, dataVale:', dataVale); console.log('MultiColumnTable setFormData called, dataVale:', dataVale);
tableData.value = dataVale.map(row => { tableData.value = dataVale.map((row, rowIndex) => {
const newRow = { ...row } const newRow = { ...row }
props.fields.forEach(field => { return newRow
if(field.formType === 'table') { })
const fieldWithGrid = field as any;
fieldWithGrid.gridOptions.data = JSON.parse(row[field.field]) nextTick(() => {
} else if(field.formType === 'AttachTable') { tableData.value.forEach((row, rowIndex) => {
const key = `${field.field}_${dataVale.indexOf(row)}`; props.fields.forEach(field => {
const child = attchTableRefs.value[key]; if(field.formType === 'table') {
console.log('MultiColumnTable AttachTable - key:', key, 'child:', child, 'row:', row);
if (child && child.setFormData) {
const tableData = {};
const fieldWithGrid = field as any; const fieldWithGrid = field as any;
console.log('MultiColumnTable AttachTable - fieldWithGrid:', fieldWithGrid); fieldWithGrid.gridOptions.data = JSON.parse(row[field.field])
if (fieldWithGrid.gridOptions && fieldWithGrid.gridOptions.datas) { } else if(field.formType === 'AttachTable') {
console.log('MultiColumnTable AttachTable - gridOptions.datas:', fieldWithGrid.gridOptions.datas); const key = `${field.field}_${rowIndex}`;
fieldWithGrid.gridOptions.datas.forEach((dataRow: any, rowIndex: number) => { const child = attchTableRefs.value[key];
console.log(`MultiColumnTable AttachTable - dataRow[${rowIndex}]:`, dataRow); if (child && child.setFormData) {
Object.values(dataRow).forEach((cellValue: any, cellIndex: number) => { const tableData: Record<string, any> = {};
console.log(`MultiColumnTable AttachTable - cellValue[${cellIndex}]:`, cellValue); const fieldWithGrid = field as any;
if (cellValue && typeof cellValue === 'object' && cellValue.field) { console.log('MultiColumnTable AttachTable - fieldWithGrid:', fieldWithGrid);
console.log(`MultiColumnTable AttachTable - found field: ${cellValue.field}, value in row:`, row[cellValue.field]); if (fieldWithGrid.gridOptions && fieldWithGrid.gridOptions.datas) {
tableData[cellValue.field] = row[cellValue.field]; fieldWithGrid.gridOptions.datas.forEach((dataRow: any, dataRowIndex: number) => {
} Object.values(dataRow).forEach((cellValue: any, cellIndex: number) => {
if (cellValue && typeof cellValue === 'object' && cellValue.field) {
tableData[cellValue.field] = row[cellValue.field];
}
});
}); });
});
}
console.log('MultiColumnTable AttachTable - final tableData:', tableData);
child.setFormData(tableData);
}
} else if (field.formType === 'combinaform') {
const fieldWithChilds = field as any;
if (fieldWithChilds.childs && Array.isArray(fieldWithChilds.childs)) {
fieldWithChilds.childs.forEach((child: any) => {
if (child.formType === 'checkbox' && !Array.isArray(newRow[child.field])) {
newRow[child.field] = []
} }
}) child.setFormData(tableData);
}
} else if (field.formType === 'combinaform') {
const fieldWithChilds = field as any;
if (fieldWithChilds.childs && Array.isArray(fieldWithChilds.childs)) {
fieldWithChilds.childs.forEach((child: any) => {
if (child.formType === 'checkbox' && !Array.isArray(row[child.field])) {
row[child.field] = []
}
})
}
} }
} })
}) })
return newRow
}) })
} }
...@@ -588,7 +587,6 @@ const getExtraFieldComponent = (type: string) => { ...@@ -588,7 +587,6 @@ const getExtraFieldComponent = (type: string) => {
const gridEvents: VxeGridListeners = { const gridEvents: VxeGridListeners = {
toolbarButtonClick(params) { toolbarButtonClick(params) {
if (params.code === "add") { if (params.code === "add") {
const fieldName = (params.button as any).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)
...@@ -649,7 +647,6 @@ defineExpose({ ...@@ -649,7 +647,6 @@ defineExpose({
}) })
onMounted(() => { onMounted(() => {
//curColnum.value = props.fields.length
return () => { return () => {
document.body.classList.remove('fullscreen-table-mode') document.body.classList.remove('fullscreen-table-mode')
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论