huangyinfeng
2024-09-13 12f7304fe9e2bb56ec328e4429a654a0653928a9
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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
<template>
    <a-card size="small">
      <div class="p-1">
        <a-form
          ref="formRef"
          :label-col="{ span: 2 }"
          :wrapper-col="{ span: 24 }"
          :model="modelRef"
        >
          <a-form-item :wrapper-col="{ span: 8 }">
            <div style="display: flex; justify-content: space-evenly">
              <a-button type="primary" shape="round" @click="fnHandleSubmit(modelRef)"
                >发送</a-button
              >
              <a-button shape="round" @click="fnSaveMailDrafts">存草稿</a-button>
              <a-button shape="round" @click="fnPreview">预览</a-button>
              <a-button shape="round">提交审批</a-button>
              <a-button shape="round">取消</a-button></div
            >
          </a-form-item>
          <a-form-item label="发件人" v-bind="validateInfos.sender" :wrapper-col="{ span: 12 }">
            <a-select
              v-model:value="modelRef.sender"
              placeholder="选择发件人"
              show-search
              :field-names="{ label: 'name', value: 'id' }"
              :options="state.data"
              :filter-option="fnFilterOption"
            >
            </a-select>
          </a-form-item>
          <a-form-item label="收件人" v-bind="validateInfos.recipients" :wrapper-col="{ span: 18 }">
            <a-row>
              <a-col class="gutter-row" :span="16">
                <a-select
                  mode="multiple"
                  show-search
                  placeholder="请选择收件人或者输入收件人邮箱"
                  v-model:value="modelRef.recipients"
                  :options="state.data"
                  :field-names="{ label: 'name', value: 'id' }"
                  :maxTagCount="4"
                  :filter-option="fnFilterOption"
                />
              </a-col>
              <a-col
                class="gutter-row"
                :span="2"
                style="display: flex; align-items: center; justify-content: center"
              >
                <plus-circle-outlined
                  style="color: rgb(0 0 0 / 45%)"
                  @click="fnHandleSelect('recipients')"
                />
              </a-col>
              <a-col class="gutter-row" :span="1">
                <a-form-item-rest>
                  <a-button
                    shape="round"
                    type="link"
                    block
                    size="small"
                    @click="ccCheckboxChange($event)"
                  >
                    {{ !isSecretDeliveryPerson ? '抄送' : '取消抄送' }}
                  </a-button>
                </a-form-item-rest>
              </a-col>
              <a-col class="gutter-row" :span="1">
                <a-form-item-rest>
                  <a-button
                    shape="round"
                    type="link"
                    block
                    size="small"
                    @click="bccCheckboxChange($event)"
                  >
                    {{ !isCRecipient ? '密送' : '取消密送' }}
                  </a-button>
                </a-form-item-rest>
              </a-col>
            </a-row>
          </a-form-item>
          <span style="position: relative; top: -18px; left: 9%" v-if="modelRef.recipients.length">
            {{ userParticulars && `${userParticulars.name}<${userParticulars.email}` }}>
            <span v-if="!userParticulars.title" style="margin-right: 10px; margin-left: 5px">
              暂未查询到该客户的当地时间
              <a @click="fnHandleTimeZone(userParticulars, 'add')">补充时区</a>
            </span>
            <span v-else>
              {{ userParticulars.title }}
              <a @click="fnHandleTimeZone(userParticulars, 'update')">时区不对?</a>
            </span>
 
            <a v-if="modelRef.recipients.length > 2">查看全部</a>
          </span>
 
          <a-form-item
            label="抄送人"
            v-bind="validateInfos.ccRecipients"
            v-if="isSecretDeliveryPerson"
            :wrapper-col="{ span: 18 }"
          >
            <a-row>
              <a-col class="gutter-row" :span="16">
                <a-select
                  mode="multiple"
                  show-search
                  placeholder="请选择抄送人或者输入抄送人邮箱"
                  v-model:value="modelRef.ccRecipients"
                  :options="state.data"
                  :field-names="{ label: 'name', value: 'id' }"
                  :maxTagCount="4"
                  :filter-option="fnFilterOption"
                />
              </a-col>
              <a-col
                class="gutter-row"
                :span="2"
                style="display: flex; align-items: center; justify-content: center"
              >
                <plus-circle-outlined
                  style="color: rgb(0 0 0 / 45%)"
                  @click="fnHandleSelect('ccRecipients')"
                />
              </a-col>
            </a-row>
          </a-form-item>
          <a-form-item
            label="密送人"
            v-bind="validateInfos.bccRecipients"
            v-if="isCRecipient"
            :wrapper-col="{ span: 18 }"
          >
            <a-row>
              <a-col class="gutter-row" :span="16">
                <a-select
                  mode="multiple"
                  show-search
                  placeholder="请选择抄送人或者输入抄送人邮箱"
                  v-model:value="modelRef.bccRecipients"
                  :options="state.data"
                  :field-names="{ label: 'name', value: 'id' }"
                  :maxTagCount="4"
                  :filter-option="fnFilterOption"
                />
              </a-col>
              <a-col
                class="gutter-row"
                :span="2"
                style="display: flex; align-items: center; justify-content: center"
              >
                <plus-circle-outlined
                  style="color: rgb(0 0 0 / 45%)"
                  @click="fnHandleSelect('bccRecipients')"
                />
              </a-col>
            </a-row>
          </a-form-item>
          <div
            style="position: relative; top: -20px; left: 9%; color: #909090; font-size: 12px"
            v-if="modelRef.recipients.length"
          >
            {{ `${userLength}/100 收件人、抄送人和密送的联系人总数不可超过100` }}
          </div>
          <a-form-item label="主题" :wrapper-col="{ span: 12 }" :label-col="{ span: 2 }">
            <a-input placeholder="请输入邮件主题" v-model:value="modelRef.subject" />
          </a-form-item>
          <a-form-item
            v-bind="validateInfos.content"
            :wrapper-col="{ span: 24 }"
            :label-col="{ span: 2 }"
          >
            <Tinymce @change="fnChangeContent"></Tinymce>
          </a-form-item>
        </a-form>
      </div>
      <SelectUser
        ref="selectUserRef"
        v-model="openSelectUser"
        :selectIds="selectIds"
        :idName="idName"
        :title="selectUserTitle"
        @updateData="fnSelectUser"
      />
      <a-modal
        v-model:open="openTimeZone"
        :title="`${titleTimeZone}时区`"
        :confirm-loading="confirmLoading"
        @ok="fnHandleTimeZoneOk"
      >
        <a-form
          ref="formTimeZoneRef"
          :label-col="{ span: 6 }"
          :wrapper-col="{ span: 24 }"
          :model="modelRef"
        >
          <a-form-item label="国家地区:" :wrapper-col="{ span: 12 }">
            <a-select
              v-model:value="modelRef.sender"
              placeholder="选择国家地区"
              show-search
              :field-names="{ label: 'name', value: 'id' }"
              :options="state.data"
            >
            </a-select>
          </a-form-item>
          <a-form-item label="时区:" :wrapper-col="{ span: 12 }">
            <a-select
              v-model:value="modelRef.sender"
              placeholder="选择时区"
              show-search
              :field-names="{ label: 'name', value: 'id' }"
              :options="state.data"
            >
            </a-select>
          </a-form-item>
          <a-form-item :label-col="{ span: 6 }">
            <a-row>
              <a-col span="6"> </a-col>
              <a-col span="18">
                <div style="color: #909090"
                  >当地实时时间根据时区信息显示<br />
                  国家地区/时区信息在客户资料-特征信息查看</div
                >
              </a-col>
            </a-row>
          </a-form-item>
        </a-form>
      </a-modal>
    </a-card>
 
