|
|
|
import { fetchJSON, postForm, postJSON } from '@/utils/request';
|
|
|
|
import { API_HOST, EMAIL_HOST } from '@/config';
|
|
|
|
import { buildTree, isEmpty, objectMapper } from '@/utils/commons';
|
|
|
|
|
|
|
|
const parseHTMLString = (html, needText = false) => {
|
|
|
|
const parser = new DOMParser()
|
|
|
|
const doc = parser.parseFromString(html, 'text/html')
|
|
|
|
let bodyContent = doc.body.innerHTML
|
|
|
|
// bodyContent = bodyContent.replace(/<img/g, '<img onerror="this.onerror=null;this.src=\'https://hiana-crm.oss-accelerate.aliyuncs.com/WAMedia/afe412d4-3acf-4e79-a623-048aeb4d696a.png\';"')
|
|
|
|
const bodyText = (doc.body.innerText);
|
|
|
|
return needText ? { html, bodyContent, bodyText } : bodyContent
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取顾问签名
|
|
|
|
* @param {object} { opi_sn }
|
|
|
|
*/
|
|
|
|
export const getSalesSignatureAction = async (params) => {
|
|
|
|
try {
|
|
|
|
const { result } = await fetchJSON(`${EMAIL_HOST}/email_sign`, params)
|
|
|
|
const { SignContent: html } = result
|
|
|
|
const bodyContent = parseHTMLString(html);
|
|
|
|
return bodyContent;
|
|
|
|
} catch (error) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 发送邮件
|
|
|
|
*/
|
|
|
|
export const postSendEmail = async (body) => {
|
|
|
|
const { attaList=[], atta, content, ...bodyData } = body;
|
|
|
|
bodyData.ordertype = 227001;
|
|
|
|
const formData = new FormData();
|
|
|
|
Object.keys(bodyData).forEach(function (key) {
|
|
|
|
formData.append(key, bodyData[key]);
|
|
|
|
});
|
|
|
|
attaList.forEach(function (item) {
|
|
|
|
formData.append('attachment', item);
|
|
|
|
});
|
|
|
|
const { result } = await postForm(`${EMAIL_HOST}/sendmail`, formData);
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 重发邮件
|
|
|
|
* @param {object} { mai_sn }
|
|
|
|
*/
|
|
|
|
export const postResendEmailAction = async (body) => {
|
|
|
|
const { attaList, atta, content, ...bodyData } = body;
|
|
|
|
const formData = new FormData();
|
|
|
|
Object.keys(bodyData).forEach(function (key) {
|
|
|
|
formData.append(key, bodyData[key]);
|
|
|
|
});
|
|
|
|
return await postForm(`${EMAIL_HOST}/email_resend`, formData);
|
|
|
|
};
|
|
|
|
|
|
|
|
const encodeEmailInfo = (info) => {
|
|
|
|
const encodeQuote = (str = '') => str.replace(/"/g, ''); //.replace(/</g,'<').replace(/>/g,'>')
|
|
|
|
|
|
|
|
const CSsClean = encodeQuote(info.MAI_CS).includes(',') ? encodeQuote(info.MAI_CS).split(',') : encodeQuote(info.MAI_CS).split(';');
|
|
|
|
const tosClean = (encodeQuote(info.MAI_To).includes(',') ? encodeQuote(info.MAI_To).split(',') : encodeQuote(info.MAI_To).split(';')).concat(CSsClean).filter(s => s);
|
|
|
|
const replyTo = info.MAI_Direction === 1 ? info.MAI_To : info.MAI_From;
|
|
|
|
const replyToAll = (tosClean.length > 1) ?
|
|
|
|
(info.MAI_Direction === 1 ? tosClean.join(',') : [...tosClean, info.MAI_From].join(','))
|
|
|
|
: (info.MAI_Direction === 1 ? info.MAI_To : info.MAI_From)
|
|
|
|
return {
|
|
|
|
...info,
|
|
|
|
MAI_From: encodeQuote(info.MAI_From),
|
|
|
|
MAI_To: encodeQuote(info.MAI_To),
|
|
|
|
tos: [...new Set(tosClean)],
|
|
|
|
replyToAll,
|
|
|
|
replyTo,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* 邮件详情
|
|
|
|
* @param {object} { mai_sn }
|
|
|
|
*/
|
|
|
|
export const getEmailDetailAction = async (params) => {
|
|
|
|
const { result } = await fetchJSON(`${EMAIL_HOST}/getmail`, params);
|
|
|
|
let mailType = result.MailInfo?.[0]?.MAI_ContentType || '';
|
|
|
|
mailType = mailType === '' && (result.MailContent||'').includes('<html') ? 'text/html' : mailType;
|
|
|
|
|
|
|
|
const emailInfo = encodeEmailInfo(result.MailInfo?.[0] || {});
|
|
|
|
const isFromHub = emailInfo.MAI_From.includes('info@chinahighlights.net');
|
|
|
|
|
|
|
|
const delLinefeed = mailType === 'text/html' ? (result.MailContent||'').includes('<html') ? true : false : true;
|
|
|
|
const cleanContent = (result.MailContent || '').replace(/\r\n/g, delLinefeed ? '' : (isFromHub ? '<br>' : ''));
|
|
|
|
|
|
|
|
const { html, bodyContent, bodyText } = mailType === 'text/html' ? parseHTMLString(cleanContent, true) : { html: '', bodyContent: '', bodyText: '' };
|
|
|
|
|
|
|
|
const attachments = (isEmpty(result?.AttachList) ? [] : result.AttachList).filter(ele => isEmpty(ele.ATI_ContentID));
|
|
|
|
|
|
|
|
return {
|
|
|
|
info: { ...encodeEmailInfo(result.MailInfo?.[0] || {}), mailType },
|
|
|
|
content: mailType === 'text/html' ? html : result.MailContent || '',
|
|
|
|
abstract: bodyText || result.MailContent || '',
|
|
|
|
attachments,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getEmailOrderAction = async ({ colisn }) => {
|
|
|
|
const { errcode, result } = await fetchJSON(`${API_HOST}/getorderinfo`, { colisn })
|
|
|
|
return errcode === 0 ? { ...result[0], customerDetail: result[0].contact[0] } : {}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 主动收邮件, 单个账户
|
|
|
|
* @param {object} { opi_sn, }
|
|
|
|
*/
|
|
|
|
export const getEmailFetchAction = async (params) => {
|
|
|
|
const { opi_sn, } = params
|
|
|
|
const { result } = await fetchJSON(`${EMAIL_HOST}/email_fetch`, {
|
|
|
|
opi_sn,
|
|
|
|
})
|
|
|
|
return result
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 报价信邮件草稿
|
|
|
|
* @param {object} { sfi_sn, coli_sn, lgc }
|
|
|
|
*/
|
|
|
|
export const getEmailQuotationDraftAction = async (params) => {
|
|
|
|
const { result } = await fetchJSON(`${EMAIL_HOST}/QuotationLetter`, params)
|
|
|
|
return { subject: (result.Subject || ''), content: parseHTMLString((result.MailContent || '').replace(/\r\n/g, '')) }
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 单个邮件绑定订单
|
|
|
|
* @param {object} { conversationid, mai_sn, coli_sn, coli_id, sourcetype }
|
|
|
|
*/
|
|
|
|
export const fetchEmailBindOrderAction = async (params) => {
|
|
|
|
const { errcode, result } = await fetchJSON(`${API_HOST}/mailinfo_bindorder`, params)
|
|
|
|
return errcode === 0 ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 顾问的邮箱目录
|
|
|
|
* @param {object} { opi_sn }
|
|
|
|
*/
|
|
|
|
export const getEmailDirAction = async (params = { opi_sn: '' }) => {
|
|
|
|
const list = [{"VKey":-227001,"VName":"长线订单","VParent":2159,"ImageIndex":1,"COLI_SN":0,"OrderSourceType":0,"IsTrue":0,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":-12,"VName":"12月","VParent":-227001,"ImageIndex":1,"COLI_SN":0,"OrderSourceType":0,"IsTrue":0,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":-11,"VName":"11月","VParent":-227001,"ImageIndex":1,"COLI_SN":0,"OrderSourceType":0,"IsTrue":0,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":-10,"VName":"10月","VParent":-227001,"ImageIndex":1,"COLI_SN":0,"OrderSourceType":0,"IsTrue":0,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":-9,"VName":"9月","VParent":-227001,"ImageIndex":1,"COLI_SN":0,"OrderSourceType":0,"IsTrue":0,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":-8,"VName":"8月","VParent":-227001,"ImageIndex":1,"COLI_SN":0,"OrderSourceType":0,"IsTrue":0,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":-7,"VName":"7月","VParent":-227001,"ImageIndex":1,"COLI_SN":0,"OrderSourceType":0,"IsTrue":0,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":-6,"VName":"6月","VParent":-227001,"ImageIndex":1,"COLI_SN":0,"OrderSourceType":0,"IsTrue":0,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":-5,"VName":"5月","VParent":-227001,"ImageIndex":1,"COLI_SN":0,"OrderSourceType":0,"IsTrue":0,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":-4,"VName":"4月","VParent":-227001,"ImageIndex":1,"COLI_SN":0,"OrderSourceType":0,"IsTrue":0,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":-3,"VName":"3月","VParent":-227001,"ImageIndex":1,"COLI_SN":0,"OrderSourceType":0,"IsTrue":0,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":-2,"VName":"2月","VParent":-227001,"ImageIndex":1,"COLI_SN":0,"OrderSourceType":0,"IsTrue":0,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":-1,"VName":"1月","VParent":-227001,"ImageIndex":1,"COLI_SN":0,"OrderSourceType":0,"IsTrue":0,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":1,"VName":"李汉超(AH)","VParent":0,"ImageIndex":0,"COLI_SN":0,"OrderSourceType":0,"IsTrue":1,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":2159,"VName":"收件箱","VParent":1,"ImageIndex":3,"COLI_SN":0,"OrderSourceType":0,"IsTrue":1,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":2160,"VName":"未读邮件","VParent":1,"ImageIndex":11,"COLI_SN":0,"OrderSourceType":0,"IsTrue":1,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":2161,"VName":"已发邮件","VParent":1,"ImageIndex":4,"COLI_SN":0,"OrderSourceType":0,"IsTrue":1,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":2162,"VName":"待发邮件","VParent":1,"ImageIndex":2,"COLI_SN":0,"OrderSourceType":0,"IsTrue":1,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":2163,"VName":"草稿","VParent":1,"ImageIndex":5,"COLI_SN":0,"OrderSourceType":0,"IsTrue":1,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":2164,"VName":"垃圾邮件","VParent":1,"ImageIndex":7,"COLI_SN":0,"OrderSourceType":0,"IsTrue":1,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":2165,"VName":"已处理邮件","VParent":1,"ImageIndex":3,"COLI_SN":0,"OrderSourceType":0,"IsTrue":1,"ApplyDate":null,"IsSuccess":0,"COLI_OrderStartDate":null},{"VKey":1101593,"VName":"250104-LHC240621097(WX 1.3 老客人11人哈尔滨雪乡亚布力 全款已付)","VParent":-1,"ImageIndex":13,"COLI_SN":1101593,"OrderSourceType":227001,"IsTrue":0,"ApplyDate":"2025-01-04","IsSuccess":1,"COLI_OrderStartDate":"2025-01-04"},{"VKey":1122677,"VName":"250113-LHC241104145(1.13 KIMI老客人哈尔滨成都 全款已付)","VParent":-1,"ImageIndex":13,"COLI_SN":1122677,"OrderSourceType":227001,"IsTrue":0,"ApplyDate":"2025-01-14","IsSuccess":1,"COLI_OrderStartDate":"2025-01-14"},{"VKey":1129232,"VName":"250114-LHC241219062(1.13 老客人不丹 全款已付)","VParent":-1,"ImageIndex":13,"COLI_SN":1129232,"OrderSourceT
|
|
|
|
return list;
|
|
|
|
const { errcode, result } = await fetchJSON(`${EMAIL_HOST}/v3/email_dir`, params);
|
|
|
|
return errcode === 0 ? [] : result;
|
|
|
|
} ;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取邮件列表
|
|
|
|
* @usage 邮件目录下的邮件列表
|
|
|
|
* @usage 订单的邮件列表
|
|
|
|
* @usage 高级搜索
|
|
|
|
*/
|
|
|
|
export const queryEmailListAction = async ({ opi_sn= '', pagesize= 10, last_id= '', query={}, order= {} }={}) => {
|
|
|
|
const _params = { ...order, ...query, opi_sn }
|
|
|
|
const { errcode, result } = await postJSON(`${EMAIL_HOST}/v3/mail_list`, _params)
|
|
|
|
return errcode === 0 ? [] : result
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 更新邮件属性
|
|
|
|
*/
|
|
|
|
export const updateEmailAction = async (params = { mai_sn_list: [], set: {} }) => {
|
|
|
|
const { errcode, result } = await postJSON(`${EMAIL_HOST}/email/update`, params)
|
|
|
|
return errcode === 0 ? {} : result
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取邮件模板
|
|
|
|
*/
|
|
|
|
export const getEmailTemplateAction = async (template_name, params = { coli_sn: 0, lgc: 1 }) => {
|
|
|
|
const { errcode, result } = await fetchJSON(`${EMAIL_HOST}/email/template/${template_name}`, params)
|
|
|
|
return errcode === 0 ? {} : result
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 保存邮件草稿
|
|
|
|
*/
|
|
|
|
export const saveEmailDraftAction = async (body) => {
|
|
|
|
const { attaList=[], atta, content, ...bodyData } = body;
|
|
|
|
bodyData.ordertype = 227001;
|
|
|
|
const formData = new FormData();
|
|
|
|
Object.keys(bodyData).forEach(function (key) {
|
|
|
|
formData.append(key, bodyData[key]);
|
|
|
|
});
|
|
|
|
attaList.forEach(function (item) {
|
|
|
|
formData.append('attachment', item);
|
|
|
|
});
|
|
|
|
const { result } = await postForm(`${EMAIL_HOST}/email-draft/save`, formData);
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 删除邮件草稿
|
|
|
|
*/
|
|
|
|
export const deleteEmailDraftAction = async (id) => {
|
|
|
|
const { errcode, result } = await postJSON(`${EMAIL_HOST}/email-draft/delete`, { id })
|
|
|
|
return errcode === 0 ? {} : result
|
|
|
|
};
|