liu
2026-09-29 982c97ab82f3beb1b4febcf014562eda34b9fc05
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { ArchiveBorrowApi } from '#/api/archive/borrow';
 
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
 
import { getDocumentPage } from '#/api/archive/document';
import { getSimpleUserList } from '#/api/system/user';
 
/** 表单类型 */
export type FormType = 'create' | 'detail' | 'edit';
 
/** 借阅单状态(对应字典 archive_borrow_status) */
export const BorrowStatus = {
  DRAFT: 0, // 草稿
  APPROVING: 15, // 审批中
  BORROWED: 20, // 借出中
  RETURNED: 30, // 已归还
  REJECTED: 35, // 已驳回
} as const;
 
/** 借阅登记表单配置 */
export function useFormSchema(
  formType: FormType,
  documentId?: number,
): VbenFormSchema[] {
  const readonly = formType === 'detail';
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'documentId',
      label: '借阅档案',
      component: 'ApiSelect',
      componentProps: {
        allowClear: true,
        showSearch: true,
        placeholder: '请选择在库档案',
        api: async () => {
          const { list } = await getDocumentPage({
            pageNo: 1,
            pageSize: 100,
            status: 10,
          });
          return list.map((item) => ({
            id: item.id,
            label: item.no ? `${item.no} ${item.title}` : item.title,
          }));
        },
        labelField: 'label',
        valueField: 'id',
        disabled: readonly || !!documentId,
      },
      rules: 'selectRequired',
      formItemClass: 'col-span-2',
    },
    {
      fieldName: 'borrowerUserId',
      label: '借阅人',
      component: 'ApiSelect',
      componentProps: {
        allowClear: true,
        showSearch: true,
        placeholder: '请选择借阅人',
        api: getSimpleUserList,
        labelField: 'nickname',
        valueField: 'id',
        disabled: readonly,
      },
      rules: 'selectRequired',
    },
    {
      fieldName: 'borrowerName',
      label: '借阅人姓名',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入借阅人姓名',
        disabled: readonly,
      },
      rules: 'required',
    },
    {
      fieldName: 'borrowerDept',
      label: '借阅人部门',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入借阅人部门',
        disabled: readonly,
      },
    },
    {
      fieldName: 'borrowerPhone',
      label: '联系电话',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入联系电话',
        disabled: readonly,
      },
    },
    {
      fieldName: 'borrowDate',
      label: '借阅日期',
      component: 'DatePicker',
      componentProps: {
        allowClear: true,
        format: 'YYYY-MM-DD',
        valueFormat: 'YYYY-MM-DD',
        placeholder: '请选择借阅日期',
        disabled: readonly,
      },
      rules: 'required',
    },
    {
      fieldName: 'returnDeadline',
      label: '归还期限',
      component: 'DatePicker',
      componentProps: {
        allowClear: true,
        format: 'YYYY-MM-DD',
        valueFormat: 'YYYY-MM-DD',
        placeholder: '请选择归还期限',
        disabled: readonly,
      },
      rules: 'required',
    },
    {
      fieldName: 'borrowPurpose',
      label: '借阅目的',
      component: 'Textarea',
      componentProps: {
        rows: 2,
        placeholder: '请输入借阅目的',
        disabled: readonly,
      },
      formItemClass: 'col-span-2',
    },
    {
      fieldName: 'remark',
      label: '备注',
      component: 'Textarea',
      componentProps: {
        rows: 2,
        placeholder: '请输入备注',
        disabled: readonly,
      },
      formItemClass: 'col-span-2',
    },
  ];
}
 
/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'no',
      label: '借阅单号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入借阅单号',
      },
    },
    {
      fieldName: 'documentNo',
      label: '档案编号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入档案编号',
      },
    },
    {
      fieldName: 'documentTitle',
      label: '档案标题',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入档案标题',
      },
    },
    {
      fieldName: 'borrowerName',
      label: '借阅人',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入借阅人姓名',
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.ARCHIVE_BORROW_STATUS, 'number'),
        allowClear: true,
        placeholder: '请选择状态',
      },
    },
    {
      fieldName: 'borrowDate',
      label: '借阅日期',
      component: 'RangePicker',
      componentProps: {
        allowClear: true,
        format: 'YYYY-MM-DD',
        valueFormat: 'YYYY-MM-DD',
        placeholder: ['开始日期', '结束日期'],
      },
    },
    {
      fieldName: 'returnDeadline',
      label: '归还期限',
      component: 'RangePicker',
      componentProps: {
        allowClear: true,
        format: 'YYYY-MM-DD',
        valueFormat: 'YYYY-MM-DD',
        placeholder: ['开始日期', '结束日期'],
      },
    },
  ];
}
 
/** 表格列配置 */
export function useGridColumns(): VxeTableGridOptions<ArchiveBorrowApi.Borrow>['columns'] {
  return [
    {
      field: 'no',
      title: '借阅单号',
      minWidth: 170,
    },
    {
      field: 'documentNo',
      title: '档案编号',
      minWidth: 170,
    },
    {
      field: 'documentTitle',
      title: '档案标题',
      minWidth: 200,
    },
    {
      field: 'borrowerName',
      title: '借阅人',
      minWidth: 100,
    },
    {
      field: 'borrowerDept',
      title: '部门',
      minWidth: 120,
    },
    {
      field: 'borrowDate',
      title: '借阅日期',
      minWidth: 120,
    },
    {
      field: 'returnDeadline',
      title: '归还期限',
      minWidth: 120,
    },
    {
      field: 'overdue',
      title: '逾期',
      minWidth: 110,
      slots: { default: 'overdue' },
    },
    {
      field: 'status',
      title: '状态',
      minWidth: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.ARCHIVE_BORROW_STATUS },
      },
    },
    {
      field: 'approveTime',
      title: '借出时间',
      minWidth: 170,
      formatter: 'formatDateTime',
    },
    {
      field: 'returnTime',
      title: '归还时间',
      minWidth: 170,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 230,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}