liu
3 天以前 fe2d6627b8f1002af7a31b08f6f43bec034d04ee
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
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
 
import { getAssetItemSimpleList } from '#/api/asset/item';
 
import { AssetCategoryOptions } from '../item/data';
 
/** 归还状态选项 */
export const ReturnStatusOptions = [
  { label: '未归还', value: 1 },
  { label: '部分归还', value: 2 },
  { label: '已归还', value: 3 },
];
 
export function getCategoryName(category?: number) {
  return (
    AssetCategoryOptions.find((item) => item.value === category)?.label ?? '-'
  );
}
 
/** 新增/修改表单 */
export function useFormSchema(formType: 'create' | 'edit' | 'detail') {
  const disabled = formType === 'detail';
  const editDisabled = formType !== 'create';
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: { triggerFields: [''], show: () => false },
    },
    {
      fieldName: 'assetId',
      label: '领用资产',
      component: 'ApiSelect',
      componentProps: {
        api: getAssetItemSimpleList,
        labelField: 'name',
        valueField: 'id',
        placeholder: '请选择领用资产',
        allowClear: true,
        showSearch: true,
        disabled: disabled || editDisabled,
      },
      rules: 'required',
    },
    {
      fieldName: 'recipientName',
      label: '领用人',
      component: 'Input',
      componentProps: {
        placeholder: '请输入领用人姓名',
        maxlength: 64,
        disabled,
      },
      rules: 'required',
    },
    {
      fieldName: 'requisitionTime',
      label: '领用时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        placeholder: '请选择领用时间',
        style: { width: '100%' },
        disabled: disabled || editDisabled,
      },
      rules: 'required',
    },
    {
      fieldName: 'quantity',
      label: '领用数量',
      component: 'InputNumber',
      componentProps: {
        min: 1,
        precision: 0,
        placeholder: '请输入领用数量',
        class: '!w-full',
        disabled: disabled || editDisabled,
      },
      rules: 'required',
    },
    {
      fieldName: 'expectedReturnDate',
      label: '预计归还日期',
      component: 'DatePicker',
      componentProps: {
        valueFormat: 'YYYY-MM-DD',
        placeholder: '请选择预计归还日期',
        style: { width: '100%' },
        disabled,
      },
    },
    {
      fieldName: 'purpose',
      label: '用途',
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入领用用途',
        autoSize: { minRows: 2, maxRows: 3 },
        disabled,
      },
      formItemClass: 'col-span-2',
    },
    {
      fieldName: 'remark',
      label: '备注',
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入备注',
        autoSize: { minRows: 2, maxRows: 3 },
        disabled,
      },
      formItemClass: 'col-span-2',
    },
  ] as VbenFormSchema[];
}
 
/** 列表搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'no',
      label: '领用单号',
      component: 'Input',
      componentProps: { placeholder: '请输入领用单号', allowClear: true },
    },
    {
      fieldName: 'assetName',
      label: '资产名称',
      component: 'Input',
      componentProps: { placeholder: '请输入资产名称', allowClear: true },
    },
    {
      fieldName: 'recipientName',
      label: '领用人',
      component: 'Input',
      componentProps: { placeholder: '请输入领用人', allowClear: true },
    },
    {
      fieldName: 'category',
      label: '资产分类',
      component: 'Select',
      componentProps: {
        options: AssetCategoryOptions,
        placeholder: '请选择资产分类',
        allowClear: true,
      },
    },
    {
      fieldName: 'returnStatus',
      label: '归还状态',
      component: 'Select',
      componentProps: {
        options: ReturnStatusOptions,
        placeholder: '请选择归还状态',
        allowClear: true,
      },
    },
  ];
}
 
/** 列表列 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    { field: 'no', title: '领用单号', width: 175, fixed: 'left' },
    { field: 'assetNo', title: '资产编号', width: 175 },
    { field: 'assetName', title: '资产名称', minWidth: 140 },
    {
      field: 'category',
      title: '资产分类',
      width: 105,
      slots: { default: 'category' },
    },
    { field: 'custodianName', title: '保管人', width: 100 },
    { field: 'recipientName', title: '领用人', width: 100 },
    {
      field: 'requisitionTime',
      title: '领用时间',
      width: 165,
      formatter: 'formatDateTime',
    },
    { field: 'quantity', title: '领用数量', width: 95 },
    { field: 'returnedQuantity', title: '已归还', width: 90 },
    { field: 'remainingQuantity', title: '未归还', width: 90 },
    {
      field: 'expectedReturnDate',
      title: '预计归还',
      width: 115,
      formatter: 'formatDate',
    },
    { field: 'purpose', title: '用途', minWidth: 150, showOverflow: 'tooltip' },
    {
      field: 'returnStatus',
      title: '归还状态',
      width: 100,
      slots: { default: 'returnStatus' },
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}