curtis
20小時前 0653c25c49805b2850a8a68b2b80722b5b05570e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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
  };
}