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
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
 
import { VehicleApplicationApi } from '#/api/vehicle/application';
 
/** 用车申请状态选项 */
export const StatusOptions = [
  { label: '草稿', value: VehicleApplicationApi.Status.DRAFT },
  { label: '审批中', value: VehicleApplicationApi.Status.APPROVING },
  { label: '已通过', value: VehicleApplicationApi.Status.APPROVED },
  { label: '已驳回', value: VehicleApplicationApi.Status.REJECTED },
];
 
export function getStatusName(status?: number) {
  return StatusOptions.find((item) => item.value === status)?.label ?? '-';
}
 
/** 新增/修改表单 */
export function useFormSchema(formType: 'create' | 'edit' | 'detail') {
  const disabled = formType === 'detail';
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: { triggerFields: [''], show: () => false },
    },
    {
      fieldName: 'useStartTime',
      label: '用车开始时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        placeholder: '请选择用车开始时间',
        style: { width: '100%' },
        disabled,
      },
      rules: 'required',
    },
    {
      fieldName: 'useEndTime',
      label: '用车结束时间',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        placeholder: '请选择用车结束时间',
        style: { width: '100%' },
        disabled,
      },
      rules: 'required',
    },
    {
      fieldName: 'departure',
      label: '出发地',
      component: 'Input',
      componentProps: {
        placeholder: '请输入出发地',
        maxlength: 128,
        disabled,
      },
      rules: 'required',
    },
    {
      fieldName: 'destination',
      label: '目的地',
      component: 'Input',
      componentProps: {
        placeholder: '请输入目的地',
        maxlength: 128,
        disabled,
      },
      rules: 'required',
    },
    {
      fieldName: 'passengers',
      label: '随行人数',
      component: 'InputNumber',
      componentProps: {
        min: 1,
        precision: 0,
        placeholder: '请输入随行人数',
        class: '!w-full',
        disabled,
      },
    },
    {
      fieldName: 'vehicleNo',
      label: '车牌号',
      component: 'Input',
      componentProps: {
        placeholder: '选填,如 苏F12345',
        maxlength: 32,
        disabled,
      },
    },
    {
      fieldName: 'reason',
      label: '用车事由',
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入用车事由',
        autoSize: { minRows: 2, maxRows: 4 },
        disabled,
      },
      formItemClass: 'col-span-2',
      rules: 'required',
    },
    {
      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: 'applicantName',
      label: '申请人',
      component: 'Input',
      componentProps: { placeholder: '请输入申请人', allowClear: true },
    },
    {
      fieldName: 'destination',
      label: '目的地',
      component: 'Input',
      componentProps: { placeholder: '请输入目的地', allowClear: true },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'Select',
      componentProps: {
        options: StatusOptions,
        placeholder: '请选择状态',
        allowClear: true,
      },
    },
  ];
}
 
/** 列表列 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    { field: 'no', title: '申请单号', width: 175, fixed: 'left' },
    { field: 'applicantName', title: '申请人', width: 110 },
    {
      field: 'useStartTime',
      title: '用车开始',
      width: 165,
      formatter: 'formatDateTime',
    },
    {
      field: 'useEndTime',
      title: '用车结束',
      width: 165,
      formatter: 'formatDateTime',
    },
    { field: 'departure', title: '出发地', minWidth: 140 },
    { field: 'destination', title: '目的地', minWidth: 140 },
    { field: 'passengers', title: '随行人数', width: 95 },
    { field: 'reason', title: '用车事由', minWidth: 180, showOverflow: 'tooltip' },
    { field: 'vehicleNo', title: '车牌号', width: 110 },
    {
      field: 'status',
      title: '状态',
      width: 100,
      slots: { default: 'status' },
    },
    {
      title: '操作',
      width: 220,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}