diff --git a/package.json b/package.json index 08c8fa9..3db6544 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "global-sales", "private": true, - "version": "1.4.10", + "version": "1.5.0-1", "type": "module", "scripts": { "dev": "vite", diff --git a/src/actions/EmailActions.js b/src/actions/EmailActions.js index 1a61f75..42cdcf4 100644 --- a/src/actions/EmailActions.js +++ b/src/actions/EmailActions.js @@ -1,5 +1,5 @@ import { fetchJSON, postForm, postJSON } from '@/utils/request'; -import { API_HOST, API_HOST_V3, DATE_FORMAT, DATEEND_FORMAT, DATETIME_FORMAT, EMAIL_HOST } from '@/config'; +import { API_HOST, API_HOST_V3, DATE_FORMAT, DATEEND_FORMAT, DATETIME_FORMAT, EMAIL_HOST, EMAIL_HOST_v3 } from '@/config'; import { buildTree, groupBy, isEmpty, objectMapper, omitEmpty, uniqWith } from '@/utils/commons'; import { readIndexDB, writeIndexDB } from '@/utils/indexedDB'; import dayjs from 'dayjs'; @@ -208,7 +208,7 @@ export const getMailboxCountAction = async (params = { opi_sn: '' }, update = tr const ret = errcode !== 0 ? { [`${params.opi_sn}`]: {} } : { [`${params.opi_sn}`]: result } // 更新数量 if (update !== false) { - const readCacheDir = await readIndexDB(Number(params.opi_sn), 'dirs', 'mailbox'); + const readCacheDir = (await readIndexDB(Number(params.opi_sn), 'dirs', 'mailbox')) || {}; const mailboxDir = isEmpty(readCacheDir) ? [] : readCacheDir.tree.filter(node => node?._raw?.IsTrue === 1); const _MapDir = new Map(mailboxDir.map((obj) => [obj.key, obj])) Object.keys(result).map(dirKey => { @@ -220,7 +220,7 @@ export const getMailboxCountAction = async (params = { opi_sn: '' }, update = tr _MapRoot.set(row.key, row) }) const _newRoot = Array.from(_MapRoot.values()) - writeIndexDB([{ key: Number(params.opi_sn), tree: _newRoot }], 'dirs', 'mailbox') + writeIndexDB([{ ...readCacheDir, key: Number(params.opi_sn), tree: _newRoot }], 'dirs', 'mailbox') notifyMailboxUpdate({ type: 'dirs', key: Number(params.opi_sn) }) } @@ -338,7 +338,7 @@ export const getRootMailboxDirAction = async ({ opi_sn = 0, userIdStr = '' } = { const mailBoxCount = await Promise.all(userIdStr.split(',').map(_opi => getMailboxCountAction({ opi_sn: _opi }, false))); const mailboxDirCountByOPI = mailBoxCount.reduce((a, c) => ({ ...a, ...c, }), {}) const mailboxDirByOPI = mailboxDir.reduce((a, c) => ({ ...a, ...(Object.keys(c).reduce((a, opi) => ({...a, [opi]: c[`${opi}`].map((dir) => ({ ...dir, count: mailboxDirCountByOPI[opi][`${dir.key}`] })) }), {} )) }), {}) - const rootTree = Object.keys(stickyTree).map((opi) => ({ key: Number(opi), tree: [...stickyTree[opi], ...(mailboxDirByOPI?.[opi] || [])] })) + const rootTree = Object.keys(stickyTree).map((opi) => ({ key: Number(opi), tree: [...stickyTree[opi], ...(mailboxDirByOPI?.[opi] || [])], treeTimestamp: Date.now() })) writeIndexDB(rootTree, 'dirs', 'mailbox') const _mapped = groupBy(rootTree, 'key') return _mapped[opi_sn]?.[0]?.tree || [] @@ -348,7 +348,6 @@ export const getRootMailboxDirAction = async ({ opi_sn = 0, userIdStr = '' } = { * 获取邮件列表 * @usage 邮件目录下的邮件列表 * @usage 订单的邮件列表 - * @usage 高级搜索 */ export const queryEmailListAction = async ({ opi_sn = '', pagesize = 10, last_id = '', node = {}, } = {}) => { const _params = { @@ -375,6 +374,20 @@ export const queryEmailListAction = async ({ opi_sn = '', pagesize = 10, last_id return ret; } +export const searchEmailListAction = async ({opi_sn = '', mailboxtype = 'ALL', sender = '', receiver = '', subject = '', content=''}={}) => { + const formData = new FormData() + formData.append('opi_sn', opi_sn) + formData.append('mailboxtype', mailboxtype) + formData.append('sender', sender) + formData.append('receiver', receiver) + formData.append('subject', subject) + // formData.append('content', content) + const { errcode, result } = await postForm(`${API_HOST_V3}/mail_search`, formData) + const ret = errcode === 0 ? result : [] + notifyMailboxUpdate({ type: 'maillist-search-result', query: [sender, receiver, subject].filter(s => s).join(' '), data: ret.map(ele => ({...ele, key: ele.MAI_SN})) }) + return ret; +} + const removeFromCurrentList = async (params) => { const readRow0 = await readIndexDB(params.mai_sn_list[0], 'listrow', 'mailbox') const listKey = readRow0?.data?.listKey || '' @@ -442,7 +455,7 @@ export const getReminderEmailTemplateAction = async (params = { coli_sn: 0, lgc: * @param {boolean} [isDraft=false] - Whether the email is a draft. */ export const saveEmailDraftOrSendAction = async (body, isDraft = false) => { - const url = isDraft !== false ? `${API_HOST_V3}/email_draft_save` : `${EMAIL_HOST}/sendmail`; + const url = isDraft !== false ? `${API_HOST_V3}/email_draft_save` : `${EMAIL_HOST_v3}/sendmail`; const { attaList=[], atta, content, ...bodyData } = body; bodyData.ordertype = 227001; const formData = new FormData(); @@ -476,7 +489,3 @@ export const queryOPIOrderAction = async (params) => { return errcode !== 0 ? [] : result }; -export const queryInMailboxAction = async (params) => { - const { errcode, result } = await fetchJSON(`${API_HOST_V3}/mail_search`, params) - return errcode !== 0 ? [] : result -} diff --git a/src/components/OrderProfile.jsx b/src/components/OrderProfile.jsx index 64478de..2fa2a3c 100644 --- a/src/components/OrderProfile.jsx +++ b/src/components/OrderProfile.jsx @@ -13,7 +13,7 @@ import { } from '@ant-design/icons' import { useEffect, useState } from 'react' -import { Link, useNavigate } from 'react-router-dom' +import { Link } from 'react-router-dom' import { App, Flex, Select, Tooltip, Divider, Typography, Skeleton, Checkbox, Drawer, Button, Form, Input } from 'antd' import { useOrderStore, fetchSetRemindStateAction, OrderLabelDefaultOptions, OrderStatusDefaultOptions, remindStatusOptions } from '@/stores/OrderStore' import { copy, isEmpty } from '@/utils/commons' @@ -21,24 +21,28 @@ import { useShallow } from 'zustand/react/shallow' import useConversationStore from '@/stores/ConversationStore' import useAuthStore from '@/stores/AuthStore' const OrderProfile = ({ coliSN, ...props }) => { - const navigate = useNavigate() const { notification, message } = App.useApp() - const [formComment, formWhatsApp] = Form.useForm() + const [formComment] = Form.useForm() + const [formWhatsApp] = Form.useForm() + const [formExtra] = Form.useForm() const [loading, setLoading] = useState(false) const [openOrderCommnet, setOpenOrderCommnet] = useState(false) const [openWhatsApp, setOpenWhatsApp] = useState(false) + const [openExtra, setOpenExtra] = useState(false) const orderLabelOptions = copy(OrderLabelDefaultOptions) orderLabelOptions.unshift({ value: 0, label: '未设置', disabled: true }) const orderStatusOptions = copy(OrderStatusDefaultOptions) - const [orderDetail, customerDetail, fetchOrderDetail, setOrderPropValue, appendOrderComment] = useOrderStore((s) => [ + const [orderDetail, customerDetail, fetchOrderDetail, setOrderPropValue, appendOrderComment, updateWhatsapp, updateExtraInfo] = useOrderStore((s) => [ s.orderDetail, s.customerDetail, s.fetchOrderDetail, s.setOrderPropValue, s.appendOrderComment, + s.updateWhatsapp, + s.updateExtraInfo, ]) const loginUser = useAuthStore((state) => state.loginUser) @@ -47,8 +51,8 @@ const OrderProfile = ({ coliSN, ...props }) => { const [orderRemindState, setOrderRemindState] = useState(orderDetail.remindstate) useEffect(() => { - setOrderRemindState(orderDetail.remindstate); - }, [orderDetail.remindstate]); + setOrderRemindState(orderDetail.remindstate) + }, [orderDetail.remindstate]) useEffect(() => { if (orderId) { setLoading(true) @@ -119,12 +123,15 @@ const OrderProfile = ({ coliSN, ...props }) => { - {isEmpty(customerDetail.whatsapp_phone_number) ? - : - - {customerDetail.whatsapp_phone_number} - - } + {isEmpty(customerDetail.whatsapp_phone_number) ? ( + + ) : ( + + {customerDetail.whatsapp_phone_number} + + )} @@ -227,9 +234,15 @@ const OrderProfile = ({ coliSN, ...props }) => { 附加信息 - {/* - - */} + + { + formExtra.setFieldsValue({ extra: orderDetail.COLI_Introduction }) + setOpenExtra(true) + }} + /> + {orderDetail.COLI_Introduction} @@ -240,7 +253,6 @@ const OrderProfile = ({ coliSN, ...props }) => { initialValues={{ comment: '' }} scrollToFirstError onFinish={(values) => { - console.log('Received values of form: ', values) appendOrderComment(loginUser.userId, orderId, values.comment) .then(() => { notification.success({ @@ -276,15 +288,47 @@ const OrderProfile = ({ coliSN, ...props }) => { initialValues={{ number: '' }} scrollToFirstError onFinish={(values) => { - console.log('Received values of form: ', values) - // appendOrderComment(loginUser.userId, orderId, values.number) + updateWhatsapp(orderId, values.number) .then(() => { notification.success({ message: '温性提示', description: '设置 WhatsApp 成功', }) setOpenWhatsApp(false) - formComment.setFieldsValue({ number: '' }) + formWhatsApp.setFieldsValue({ number: '' }) + }) + .catch((reason) => { + notification.error({ + message: '设置出错', + description: reason.message, + placement: 'top', + duration: 60, + }) + }) + }}> + + + + + + + + + setOpenExtra(false)} open={openExtra}> +
{ + updateExtraInfo(orderId, values.extra) + .then(() => { + notification.success({ + message: '温性提示', + description: '设置附加信息成功', + }) + setOpenExtra(false) }) .catch((reason) => { notification.error({ @@ -295,8 +339,8 @@ const OrderProfile = ({ coliSN, ...props }) => { }) }) }}> - - + +