</template>
 
<script lang="ts" setup>
name: 'Edit';
  import { useDesign } from '@/hooks/web/useDesign'
 
  import { ref, reactive, computed } from 'vue';
  import { useMessage } from '@/hooks/web/useMessage';
  import { Tinymce } from '@/components/Tinymce';
  import { PlusCircleOutlined } from '@ant-design/icons-vue';
  import SelectUser from '../components/SelectUser/index.vue';
  import { Form } from 'ant-design-vue';
  const modelRef = reactive({
    sender: '',
    recipients: [],
    ccRecipients: [],
    bccRecipients: [],
    fileUNID: [],
    subject: '',
    content: '',
  });
  const rulesRef = reactive({
    sender: [
      {
        required: true,
        message: '发件人不能为空',
      },
    ],
    recipients: [
      {
        required: true,
        message: '收件人不能为空',
      },
    ],
    content: [
      {
        required: true,
        message: '内容不能为空',
      },
    ],
  });
  const useForm = Form.useForm;
  const { validate, validateInfos } = useForm(modelRef, rulesRef);
 
  const formRef = ref();
 
  let isSecretDeliveryPerson = ref(false);
 
  let isCRecipient = ref(false);
  const handleCheckboxChange = (ref, e) => {
    ref.value = !ref.value;
  };
 
  const ccCheckboxChange = (e) => {
    handleCheckboxChange(isSecretDeliveryPerson, e);
  };
  const bccCheckboxChange = (e) => {
    handleCheckboxChange(isCRecipient, e);
  };
 
  const { createMessage } = useMessage();
  import { getUserListApi, sendingMailApi, saveMailDraftsApi } from '@/api/email/userList';
  // 定义状态管理对象
  const state = reactive({
    data: [],
    fetching: false,
    error: null,
  });
 
  // 获取用户列表的函数
  const fnGetUserList = async (params) => {
    try {
      state.fetching = true;
      const res = await getUserListApi(params);
 
      if (res && res.items && Array.isArray(res.items)) {
        state.data = res.items;
      } else {
        console.error('Invalid response format:', res);
      }
    } catch (error) {
      console.error('Failed to fetch user list:', error);
    } finally {
      state.fetching = false;
    }
  };
 
  // 初始化用户数据
  const fetchData = async () => {
    await fnGetUserList({ page: 1, pageSize: 30 });
  };
  console.log(state.data, 'state.data');
  // 调用初始化函数
  fetchData();
 
  const fnFilterOption = (input: string, option: any) => {
    return option.name.toLowerCase().indexOf(input.toLowerCase()) >= 0;
  };
 
  const openSelectUser = ref(false);
  const selectUserTitle = ref('选择收件人');
  const selectIds = ref([]);
  const idName = ref('');
  const fnHandleSelect = (e) => {
    if (e === 'recipients') {
      selectUserTitle.value = '选择收件人';
      idName.value = e;
    }
    if (e === 'ccRecipients') {
      selectUserTitle.value = '选择抄送人';
      idName.value = e;
    }
    if (e === 'bccRecipients') {
      selectUserTitle.value = '选择密送人';
      idName.value = e;
    }
    selectIds.value = modelRef[e];
    openSelectUser.value = true;
  };
 
  function fnChangeContent(e) {
    modelRef.content = e.content;
    modelRef.fileUNID = e.fileUNID;
  }
 
  function fnBuildingCommitData() {
    return {
      sender: modelRef.sender,
      receiver: modelRef.recipients,
      cc: modelRef.ccRecipients,
      bcc: modelRef.bccRecipients,
      subject: modelRef.subject,
      content: modelRef.content,
      fileUNID: '4DFEFEB4-3BB1-448D-9712-DC6C106A7A44;7732',
      docCode: docCode.value,
    };
  }
  const docCode = ref('');
  import { Modal } from 'ant-design-vue';
  function fnHandleSubmit(values: any) {
    validate()
      .then((res) => {
        if (!modelRef.subject) {
          Modal.confirm({
            title: '提示',
            content: '邮件主题为空,确定要发送吗?',
            onOk() {
              pushSendingMail();
            },
            onCancel() {},
          });
        } else {
          pushSendingMail();
        }
      })
      .catch((error) => {
        createMessage.error('表单验证失败');
      });
  }
 
  function pushSendingMail() {
    const data = fnBuildingCommitData();
    sendingMailApi(data).then((res) => {});
  }
  function fnPreview() {}
 
  function fnSaveMailDrafts() {
    const data = fnBuildingCommitData();
    saveMailDraftsApi(data).then((res) => {
      docCode.value = res.data.docCode;
      createMessage.success(res.msg);
    });
  }
 
  const fnSelectUser = (e) => {
    modelRef[e.idName] = e.selectedRowKeys;
  };
 
  const userLength = computed(() => {
    return (
      modelRef.recipients.length + modelRef.ccRecipients.length + modelRef.bccRecipients.length
    );
  });
 
  interface Recipient {
    value: string;
    email: string;
    title: string;
  }
 
  const userParticulars = computed<Recipient | null>(() => {
    const recipientId = modelRef.recipients?.[0];
    if (!recipientId) {
      console.error('Recipient ID is not defined.');
      return { value: '', email: '', title: '' };
    }
    // 使用 find 方法查找匹配项
    const foundItem = state.data.find((item) => item.id === recipientId);
 
    // 返回找到的项,如果未找到则返回 null
    return foundItem || { value: '', email: '', title: '' };
  });
  const fnHandleTimeZone = (e, type) => {
    console.log('fnHandleTimeZone');
    if (type == 'add') {
      titleTimeZone.value = '添加';
      typeTimeZone.value = 1;
    } else {
      titleTimeZone.value = '修改';
      typeTimeZone.value = 2;
    }
    openTimeZone.value = true;
  };
 
  const openTimeZone = ref<boolean>(false);
  const confirmLoading = ref<boolean>(false);
  const titleTimeZone = ref<string>('添加');
  const typeTimeZone = ref<number>(1);
 
  const fnHandleTimeZoneOk = () => {
    confirmLoading.value = true;
    setTimeout(() => {
      openTimeZone.value = false;
      confirmLoading.value = false;
    }, 2000);
  };
  const { prefixCls } = useDesign('email');
</script>
<style lang="less" scoped>
  @prefix-cls: ~'@{namespace}-email';
  .@{prefix-cls} {
    .splitpanes__pane {
      display: flex;
      align-items: stretch;
      justify-content: center;
      // background-color: var(--component-background-color);
    }
  }
</style>