|
|
|
@ -2,7 +2,7 @@ import { useEffect, useState, useRef } from 'react';
|
|
|
|
|
import { useParams, useNavigate, useLocation } from 'react-router-dom';
|
|
|
|
|
import { Button, Dropdown, Input } from 'antd';
|
|
|
|
|
import { MoreOutlined } from '@ant-design/icons';
|
|
|
|
|
import { fetchOrderConversationsList, fetchConversationItemClose, fetchMessages } from '@/actions/ConversationActions';
|
|
|
|
|
import { fetchOrderConversationsList, fetchConversationItemClose, fetchMessages, fetchCleanUnreadMsgCount } from '@/actions/ConversationActions';
|
|
|
|
|
import { ChatList, ChatItem } from 'react-chat-elements';
|
|
|
|
|
import { isEmpty } from '@/utils/utils';
|
|
|
|
|
import useConversationStore from '@/stores/ConversationStore';
|
|
|
|
@ -28,6 +28,10 @@ const Conversations = () => {
|
|
|
|
|
const setMsgLoading = useConversationStore((state) => state.setMsgLoading);
|
|
|
|
|
|
|
|
|
|
const [dataSource, setDataSource] = useState(conversationsList);
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setDataSource(conversationsList);
|
|
|
|
|
return () => {};
|
|
|
|
|
}, [conversationsList]);
|
|
|
|
|
|
|
|
|
|
const [switchToC, setSwitchToC] = useState({});
|
|
|
|
|
const [shouldFetchCList, setShouldFetchCList] = useState(true);
|
|
|
|
@ -65,9 +69,10 @@ const Conversations = () => {
|
|
|
|
|
receivedMessageList(item.sn, data);
|
|
|
|
|
};
|
|
|
|
|
const switchConversation = async (item) => {
|
|
|
|
|
fetchCleanUnreadMsgCount({ opisn: item.opi_sn, whatsappid: item.whatsapp_phone_number });
|
|
|
|
|
const messagesList = activeConversations[`${item.sn}`] || [];
|
|
|
|
|
if (messagesList.length < 20) {
|
|
|
|
|
await getMessages(item);
|
|
|
|
|
getMessages(item);
|
|
|
|
|
}
|
|
|
|
|
if (String(item.sn) === String(currentConversation.sn)) {
|
|
|
|
|
return false;
|
|
|
|
@ -75,7 +80,7 @@ const Conversations = () => {
|
|
|
|
|
setCurrentConversation(item);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onSwitchConversation = (item) => {
|
|
|
|
|
const onSwitchConversation = async (item) => {
|
|
|
|
|
if (!isEmpty(item.coli_sn)) {
|
|
|
|
|
setSwitchToC(item);
|
|
|
|
|
setShouldFetchCList(false);
|
|
|
|
@ -100,7 +105,7 @@ const Conversations = () => {
|
|
|
|
|
if (val.toLowerCase().trim() !== '') {
|
|
|
|
|
const res = conversationsList.filter(
|
|
|
|
|
(item) => (item.whatsapp_name.toLowerCase()).includes(val.toLowerCase().trim())
|
|
|
|
|
|| (item.whatsapp_name.toLowerCase()).includes(val.toLowerCase().trim())
|
|
|
|
|
|| (item.whatsapp_phone_number.toLowerCase()).includes(val.toLowerCase().trim())
|
|
|
|
|
|| (item.coli_id.toLowerCase()).includes(val.toLowerCase().trim())
|
|
|
|
|
);
|
|
|
|
|
setDataSource(res);
|
|
|
|
@ -122,6 +127,12 @@ const Conversations = () => {
|
|
|
|
|
setSearchContent(e.target.value);
|
|
|
|
|
handleSearchConversations(e.target.value);
|
|
|
|
|
}}
|
|
|
|
|
onPressEnter={(e) => {
|
|
|
|
|
handleSearchConversations(e.target.value);
|
|
|
|
|
searchInputRef.current.blur();
|
|
|
|
|
onSwitchConversation(dataSource[0]);
|
|
|
|
|
return false;
|
|
|
|
|
}}
|
|
|
|
|
placeholder='搜索名称'
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|