diff --git a/src/actions/ConversationActions.js b/src/actions/ConversationActions.js
index e12a4c6..991eb94 100644
--- a/src/actions/ConversationActions.js
+++ b/src/actions/ConversationActions.js
@@ -1,8 +1,9 @@
-import { groupBy } from '@/utils/utils';
+import { groupBy, pick } from '@/utils/utils';
import { fetchJSON, postJSON } from '@/utils/request'
import { parseRenderMessageList } from '@/lib/msgUtils';
import { API_HOST } from '@/config';
+import { isEmpty } from '@/utils/commons';
export const fetchTemplates = async () => {
const data = await fetchJSON(`${API_HOST}/listtemplates`);
@@ -17,7 +18,8 @@ export const fetchTemplates = async () => {
* @param {object} params { opisn }
*/
export const fetchConversationsList = async (params) => {
- const { result: data } = await fetchJSON(`${API_HOST}/getconversations`, params);
+ const { errcode, result: data } = await fetchJSON(`${API_HOST}/getconversations`, params);
+ if (errcode !== 0) return [];
const list = (data || []).map((ele) => ({ ...ele, customer_name: `${ele.whatsapp_name || ''}`.trim(), whatsapp_name: `${ele.whatsapp_name || ''}`.trim() }));
return list;
};
@@ -72,3 +74,41 @@ export const fetchCleanUnreadMsgCount = async (params) => {
* ------------------------------------------------------------------------------------------------
* 历史记录
*/
+/**
+ * @param {object} params { search, from_date, end_date, whatsapp_id, opisn, coli_id, msg_type }
+ * @todo msg_type
+ */
+export const fetchConversationsSearch = async (params) => {
+ const { errcode, result: data } = await fetchJSON(`${API_HOST}/conversation_search`, params);
+ const list =
+ errcode !== 0
+ ? []
+ : (data || []).map((ele) => ({
+ ...ele,
+ customer_name: `${ele.whatsapp_name || ''}`.trim(),
+ whatsapp_name: `${ele.whatsapp_name || ''}`.trim(),
+ matchMsgList: parseRenderMessageList((ele.msglist_AsJOSN || [])), // .reverse()),
+ }));
+ return list;
+};
+
+/**
+ *
+ * @param {object} params { opisn, whatsappid, lasttime, pagesize, pagedir }
+ */
+export const fetchMessagesHistory = async (params) => {
+ const defaultParams = {
+ opisn: '',
+ whatsappid: '',
+ lasttime: '2024-01-01T00:00:00',
+ pagesize: MESSAGE_PAGE_SIZE,
+ pagedir: 'next',
+ };
+ const _params = pick(params, Object.keys(defaultParams));
+ if (isEmpty(_params.opisn) || isEmpty(_params.whatsappid)) {
+ return [];
+ }
+ const { errcode, result } = await fetchJSON(`${API_HOST}/get_item_messages`, {...defaultParams, ..._params});
+ const data = errcode !== 0 ? [] : result; // _params.pagedir === 'next' ? result.reverse() : result;
+ return parseRenderMessageList(data);
+}
diff --git a/src/components/SearchInput.jsx b/src/components/SearchInput.jsx
index cf61f9d..cfd7354 100644
--- a/src/components/SearchInput.jsx
+++ b/src/components/SearchInput.jsx
@@ -30,6 +30,7 @@ function DebounceSelect({ fetchOptions, debounceTimeout = 800, ...props }) {
showSearch
allowClear
{...props}
+ maxTagCount={1}
onSearch={debounceFetcher}
notFoundContent={fetching ? : null}
optionFilterProp='label'
diff --git a/src/lib/msgUtils.js b/src/lib/msgUtils.js
index 35bcc13..38b57cf 100644
--- a/src/lib/msgUtils.js
+++ b/src/lib/msgUtils.js
@@ -408,8 +408,8 @@ export const whatsappMsgTypeMapped = {
template: {
type: 'text',
data: (msg) => {
- const templateDataMapped = msg.template?.components ? msg.template.components.reduce((r, v) => ({ ...r, [v.type]: v }), {}) : null;
- return { id: msg.wamid, text: autoLinkText(templateDataMapped?.body?.text || `......${templateDataMapped?.body?.parameters.map(pv => pv?.text || '').join('......')}......`), title: msg.template.name };
+ const templateDataMapped = msg.template?.components ? msg.template.components.reduce((r, v) => ({ ...r, [v.type]: v }), {}) : {};
+ return { id: msg.wamid, text: autoLinkText(templateDataMapped?.body?.text || `......${(templateDataMapped?.body?.parameters || []).map(pv => pv?.text || '').join('......')}......`), title: msg.template.name };
},
renderForReply: (msg) => {
const templateDataMapped = msg.template?.components ? msg.template.components.reduce((r, v) => ({ ...r, [v.type]: v }), {}) : null;
diff --git a/src/stores/FormStore.js b/src/stores/FormStore.js
index 68ef9ef..d79605b 100644
--- a/src/stores/FormStore.js
+++ b/src/stores/FormStore.js
@@ -8,6 +8,10 @@ export const useFormStore = create(
setChatHistoryForm: (chatHistoryForm) => set({ chatHistoryForm, chatHistorySelectChat: {} }),
chatHistorySelectChat: {},
setChatHistorySelectChat: (chatHistorySelectChat) => set({ chatHistorySelectChat }),
+ msgHistorySelectMatch: {},
+ setMsgHistorySelectMatch: (msgHistorySelectMatch) => set({ msgHistorySelectMatch }),
+ msgListParams: {},
+ setMsgListParams: (msgListParams) => set(state => ({ msgListParams: {...state.msgListParams, ...msgListParams} })),
// 订单跟踪页面
orderFollowForm: {
diff --git a/src/views/ChatHistory.jsx b/src/views/ChatHistory.jsx
index 67f176a..1882e14 100644
--- a/src/views/ChatHistory.jsx
+++ b/src/views/ChatHistory.jsx
@@ -1,12 +1,14 @@
import { memo, useCallback, useEffect, useRef, useState, forwardRef } from 'react';
-import { Divider, Button, Input, Layout, DatePicker, Form, List, Spin } from 'antd';
+import { Divider, Button, Input, Layout, DatePicker, Form, List, Spin, Flex } from 'antd';
+import { LoadingOutlined } from '@ant-design/icons';
import { ChatItem, MessageBox } from 'react-chat-elements';
-import { fetchConversationsList, fetchMessages, MESSAGE_PAGE_SIZE } from '@/actions/ConversationActions';
-import { isEmpty, stringToColour } from '@/utils/utils';
+import { MESSAGE_PAGE_SIZE, fetchConversationsSearch, fetchMessagesHistory } from '@/actions/ConversationActions';
+import { cloneDeep, flush, isEmpty, pick, stringToColour } from '@/utils/utils';
import useFormStore from '@/stores/FormStore';
import { fetchSalesAgent, fetchCustomerList } from '@/actions/CommonActions';
import SearchInput from '@/components/SearchInput';
+import { isNotEmpty } from '@/utils/commons';
const { Sider, Content, Header, Footer } = Layout;
const { Search } = Input;
@@ -18,10 +20,16 @@ const { RangePicker } = DatePicker;
const SearchForm = memo(function ({ initialValues, onSubmit }) {
const [form] = Form.useForm();
function handleSubmit(values) {
+ const multiAgents = (values?.agent || []).map(ele => ele.value).join(',');
+ const multiCustomers = (values?.customer || []).map(ele => ele.value).join(',');
onSubmit?.({
...values,
- opisn: values?.agent?.value || '',
- customer_name: values?.customer?.label || '',
+ opisn: multiAgents,
+ whatsapp_id: multiCustomers,
+ ...(isNotEmpty(values.msgDateRange) ? {
+ from_date: values.msgDateRange[0].format('YYYY-MM-DD'),
+ end_date: values.msgDateRange[1].format('YYYY-MM-DD'),
+ } : {}),
});
}
return (
@@ -30,29 +38,21 @@ const SearchForm = memo(function ({ initialValues, onSubmit }) {
form={form}
initialValues={initialValues}
onFinish={handleSubmit}
- style={{
- maxWidth: 'none',
- }}>
-
-
+ style={{}}>
+
+
-
+
+
+
+
- {/*
- */}
-
-
+
+