DrawerCreate.vue
6.46 KB
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
<template>
<BasicDrawer
v-cloakv-bind="$attrs"
@register="register"
title="新增邮件发送"
width="35%"
showFooter
@ok="handleSubmit"
ref="formRef"
okText="保存"
:destroyOnClose="true"
:isDetail="true"
:showDetailBack="false"
:mask="false"
class="z-20"
>
<div>
<BasicForm @register="registerForm" />
</div>
</BasicDrawer>
</template>
<script lang="ts" setup>
import { BasicDrawer, useDrawerInner } from '@/components/Drawer';
import { BasicForm, FormSchema, useForm } from '@/components/Form';
import { defineComponent, ref, computed, unref, toRaw } from 'vue';
import { useOrderInfo } from '/@/hooks/component/order';
import { useOrderStoreWithOut } from '/@/store/modules/order';
const orderStore = useOrderStoreWithOut();
const { customerCode: customerCodeOptions } = useOrderInfo(orderStore);
const emit = defineEmits(['success2']);
const configInfos: ConfigInfo[] = [
{
fieldName: '确认样品确认状态',
fieldValue: 'configSample',
event: 'CONFIRM_SAMPLE_EVENT',
emails: [],
},
{
fieldName: '其他要求样品发送日期',
fieldValue: 'otherSample',
event: 'OTHER_SAMPLE_EVENT',
emails: [],
},
{
fieldName: '大货样确认态',
fieldValue: 'bigSample',
event: 'BIG_SAMPLE_EVENT',
emails: [],
},
{
fieldName: 'AIDE/SGS测试状态',
fieldValue: 'aitexSgsTest',
event: 'AITEX_SGS_TEST_EVENT',
emails: [],
},
{
fieldName: '要求包材到货日期',
fieldValue: 'barcodeArrival',
event: 'BARCODE_ARRIVAL_EVENT',
emails: [],
},
{
fieldName: '最晚订舱日期',
fieldValue: 'latestDc',
event: 'LATEST_DC_EVENT',
emails: [],
},
// {
// fieldName: '尾期验货日期',
// fieldValue: 'endCheckDate',
// event: 'END_CHECK_DATE_EVENT',
// emails: [],
// },
// {
// fieldName: '中期验货报告',
// fieldValue: 'midCheckReport',
// event: 'MID_CHECK_REPORT_EVENT',
// emails: [],
// },
// {
// fieldName: '尾期验货报告',
// fieldValue: 'endCheckReport',
// event: 'END_CHECK_REPORT_EVENT',
// emails: [],
// },
];
const schemas: FormSchema[] = [
{
field: 'typeValue',
component: 'Select',
label: '客户编码',
componentProps: {
options: customerCodeOptions,
},
colProps: {
span: 23,
},
defaultValue: '',
rules: [{ required: true }],
},
{
field: 'configSample',
component: 'InputTextArea',
labelWidth: 250,
colProps: {
span: 23,
},
label: '确认样品确认状态(填写邮箱)',
rules: [{ required: true }],
},
{
field: 'otherSample',
component: 'InputTextArea',
labelWidth: 250,
colProps: {
span: 23,
},
label: '其他需求样品发送时间(填写邮箱)',
rules: [{ required: true }],
},
{
field: 'bigSample',
component: 'InputTextArea',
labelWidth: 250,
colProps: {
span: 23,
},
label: '大货样确认意见(填写邮箱)',
rules: [{ required: true }],
},
{
field: 'aitexSgsTest',
component: 'InputTextArea',
labelWidth: 250,
colProps: {
span: 23,
},
label: 'AITEX/SGS测试状态(填写邮箱)',
rules: [{ required: true }],
},
{
field: 'barcodeArrival',
component: 'InputTextArea',
labelWidth: 250,
colProps: {
span: 23,
},
label: '要求包装到货日期(填写邮箱)',
rules: [{ required: true }],
},
{
field: 'latestDc',
component: 'InputTextArea',
labelWidth: 250,
colProps: {
span: 23,
},
label: '最晚订舱时间(填写邮箱)',
rules: [{ required: true }],
},
{
field: 'endCheckDate',
component: 'InputTextArea',
labelWidth: 250,
colProps: {
span: 23,
},
label: '尾期验货日期(填写邮箱)',
rules: [{ required: true }],
},
{
field: 'midCheckReport',
component: 'InputTextArea',
labelWidth: 250,
colProps: {
span: 23,
},
label: '中期验货报告(填写邮箱)',
rules: [{ required: true }],
},
{
field: 'endCheckReport',
component: 'InputTextArea',
labelWidth: 250,
colProps: {
span: 23,
},
label: '尾期验货报告(填写邮箱)',
rules: [{ required: true }],
},
];
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({
labelWidth: 120,
schemas,
layout: 'vertical',
showActionButtonGroup: false,
actionColOptions: {
span: 24,
},
});
const [register, { setDrawerProps, closeDrawer }] = useDrawerInner((data) => {
// 方式1
resetFields();
setDrawerProps({ confirmLoading: false });
});
interface ConfigInfo {
fieldName: string; // 字段名称,必须
fieldValue: string; // 字段值,必须
event?: string; // 订单事件,非必须,可选字段
emails: string[]; // 邮箱列表,必须
}
// 定义包含configInfos的更大对象
interface ProductionDepartment {
type: string; // 类型,必须
typeValue: string; // 某个type中具体的值,必须
configInfos: ConfigInfo[]; // 配置信息数组,必须
}
async function handleSubmit() {
try {
const values = await validate();
//引入所有事件合集,给各个事件命名,用于匹配
const configObject = configInfos.reduce((obj, item) => {
obj[item.fieldValue] = item;
return obj;
}, {} as { [key: string]: ConfigInfo });
const newValues = ref<ProductionDepartment>({
type: '客户编码',
typeValue: '',
configInfos: [],
});
newValues.value.typeValue = values.typeValue;
//添加邮件事件
for (const value1 in values) {
if (value1 != 'typeValue') {
const arr: string[] = values[value1].split(/[,|,]/);
configObject[value1].emails = arr;
newValues.value.configInfos.push(configObject[value1]);
}
}
emit('success2', {
values: { ...newValues.value },
});
setDrawerProps({ confirmLoading: true });
closeDrawer();
} finally {
setDrawerProps({ confirmLoading: false });
}
}
</script>