Closed as not planned
Description
列配置:
{
title: '品类范围',
field: props.editable ? 'sortRange' : 'sortRangeName',
width: 160,
editRender: { enabled: props.editable },
slots: props.editable
? {
edit: ({ row, rowIndex }) => {
return (
<FormField
commonComponentProps={{}}
component="Cascader"
componentProps={{
ref: 'sortRangeRef',
placeholder: '请选择',
options: sortList.value,
filterable: true,
showAllLevels: false,
popperClass: 'vxe-table--ignore-clear',
props: {
value: 'categoryId',
label: 'categoryName',
children: 'children',
checkStrictly: true,
},
onChange(value: any) {
const findCategoryName = (
id: string,
list: any[],
): string => {
for (const item of list) {
if (item.categoryId === id) {
return item.categoryName;
}
if (item.children) {
const found = findCategoryName(id, item.children);
if (found) return found;
}
}
return '';
};
// 获取数组的最后一个值作为实际选中值
const selectedId = Array.isArray(value)
? value[value.length - 1]
: value;
row.sortRangeName = findCategoryName(
selectedId,
sortList.value,
);
},
}}
fieldName={`${props.prefixName}[${rowIndex}].sortRange`}
hideLabel={true}
inline={true}
/>
);
},
default: ({ row }) => {
return row.sortRangeName;
},
}
: undefined,
},
表格配置:
editRules: {
xxxx: [{ required: true, message: '必须填写' }]
}