|
|
|
@ -53,7 +53,7 @@ const generateQuoteContent = (mailData) => `<br><br>
|
|
|
|
|
<b>
|
|
|
|
|
<strong >Subject: </strong>
|
|
|
|
|
</b>
|
|
|
|
|
<span >${mailData.info.subject || ''}</span>
|
|
|
|
|
<span >${mailData.info?.MAI_Subject || ''}</span>
|
|
|
|
|
</p>
|
|
|
|
|
<p>
|
|
|
|
|
${mailData.content}
|
|
|
|
@ -65,52 +65,89 @@ const generateMailContent = (mailData) => `
|
|
|
|
|
${mailData.content}
|
|
|
|
|
</p>`
|
|
|
|
|
|
|
|
|
|
const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, toEmail, conversationid, quoteid, initial = {}, mailData: _mailData, action = 'reply', ...props }) => {
|
|
|
|
|
/**
|
|
|
|
|
* @property {string} fromEmail - 发件人邮箱
|
|
|
|
|
* @property {string} fromUser - 发件人用户
|
|
|
|
|
* @property {string} fromOrder - 发件人订单
|
|
|
|
|
* @property {string} toEmail - 收件人邮箱
|
|
|
|
|
* @property {string} conversationid - 会话ID
|
|
|
|
|
* @property {string} quoteid - 引用邮件ID
|
|
|
|
|
*/
|
|
|
|
|
const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, fromOrder, toEmail, conversationid, quoteid, initial = {}, mailData: _mailData, action = 'reply', ...props }) => {
|
|
|
|
|
const { notification, message } = App.useApp();
|
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
|
|
|
|
|
|
const [mobile] = useStyleStore((state) => [state.mobile]);
|
|
|
|
|
const [userId, username, emailList] = useAuthStore((state) => [state.loginUser.userId, state.loginUser.username, state.loginUser.emailList]);
|
|
|
|
|
const emailListOption = emailList?.map(ele => ({ ...ele, label: ele.email, key: ele.email, value: ele.email })) || [];
|
|
|
|
|
const emailListMapped = emailListOption?.reduce((r, v) => ({ ...r, [v.opi_sn]: v }), {});
|
|
|
|
|
// const emailListMapped = emailListOption?.reduce((r, v) => ({ ...r, [v.opi_sn]: v }), {});
|
|
|
|
|
const emailListAddrMapped = emailListOption?.reduce((r, v) => ({ ...r, [v.email]: v }), {});
|
|
|
|
|
const emailListMatMapped = emailListOption?.reduce((r, v) => ({ ...r, [v.mat_sn]: v }), {});
|
|
|
|
|
// console.log('emailListMapped', emailListOption, emailListAddrMapped);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const mai_sn = quoteid;
|
|
|
|
|
const { loading, mailData } = useEmailDetail(mai_sn, _mailData)
|
|
|
|
|
const { loading: getLoading, mailData } = useEmailDetail(mai_sn, _mailData)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [newFromEmail, setNewFromEmail] = useState(fromEmail);
|
|
|
|
|
const [newToEmail, setNewToEmail] = useState(toEmail);
|
|
|
|
|
const [emailOPI, setEmailOPI] = useState(fromUser);
|
|
|
|
|
const [stickToProps, setStickToProps] = useState({});
|
|
|
|
|
|
|
|
|
|
const [newFromEmail, setNewFromEmail] = useState('');
|
|
|
|
|
const [newToEmail, setNewToEmail] = useState('');
|
|
|
|
|
const [emailOPI, setEmailOPI] = useState('');
|
|
|
|
|
const [emailOrder, setEmailOrder] = useState('');
|
|
|
|
|
const [emailMat, setEmailMat] = useState('');
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const emailUser = mailData.info?.MAI_OPI_SN || fromUser // quote.order_opi
|
|
|
|
|
const emailUserMat = mailData.info?.MAI_MAT_SN
|
|
|
|
|
|
|
|
|
|
// const _default =
|
|
|
|
|
// emailListOption?.find((ele) => ele.opi_sn === emailUser && ele.default === true) ||
|
|
|
|
|
// emailListOption?.find((ele) => ele.opi_sn === emailUser && ele.backup === true) ||
|
|
|
|
|
// emailListOption?.find((ele) => ele.opi_sn === emailUser) ||
|
|
|
|
|
// emailListOption?.find((ele) => ele.default === true) ||
|
|
|
|
|
// emailListOption?.find((ele) => ele.backup === true)
|
|
|
|
|
// 存储: 会话ID,
|
|
|
|
|
// 这个窗口没有模态, 即使不是focus, 还是需要保持会话ID
|
|
|
|
|
// 否则, 会话列表切换之后, 会话ID更新, 导致消息关联错误
|
|
|
|
|
const [stickToCid, setStickToCid] = useState(conversationid);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
// console.log('emailEditorPopup effect', open, '\nto', toEmail)
|
|
|
|
|
setStickToProps({ fromEmail, fromUser, fromOrder, toEmail, conversationid, quoteid, action });
|
|
|
|
|
|
|
|
|
|
setNewFromEmail(fromEmail);
|
|
|
|
|
setEmailOPI(emailUser);
|
|
|
|
|
setNewToEmail(toEmail);
|
|
|
|
|
setStickToCid(conversationid)
|
|
|
|
|
setEmailOrder(fromOrder)
|
|
|
|
|
setEmailOPI(fromUser)
|
|
|
|
|
setNewFromEmail(fromEmail)
|
|
|
|
|
setNewToEmail(toEmail)
|
|
|
|
|
|
|
|
|
|
const _findMat = emailListAddrMapped?.[fromEmail]?.mat_sn
|
|
|
|
|
setEmailMat(emailUserMat || _findMat)
|
|
|
|
|
setEmailMat(_findMat)
|
|
|
|
|
|
|
|
|
|
// 转发/回复时, 从发出的邮件操作, 获取原来的发件人邮箱
|
|
|
|
|
const _findMatOld = emailListMatMapped?.[emailUserMat]
|
|
|
|
|
if (isEmpty(_findMat) && _findMatOld) {
|
|
|
|
|
if (open !== true) {
|
|
|
|
|
form.resetFields()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
setStickToProps({})
|
|
|
|
|
setStickToCid('')
|
|
|
|
|
setEmailOrder('')
|
|
|
|
|
setEmailOPI('')
|
|
|
|
|
setNewFromEmail('')
|
|
|
|
|
setNewToEmail('')
|
|
|
|
|
}
|
|
|
|
|
}, [open])
|
|
|
|
|
|
|
|
|
|
// 转发/回复时, 使用详情的账户信息
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const reEmailO = mailData.info?.MAI_COLI_SN
|
|
|
|
|
const reEmailUser = mailData.info?.MAI_OPI_SN
|
|
|
|
|
const reEmailUserMat = mailData.info?.MAI_MAT_SN
|
|
|
|
|
|
|
|
|
|
setEmailOrder(prev => reEmailO || prev);
|
|
|
|
|
setEmailOPI(prev => reEmailUser || prev);
|
|
|
|
|
setEmailMat(prev => reEmailUserMat || prev)
|
|
|
|
|
|
|
|
|
|
const _findMatOld = emailListMatMapped?.[reEmailUserMat]
|
|
|
|
|
if (_findMatOld) {
|
|
|
|
|
setNewFromEmail(_findMatOld.email)
|
|
|
|
|
setEmailOPI(_findMatOld.opi_sn)
|
|
|
|
|
setEmailMat(_findMatOld.mat_sn)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return () => {}
|
|
|
|
|
}, [open, fromEmail, fromUser, toEmail, mailData])
|
|
|
|
|
}, [mailData])
|
|
|
|
|
|
|
|
|
|
const handleSwitchEmail = (labelValue) => {
|
|
|
|
|
const { value } = labelValue
|
|
|
|
@ -120,24 +157,6 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, toEmail, convers
|
|
|
|
|
setEmailOPI(_findMat?.opi_sn)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { notification, message } = App.useApp();
|
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
|
|
|
|
|
|
// 存储会话ID,
|
|
|
|
|
// 这个窗口没有模态, 即使不是focus, 还是需要保持会话ID
|
|
|
|
|
// 否则, 会话列表切换之后, 会话ID更新, 导致消息关联错误
|
|
|
|
|
const [stickToCid, setStickToCid] = useState(conversationid);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setStickToCid(conversationid)
|
|
|
|
|
if (open !== true) {
|
|
|
|
|
form.resetFields();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return () => {}
|
|
|
|
|
}, [open])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [isRichText, setIsRichText] = useState(mobile === false);
|
|
|
|
|
// const [isRichText, setIsRichText] = useState(false); // 默认纯文本
|
|
|
|
|
const [htmlContent, setHtmlContent] = useState('');
|
|
|
|
@ -164,9 +183,6 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, toEmail, convers
|
|
|
|
|
const [initialForm, setInitialForm] = useState({});
|
|
|
|
|
const [initialContent, setInitialContent] = useState('');
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 加载邮件数据
|
|
|
|
|
*/
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
// console.log('quoteid', quoteid, isEmpty(quoteid), isEmpty(mailData.info));
|
|
|
|
|
|
|
|
|
@ -184,12 +200,12 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, toEmail, convers
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const _formValues = {
|
|
|
|
|
to: info?.MAI_From || fromEmail,
|
|
|
|
|
to: info?.MAI_From || newFromEmail,
|
|
|
|
|
cc: info?.MAI_CS || '',
|
|
|
|
|
// bcc: quote.bcc || '',
|
|
|
|
|
subject: `Re: ${info.MAI_Subject || ''}`,
|
|
|
|
|
};
|
|
|
|
|
const forwardValues = { subject: `Fw: ${info.subject || ''}` };
|
|
|
|
|
const forwardValues = { subject: `Fw: ${info.MAI_Subject || ''}` };
|
|
|
|
|
if (action === 'reply') {
|
|
|
|
|
form.setFieldsValue(_formValues);
|
|
|
|
|
setInitialForm(_formValues);
|
|
|
|
@ -209,13 +225,13 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, toEmail, convers
|
|
|
|
|
|
|
|
|
|
setInitialContent(thisBody)
|
|
|
|
|
} else if (action === 'new') {
|
|
|
|
|
const newEmail = { to: toEmail, }
|
|
|
|
|
const newEmail = { to: newToEmail, }
|
|
|
|
|
form.setFieldsValue(newEmail);
|
|
|
|
|
setInitialForm(newEmail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return () => {};
|
|
|
|
|
}, [open, action, mailData.info]);
|
|
|
|
|
}, [stickToProps, mailData.info, newToEmail, newFromEmail]);
|
|
|
|
|
|
|
|
|
|
const [openPlainTextConfirm, setOpenPlainTextConfirm] = useState(false);
|
|
|
|
|
const handlePlainTextOpenChange = ({ target }) => {
|
|
|
|
@ -306,15 +322,16 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, toEmail, convers
|
|
|
|
|
const [sendLoading, setSendLoading] = useState(false);
|
|
|
|
|
|
|
|
|
|
const onHandleSend = async () => {
|
|
|
|
|
console.log('onSend callback', '\nisRichText', isRichText);
|
|
|
|
|
// console.log('onSend callback', '\nisRichText', isRichText);
|
|
|
|
|
// console.log(form.getFieldsValue());
|
|
|
|
|
const body = structuredClone(form.getFieldsValue());
|
|
|
|
|
body.mailcontent = isRichText ? htmlContent : textContent;
|
|
|
|
|
body.from = newFromEmail || fromEmail;
|
|
|
|
|
body.from = newFromEmail;
|
|
|
|
|
body.attaList = fileList;
|
|
|
|
|
body.opi_sn = emailOPI;
|
|
|
|
|
body.mat_sn = emailMat;
|
|
|
|
|
console.log('body', body);
|
|
|
|
|
body.coli_sn = emailOrder || '';
|
|
|
|
|
// console.log('body', body, '\n', emailOrder);
|
|
|
|
|
const values = await form.validateFields();
|
|
|
|
|
body.cc = values.cc || '';
|
|
|
|
|
body.bcc = values.bcc || '';
|
|
|
|
@ -338,14 +355,14 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, toEmail, convers
|
|
|
|
|
try {
|
|
|
|
|
const bubbleMsg = cloneDeep(msgObj);
|
|
|
|
|
bubbleMsg.id = `${stickToCid}.${msgObj.id}`;
|
|
|
|
|
bubbleMsg.email.mai_sn = '';
|
|
|
|
|
// bubbleMsg.email.mai_sn = '';
|
|
|
|
|
bubbleMsg.content = undefined;
|
|
|
|
|
invokeEmailMessage(bubbleMsg);
|
|
|
|
|
// invokeEmailMessage(bubbleMsg);
|
|
|
|
|
|
|
|
|
|
const result = await postSendEmail(body);
|
|
|
|
|
// const mailSavedId = result.id || '';
|
|
|
|
|
// bubbleMsg.email.mai_sn = mailSavedId;
|
|
|
|
|
// invokeEmailMessage(bubbleMsg);
|
|
|
|
|
const mailSavedId = result.id || '';
|
|
|
|
|
bubbleMsg.email.mai_sn = mailSavedId;
|
|
|
|
|
invokeEmailMessage(bubbleMsg);
|
|
|
|
|
|
|
|
|
|
// setSendLoading(false);
|
|
|
|
|
|
|
|
|
@ -358,8 +375,9 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, toEmail, convers
|
|
|
|
|
duration: 3,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
setSendLoading(false);
|
|
|
|
|
}
|
|
|
|
|
setSendLoading(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -382,8 +400,8 @@ const EmailEditorPopup = ({ open, setOpen, fromEmail, fromUser, toEmail, convers
|
|
|
|
|
}}
|
|
|
|
|
title={
|
|
|
|
|
<>
|
|
|
|
|
{loading ? <LoadingOutlined className='mr-1' /> : null}
|
|
|
|
|
{initialForm.subject || `${!isEmpty(quoteid) ? '回复: ' : '写邮件: '} ${fromEmail || ''}`}
|
|
|
|
|
{getLoading ? <LoadingOutlined className='mr-1' /> : null}
|
|
|
|
|
{initialForm.subject || `${!isEmpty(quoteid) ? '回复: ' : '写邮件: '} ${newFromEmail || ''}`}
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
footer={
|
|
|
|
|