diff --git a/src/actions/ConversationActions.js b/src/actions/ConversationActions.js index 7908463..06618fa 100644 --- a/src/actions/ConversationActions.js +++ b/src/actions/ConversationActions.js @@ -1,6 +1,6 @@ import { groupBy, pick, sortArrayByOrder } from '@/utils/commons'; -import { fetchJSON, postJSON } from '@/utils/request' +import { fetchJSON, postJSON, postForm } from '@/utils/request' import { parseRenderMessageList } from '@/channel/whatsappUtils'; import { API_HOST } from '@/config'; import { isEmpty } from '@/utils/commons'; @@ -70,8 +70,20 @@ export const fetchConversationItemClose = async (body) => { * @param {object} body { phone_number, name } */ export const postNewConversationItem = async (body) => { - const { errcode, result } = await postJSON(`${API_HOST}/newconversation`, body); - return errcode !== 0 ? {} : result; + const formData = new FormData(); + Object.keys(body).forEach(function (key) { + formData.append(key, body[key]); + }); + const { errcode, result } = await postForm(`${API_HOST}/new_conversation`, formData); + if (errcode !== 0) { + return {}; + } + const resultItem = result?.[0] || {}; + return { + ...resultItem, + customer_name: `${resultItem.whatsapp_name || ''}`.trim(), + whatsapp_name: `${resultItem.whatsapp_name || ''}`.trim(), + }; }; /** @@ -86,6 +98,7 @@ export const fetchCleanUnreadMsgCount = async (params) => { * 标记未未读 * @param {object} body conversationItem: { sn, ... } */ +export const UNREAD_MARK = 999; export const fetchConversationItemUnread = async (body) => { const { errcode, result } = await fetchJSON(`${API_HOST}/set_state_unread`, body); return errcode !== 0 ? {} : result; diff --git a/src/stores/ConversationStore.js b/src/stores/ConversationStore.js index 66dcbe2..ea3ce14 100644 --- a/src/stores/ConversationStore.js +++ b/src/stores/ConversationStore.js @@ -178,7 +178,7 @@ const conversationSlice = (set, get) => ({ const withoutNew = conversationsList.filter((item) => !newListIds.includes(`${item.sn}`)); const mergedList = [...newList, ...withoutNew]; - const refreshTotalNotify = mergedList.reduce((r, c) => r+c.unread_msg_count, 0); + const refreshTotalNotify = mergedList.reduce((r, c) => r+(c.unread_msg_count === 999 ? 0 : c.unread_msg_count), 0); return set((state) => ({ conversationsList: mergedList, @@ -237,7 +237,7 @@ const messageSlice = (set, get) => ({ totalNotify: 0, msgListLoading: false, activeConversations: {}, - refreshTotalNotify: () => set((state) => ({ totalNotify: state.conversationsList.reduce((r, c) => r+c.unread_msg_count, 0) })), + refreshTotalNotify: () => set((state) => ({ totalNotify: state.conversationsList.reduce((r, c) => r+(c.unread_msg_count === 999 ? 0 : c.unread_msg_count), 0) })), setMsgLoading: (msgListLoading) => set({ msgListLoading }), receivedMessageList: (conversationid, msgList) => set((state) => ({ diff --git a/src/views/Conversations/Online/ConversationsList.jsx b/src/views/Conversations/Online/ConversationsList.jsx index 457440e..d5f9cf8 100644 --- a/src/views/Conversations/Online/ConversationsList.jsx +++ b/src/views/Conversations/Online/ConversationsList.jsx @@ -2,7 +2,7 @@ import { useEffect, useState, useRef } from 'react'; import { useParams, useNavigate, useLocation } from 'react-router-dom'; import { Dropdown, Input, Button, Empty, Tooltip, Tag, Select } from 'antd'; import { PlusOutlined, WhatsAppOutlined, LoadingOutlined, HistoryOutlined, FireOutlined, MessageFilled, FilterOutlined, PlusSquareOutlined } from '@ant-design/icons'; -import { fetchConversationsList, fetchOrderConversationsList, fetchConversationItemClose, fetchConversationsSearch, postNewConversationItem, fetchConversationItemUnread } from '@/actions/ConversationActions'; +import { fetchConversationsList, fetchOrderConversationsList, fetchConversationItemClose, fetchConversationsSearch, postNewConversationItem, fetchConversationItemUnread, UNREAD_MARK } from '@/actions/ConversationActions'; import { ChatItem } from 'react-chat-elements'; import ConversationsNewItem from './ConversationsNewItem'; import { isEmpty, olog } from '@/utils/commons'; @@ -29,7 +29,6 @@ const Conversations = ({ mobile }) => { const [conversationsListLoading, setConversationsListLoading] = useConversationStore((state) => [state.conversationsListLoading, state.setConversationsListLoading]); const addToConversationList = useConversationStore((state) => state.addToConversationList); const delConversationitem = useConversationStore((state) => state.delConversationitem); - const updateConversationItem = useConversationStore((state) => state.updateConversationItem); const closedConversationsList = useConversationStore((state) => state.closedConversationsList); const setClosedConversationList = useConversationStore((state) => state.setClosedConversationList); @@ -61,11 +60,15 @@ const Conversations = ({ mobile }) => { return () => {}; }, [isVisible]); + const [activeList, setActiveList] = useState(true); + const [dataSource, setDataSource] = useState(conversationsList); + const [listUpdateFlag, setListUpdateFlag] = useState(); useEffect(() => { - setDataSource(conversationsList); + // setDataSource(conversationsList); + setDataSource(activeList ? conversationsList: closedConversationsList); return () => {}; - }, [conversationsList.length]); + }, [conversationsList.length, listUpdateFlag, currentConversation.unread_msg_count]); const [switchToC, setSwitchToC] = useState({}); const [shouldFetchCList, setShouldFetchCList] = useState(true); @@ -141,22 +144,9 @@ const Conversations = ({ mobile }) => { }; const handleConversationItemUnread = async (item) => { - // updateConversationItem({ sn: item.sn, unread_msg_count: 1000 }); - // const bak_dataSource = dataSource; - // const targetIndex = bak_dataSource.findIndex((ele) => String(ele.sn) === String(item.sn)); - // bak_dataSource.splice(targetIndex, 1, { - // ...conversationsList[targetIndex], - // ...{ sn: item.sn, unread_msg_count: 1000 }, - // }) - setDataSource((prev) => - prev.map((ele) => { - return String(ele.sn) === String(item.sn) ? { ...ele, unread_msg_count: 1000 } : ele; - }) - ); - // setDataSource(bak_dataSource); - // setDataSource(conversationsList); await fetchConversationItemUnread({ conversationid: item.sn }); - refreshConversationList(); + await refreshConversationList(); + setListUpdateFlag(Math.random()); } const searchInputRef = useRef(null); @@ -181,23 +171,20 @@ const Conversations = ({ mobile }) => { } const [newChatModalVisible, setNewChatModalVisible] = useState(false); - const [newChatFormValues, setNewChatFormValues] = useState(); + const [newItemLoading, setNewItemLoading] = useState(false); const handleNewChat = async (values) => { // console.log(values); - const hasNewCurrent = await getOrderConversationList(values.coli_sn, values.phone_number); - if (hasNewCurrent !== false) { - // - } - setNewChatModalVisible(false); - // const newItem = await postNewConversationItem({...values, opi_sn: userId }); + const newChat = { phone_number: values.wa_id, remark_name: values.name }; + setNewItemLoading(true); + const createdNew = await postNewConversationItem({...newChat, opi_sn: userId }); // if ( ! isEmpty(newItem)) { - // addToConversationList(newItem); - // setCurrentConversation(newItem); + addToConversationList([createdNew]); + setCurrentConversation(createdNew); // } - // setNewChatFormValues(values); + setNewChatModalVisible(false); + setNewItemLoading(false); }; - const [activeList, setActiveList] = useState(true); // const closedVisible = closedConversationsList.length > 0; const toggleClosedConversationsList = () => { const _active = activeList; @@ -235,7 +222,7 @@ const Conversations = ({ mobile }) => { return (
- {['404', 383].includes(userId) &&
setNewChatModalVisible(false)} + loading={newItemLoading} />
); diff --git a/src/views/Conversations/Online/ConversationsNewItem.jsx b/src/views/Conversations/Online/ConversationsNewItem.jsx index abd6e21..d6725cd 100644 --- a/src/views/Conversations/Online/ConversationsNewItem.jsx +++ b/src/views/Conversations/Online/ConversationsNewItem.jsx @@ -58,14 +58,15 @@ export const ConversationItemForm = ({ initialValues, onFormInstanceReady }) => )} {!initialValues.is_current_order && ( - + )} + {/*
如果会话已存在, 将直接切换
*/} ); }; -export const ConversationItemFormModal = ({ open, onCreate, onCancel, initialValues }) => { +export const ConversationItemFormModal = ({ open, onCreate, onCancel, initialValues, loading }) => { const [formInstance, setFormInstance] = useState(); return ( { onCancel(); formInstance?.resetFields(); diff --git a/src/views/Conversations/Online/MessagesWrapper.jsx b/src/views/Conversations/Online/MessagesWrapper.jsx index 46b0e68..6aedf16 100644 --- a/src/views/Conversations/Online/MessagesWrapper.jsx +++ b/src/views/Conversations/Online/MessagesWrapper.jsx @@ -46,6 +46,7 @@ const MessagesWrapper = ({ updateRead = true, forceGetMessages }) => { if (updateRead === true && isVisible && currentConversation.opi_sn && currentConversation.whatsapp_phone_number && activeMessages.length > 0) { fetchCleanUnreadMsgCount({ opisn: currentConversation.opi_sn, whatsappid: currentConversation.whatsapp_phone_number }); refreshTotalNotify(); + updateCurrentConversation({ unread_msg_count: 0 }); } return () => {}; }, [activeMessages.length, isVisible]); diff --git a/src/views/orders/Follow.jsx b/src/views/orders/Follow.jsx index 45bd68f..963afd4 100644 --- a/src/views/orders/Follow.jsx +++ b/src/views/orders/Follow.jsx @@ -18,6 +18,7 @@ import dayjs from 'dayjs' import { memo, useCallback, useEffect, useState } from 'react' import { Link } from 'react-router-dom' import { useShallow } from 'zustand/react/shallow' +import { UNREAD_MARK } from '@/actions/ConversationActions'; const { RangePicker } = DatePicker @@ -54,11 +55,11 @@ const AdvanceSearchForm = memo(function noName({ initialValues, onSubmit }) { orderLabelOptions.unshift({ value: '', label: '全部' }) const orderStatusOptions = copy(OrderStatusDefaultOptions) - orderStatusOptions.unshift({ value: '', label: '全部' }) + orderStatusOptions.unshift({ value: '', label: '全部' }) const remindStateOptions = copy(RemindStateDefaultOptions) - remindStateOptions.unshift({ value: '', label: '全部' }) - + remindStateOptions.unshift({ value: '', label: '全部' }) + const [form] = Form.useForm() function handleSubmit(values) { @@ -151,7 +152,7 @@ function OrderGroupTable({ formValues }) { title: '订单号', dataIndex: 'COLI_ID', width: 222, - render: (text, record) => { + render: (text, record) => { let tagIcon = '' if (record.COLI_LineGrade === 240003) tagIcon = 重点 @@ -182,7 +183,7 @@ function OrderGroupTable({ formValues }) { /> {text + regularText} = UNREAD_MARK ? ' ' : record.unread_msg} style={{ backgroundColor: '#52c41a', }} @@ -213,7 +214,7 @@ function OrderGroupTable({ formValues }) { title: '报价 Title', dataIndex: 'lettertitle', ellipsis: true, - hidden: false, + hidden: false, // render: (text, record) => { // return ( // {text} @@ -373,16 +374,16 @@ function OrderGroupTable({ formValues }) { pagination={newOrderList.length <= 10 ? false : paginationProps} />} whenFalse={} /> - + 新消息/老邮件 0} whenTrue={} whenFalse={} /> - + 催信 0} @@ -391,7 +392,7 @@ function OrderGroupTable({ formValues }) { pagination={followUpList.length <= 10 ? false : paginationProps} />} whenFalse={} /> - + 余款收付 0} @@ -399,8 +400,8 @@ function OrderGroupTable({ formValues }) { columns={orderColumns} pagination={paymentList.length <= 10 ? false : paginationProps} />} whenFalse={} - /> - + /> + 入境提醒 0} @@ -409,7 +410,7 @@ function OrderGroupTable({ formValues }) { pagination={entryList.length <= 10 ? false : paginationProps} /> } whenFalse={} /> - + } )