import { ref, computed, onMounted } from 'vue';
|
|
interface DocListItem {
|
formId: string;
|
docName: string;
|
}
|
|
export function useDocListLogic() {
|
// --- State Mapped from Delphi UI Components ---
|
|
const searchText = ref<string>('');
|
const isCustomDoc = ref<boolean>(false);
|
const selectedIndex = ref<number>(-1);
|
const sortColumn = ref<number>(0);
|
const sortOrder = ref<'asc' | 'desc'>('asc');
|
|
// FormIDList: TStringList equivalent
|
// Sample data format from Pascal: 'FormID#@#DocName'
|
const formIDList = ref<string[]>([]);
|
|
// --- Computed ---
|
|
const filteredItems = computed(() => {
|
const items: DocListItem[] = formIDList.value
|
.filter(line => !searchText.value || line.toUpperCase().includes(searchText.value.toUpperCase()))
|
.map(line => {
|
const parts = line.split('#@#');
|
return {
|
formId: parts[0] || '',
|
docName: parts[1] || ''
|
};
|
});
|
|
// Sort items
|
items.sort((a, b) => {
|
let valA = sortColumn.value === 0 ? a.formId : a.docName;
|
let valB = sortColumn.value === 0 ? b.formId : b.docName;
|
|
const comparison = valA.localeCompare(valB);
|
return sortOrder.value === 'asc' ? comparison : -comparison;
|
});
|
|
return items;
|
});
|
|
// --- Methods ---
|
|
const FormCreate = () => {
|
// PostMessage(Handle,WM_ACTIVATE,WA_CLICKACTIVE,0);
|
console.log('DocListForm created');
|
|
// Mock initialization for demo
|
formIDList.value = [
|
'F001#@#測試文件一',
|
'F002#@#測試文件二',
|
'A003#@#合約書',
|
'B004#@#申請書'
|
];
|
};
|
|
const OkBtClick = () => {
|
if (selectedIndex.value === -1 && !isCustomDoc.value) {
|
// Showmessage(_Msg('請選擇一個種類'));
|
alert('請選擇一個種類');
|
return;
|
}
|
console.log('Form confirmed:', selectedIndex.value !== -1 ? filteredItems.value[selectedIndex.value] : 'Custom');
|
closeForm('ok');
|
};
|
|
const CancelBtClick = () => {
|
closeForm('cancel');
|
};
|
|
const Edit1Change = () => {
|
// Logic handled by computed filteredItems
|
selectedIndex.value = -1;
|
};
|
|
const DocLVColumnClick = (index: number) => {
|
if (sortColumn.value === index) {
|
sortOrder.value = sortOrder.value === 'asc' ? 'desc' : 'asc';
|
} else {
|
sortColumn.value = index;
|
sortOrder.value = 'asc';
|
}
|
};
|
|
const DocLVDblClick = (index: number) => {
|
selectedIndex.value = index;
|
OkBtClick();
|
};
|
|
const selectItem = (index: number) => {
|
selectedIndex.value = index;
|
};
|
|
const closeForm = (result: string) => {
|
console.log(`DocListForm closing with result: ${result}`);
|
};
|
|
onMounted(() => {
|
FormCreate();
|
});
|
|
return {
|
// State
|
searchText,
|
isCustomDoc,
|
selectedIndex,
|
filteredItems,
|
sortColumn,
|
sortOrder,
|
|
// Actions
|
OkBtClick,
|
CancelBtClick,
|
Edit1Change,
|
DocLVColumnClick,
|
DocLVDblClick,
|
selectItem
|
};
|
}
|