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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
| import type { VbenFormApi, VbenFormSchema } from '#/adapter/form';
| import type { VxeTableGridOptions } from '#/adapter/vxe-table';
| import type { MesWmSalesNoticeApi } from '#/api/mes/wm/salesnotice';
| import type { MesWmSalesNoticeLineApi } from '#/api/mes/wm/salesnotice/line';
|
| import { h, markRaw } from 'vue';
|
| import {
| DICT_TYPE,
| MesAutoCodeRuleCode,
| } from '@vben/constants';
|
| import { Button } from 'ant-design-vue';
|
| import { z } from '#/adapter/form';
| import { generateAutoCode } from '#/api/mes/md/autocode/record';
| import CrmCustomerSelect from '#/components/crm-customer-select.vue';
| import { ErpSaleOrderSelect } from '#/views/erp/sale/order/components';
| import { MdItemSelect } from '#/views/mes/md/item/components';
|
| /** 表单类型 */
| export type FormType = 'create' | 'detail' | 'update';
|
| /** 表单头部是否只读(详情态) */
| function isHeaderReadonly(formType: FormType): boolean {
| return formType === 'detail';
| }
|
| /** 新增/修改的表单 */
| export function useFormSchema(
| formType: FormType,
| formApi?: VbenFormApi,
| ): VbenFormSchema[] {
| return [
| {
| fieldName: 'id',
| component: 'Input',
| dependencies: {
| triggerFields: [''],
| show: () => false,
| },
| },
| {
| fieldName: 'status',
| component: 'Input',
| dependencies: {
| triggerFields: [''],
| show: () => false,
| },
| },
| {
| fieldName: 'code',
| label: '通知单编号',
| component: 'Input',
| componentProps: {
| placeholder: '请输入通知单编号',
| },
| rules: 'required',
| suffix: isHeaderReadonly(formType)
| ? undefined
| : () =>
| h(
| Button,
| {
| type: 'default',
| onClick: async () => {
| const code = await generateAutoCode(
| MesAutoCodeRuleCode.WM_SALES_NOTICE_CODE,
| );
| await formApi?.setFieldValue('code', code);
| },
| },
| { default: () => '生成' },
| ),
| },
| {
| fieldName: 'name',
| label: '通知单名称',
| component: 'Input',
| componentProps: {
| placeholder: '请输入通知单名称',
| },
| rules: 'required',
| },
| {
| fieldName: 'saleOrderId',
| label: '销售订单',
| component: markRaw(ErpSaleOrderSelect),
| componentProps: {
| placeholder: '请选择销售订单',
| // 选择销售订单后,自动回填客户信息
| onChange: (item: any) => {
| if (item?.customerId && formApi) {
| formApi.setFieldValue('clientId', item.customerId);
| }
| },
| },
| },
| {
| fieldName: 'clientId',
| label: '客户',
| component: markRaw(CrmCustomerSelect),
| componentProps: {
| placeholder: '请选择客户',
| disabled: true,
| },
| rules: 'selectRequired',
| },
| {
| fieldName: 'salesDate',
| label: '发货日期',
| component: 'DatePicker',
| componentProps: {
| class: '!w-full',
| format: 'YYYY-MM-DD',
| placeholder: '请选择发货日期',
| valueFormat: 'x',
| },
| rules: 'required',
| },
| {
| fieldName: 'recipientName',
| label: '收货人',
| component: 'Input',
| componentProps: {
| placeholder: '请输入收货人',
| },
| },
| {
| fieldName: 'recipientTelephone',
| label: '联系方式',
| component: 'Input',
| componentProps: {
| placeholder: '请输入联系方式',
| },
| },
| {
| fieldName: 'recipientAddress',
| label: '收货地址',
| component: 'Input',
| componentProps: {
| placeholder: '请输入收货地址',
| },
| },
| {
| fieldName: 'remark',
| label: '备注',
| component: 'Textarea',
| formItemClass: 'col-span-3',
| componentProps: {
| placeholder: '请输入备注',
| rows: 3,
| },
| },
| ];
| }
|
| /** 列表的搜索表单 */
| export function useGridFormSchema(): VbenFormSchema[] {
| return [
| {
| fieldName: 'code',
| label: '通知单编号',
| component: 'Input',
| componentProps: {
| allowClear: true,
| placeholder: '请输入通知单编号',
| },
| },
| {
| fieldName: 'name',
| label: '通知单名称',
| component: 'Input',
| componentProps: {
| allowClear: true,
| placeholder: '请输入通知单名称',
| },
| },
| {
| fieldName: 'saleOrderCode',
| label: '销售订单编号',
| component: 'Input',
| componentProps: {
| allowClear: true,
| placeholder: '请输入销售订单编号',
| },
| },
| {
| fieldName: 'clientId',
| label: '客户',
| component: markRaw(CrmCustomerSelect),
| componentProps: {
| placeholder: '请选择客户',
| },
| },
| ];
| }
|
| /** 列表的字段 */
| export function useGridColumns(): VxeTableGridOptions<MesWmSalesNoticeApi.SalesNotice>['columns'] {
| return [
| {
| field: 'code',
| title: '通知单编号',
| minWidth: 160,
| slots: { default: 'code' },
| },
| {
| field: 'name',
| title: '通知单名称',
| minWidth: 150,
| },
| {
| field: 'saleOrderCode',
| title: '销售订单编号',
| minWidth: 140,
| },
| {
| field: 'clientName',
| title: '客户名称',
| minWidth: 120,
| },
| {
| field: 'salesDate',
| title: '发货日期',
| width: 180,
| formatter: 'formatDate',
| },
| {
| field: 'recipientName',
| title: '收货人',
| minWidth: 100,
| },
| {
| field: 'recipientTelephone',
| title: '联系方式',
| minWidth: 120,
| },
| {
| field: 'recipientAddress',
| title: '收货地址',
| minWidth: 200,
| },
| {
| field: 'status',
| title: '单据状态',
| minWidth: 100,
| cellRender: {
| name: 'CellDict',
| props: { type: DICT_TYPE.MES_WM_SALES_NOTICE_STATUS },
| },
| },
| {
| field: 'outStatus',
| title: '出库状态',
| minWidth: 100,
| slots: { default: 'outStatus' },
| },
| {
| title: '操作',
| width: 200,
| fixed: 'right',
| slots: { default: 'actions' },
| },
| ];
| }
|
| /** 通知单行子表的字段 */
| export function useLineGridColumns(
| editable: boolean,
| ): VxeTableGridOptions<MesWmSalesNoticeLineApi.SalesNoticeLine>['columns'] {
| return [
| {
| field: 'itemCode',
| title: '物料编码',
| minWidth: 120,
| },
| {
| field: 'itemName',
| title: '物料名称',
| minWidth: 140,
| },
| {
| field: 'specification',
| title: '规格型号',
| minWidth: 120,
| },
| {
| field: 'unitMeasureName',
| title: '单位',
| width: 80,
| },
| {
| field: 'quantity',
| title: '发货数量',
| width: 100,
| },
| {
| field: 'outCount',
| title: '已出库数量',
| width: 100,
| formatter: ({ cellValue }: { cellValue: number }) => (cellValue || 0).toFixed(2),
| },
| {
| field: 'outProgress',
| title: '出库进度',
| width: 120,
| cellRender: {
| name: 'CellText',
| props: {
| formatter: ({ row }: { row: MesWmSalesNoticeLineApi.SalesNoticeLine }) => {
| const quantity = row.quantity || 0;
| const outCount = row.outCount || 0;
| const percent = quantity > 0 ? Math.round((outCount / quantity) * 100) : 0;
| return `${outCount.toFixed(2)} / ${quantity.toFixed(2)} (${percent}%)`;
| },
| },
| },
| },
| {
| field: 'batchCode',
| title: '批次号',
| minWidth: 120,
| },
| {
| field: 'oqcCheckFlag',
| title: '是否检验',
| width: 90,
| cellRender: {
| name: 'CellDict',
| props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
| },
| },
| {
| field: 'remark',
| title: '备注',
| minWidth: 120,
| },
| ...(editable
| ? [
| {
| title: '操作',
| width: 120,
| fixed: 'right',
| slots: { default: 'actions' },
| } as const,
| ]
| : []),
| ];
| }
|
| /** 通知单行新增/修改的表单 */
| export function useLineFormSchema(): VbenFormSchema[] {
| return [
| {
| fieldName: 'itemId',
| label: '物料',
| component: markRaw(MdItemSelect),
| componentProps: {
| placeholder: '请选择物料',
| },
| rules: 'selectRequired',
| },
| {
| fieldName: 'quantity',
| label: '发货数量',
| component: 'InputNumber',
| componentProps: {
| class: '!w-full',
| min: 0.01,
| placeholder: '请输入发货数量',
| precision: 2,
| },
| rules: 'required',
| },
| {
| fieldName: 'batchCode',
| label: '批次号',
| component: 'Input',
| componentProps: {
| placeholder: '请输入批次号',
| },
| },
| {
| fieldName: 'oqcCheckFlag',
| label: '是否检验',
| component: 'Switch',
| rules: z.boolean().default(true),
| },
| {
| fieldName: 'remark',
| label: '备注',
| component: 'Textarea',
| formItemClass: 'col-span-3',
| componentProps: {
| placeholder: '请输入备注',
| rows: 3,
| },
| },
| ];
| }
|
|