feat: 切换客人订单: 更新订单和消息窗口

dev/emitter
Lei OT 10 months ago
parent bda5abe8aa
commit 6a3d32dfda

@ -116,8 +116,8 @@ export const useOrderStore = create(devtools((set, get) => ({
}) })
}, },
fetchHistoryOrder: (userId, email) => { fetchHistoryOrder: (userId, email, whatsappid='') => {
return fetchJSON(`${API_HOST}/query_guest_order`, { opisn: userId, whatsappid: '', email: email }) return fetchJSON(`${API_HOST}/query_guest_order`, { opisn: userId, whatsappid, email: email })
.then(json => { .then(json => {
if (json.errcode === 0) { if (json.errcode === 0) {
return json.result return json.result

@ -28,8 +28,7 @@ const MessagesWrapper = ({ updateRead = true, forceGetMessages }) => {
const refreshTotalNotify = useConversationStore(useShallow((state) => state.refreshTotalNotify)); const refreshTotalNotify = useConversationStore(useShallow((state) => state.refreshTotalNotify));
const [orderDetail] = useOrderStore(state => [state.orderDetail]); const [orderDetail, ] = useOrderStore(state => [state.orderDetail, ]);
const isVisible = useVisibilityState(); const isVisible = useVisibilityState();
@ -42,7 +41,15 @@ const MessagesWrapper = ({ updateRead = true, forceGetMessages }) => {
} }
setShouldScrollBottom(true); setShouldScrollBottom(true);
return () => {}; return () => {};
}, [currentConversation.sn, orderDetail.coli_sn]); }, [currentConversation.sn]);
useEffect(() => {
if (currentConversation.sn) {
getFirstPageMessages({...currentConversation, });
}
setShouldScrollBottom(true);
return () => {};
}, [currentConversation.coli_sn]);
useEffect(() => { useEffect(() => {
setLongList(activeMessages); setLongList(activeMessages);
@ -62,14 +69,19 @@ const MessagesWrapper = ({ updateRead = true, forceGetMessages }) => {
}, [activeMessages.length, isVisible]); }, [activeMessages.length, isVisible]);
let refreshing = false;
const getFirstPageMessages = async (item) => { const getFirstPageMessages = async (item) => {
if (refreshing !== false) {
return false;
}
refreshing = true;
setMsgLoading(true); setMsgLoading(true);
const data = await fetchMessages({ const data = await fetchMessages({
conversationid: item.sn, conversationid: item.sn,
opisn: forceGetMessages ? currentConversation.opi_sn || '' : userId, opisn: forceGetMessages ? currentConversation.opi_sn || '' : userId,
whatsappid: item.whatsapp_phone_number, whatsappid: item.whatsapp_phone_number,
lasttime: '', lasttime: '',
coli_sn: isEmpty(currentConversation.coli_sn) ? '' : (orderDetail.coli_sn || ''), // todo: coli_sn: currentConversation.coli_sn || '',
}) })
const thisLastTime = data.length > 0 ? data[0].msgtime : ''; // orgmsgtime const thisLastTime = data.length > 0 ? data[0].msgtime : ''; // orgmsgtime
const loadNextPage = !(data.length === 0 || data.length < MESSAGE_PAGE_SIZE); const loadNextPage = !(data.length === 0 || data.length < MESSAGE_PAGE_SIZE);
@ -77,6 +89,7 @@ const MessagesWrapper = ({ updateRead = true, forceGetMessages }) => {
setMsgLoading(false); setMsgLoading(false);
receivedMessageList(item.sn, data); receivedMessageList(item.sn, data);
refreshing = false;
}; };
const getMoreMessages = async () => { const getMoreMessages = async () => {
@ -87,7 +100,7 @@ const MessagesWrapper = ({ updateRead = true, forceGetMessages }) => {
opisn: currentConversation.opi_sn, opisn: currentConversation.opi_sn,
whatsappid: currentConversation.whatsapp_phone_number, whatsappid: currentConversation.whatsapp_phone_number,
lasttime: currentConversation?.lasttime || '', lasttime: currentConversation?.lasttime || '',
coli_sn: isEmpty(currentConversation.coli_sn) ? '' : (orderDetail.coli_sn || ''), coli_sn: currentConversation.coli_sn || '',
}) })
setLongListLoading(false); setLongListLoading(false);
setLongList(prevValue => data.concat(prevValue)); setLongList(prevValue => data.concat(prevValue));

@ -24,6 +24,7 @@ const CustomerProfile = () => {
const currentOrder = useConversationStore(state => state.currentConversation?.coli_sn || ""); const currentOrder = useConversationStore(state => state.currentConversation?.coli_sn || "");
const currentConversationID = useConversationStore(state => state.currentConversation?.sn || ""); const currentConversationID = useConversationStore(state => state.currentConversation?.sn || "");
const channels = useConversationStore(state => state.currentConversation?.channels);
const [updateCurrentConversation] = useConversationStore(state => [state.updateCurrentConversation]); const [updateCurrentConversation] = useConversationStore(state => [state.updateCurrentConversation]);
const [emailMsg, setEmailMsg, detailPopupOpen, setDetailOpen, openDetail] = useConversationStore(state => [state.emailMsg, state.setEmailMsg, state.detailPopupOpen, state.setDetailOpen, state.openDetail]); const [emailMsg, setEmailMsg, detailPopupOpen, setDetailOpen, openDetail] = useConversationStore(state => [state.emailMsg, state.setEmailMsg, state.detailPopupOpen, state.setDetailOpen, state.openDetail]);
const loginUser = useAuthStore(state => state.loginUser); const loginUser = useAuthStore(state => state.loginUser);
@ -33,24 +34,37 @@ const CustomerProfile = () => {
s.orderDetail, s.customerDetail, s.lastQuotation, s.quotationList, s.fetchOrderDetail, s.setOrderPropValue, s.appendOrderComment, s.fetchOtherEmail, s.otherEmailList, s.fetchHistoryOrder s.orderDetail, s.customerDetail, s.lastQuotation, s.quotationList, s.fetchOrderDetail, s.setOrderPropValue, s.appendOrderComment, s.fetchOtherEmail, s.otherEmailList, s.fetchHistoryOrder
]); ]);
const [chatOrder, setChatOrder] = useState(currentOrder);
const orderLabelOptions = copy(OrderLabelDefaultOptions); const orderLabelOptions = copy(OrderLabelDefaultOptions);
orderLabelOptions.unshift({ value: 0, label: "未设置", disabled: true }); orderLabelOptions.unshift({ value: 0, label: "未设置", disabled: true });
const orderStatusOptions = copy(OrderStatusDefaultOptions); const orderStatusOptions = copy(OrderStatusDefaultOptions);
const getHistoryOrder = (email, whatsappid='') => {
return fetchHistoryOrder(loginUser.userId, email, whatsappid)
.then(orderList => {
const mapOrderList = orderList.map(o => {
return { value: o.coli_sn, label: o.coli_id }
})
setOrderList(mapOrderList)
if (!isEmpty(orderList)) {
setChatOrder(currentOrder)
}
})
}
useEffect(() => { useEffect(() => {
setChatOrder(currentOrder)
if (currentOrder) { if (currentOrder) {
setLoading(true); setLoading(true);
fetchOrderDetail(currentOrder) fetchOrderDetail(currentOrder)
.then(result => { .then(result => {
setOrderNumber(result.orderDetail.order_no) setOrderNumber(result.orderDetail.order_no)
fetchHistoryOrder(result.orderDetail.order_no, result.customerDetail.email) setChatOrder(result.orderDetail.order_no)
.then(orderList => { const queryEmail = result.customerDetail.email || channels?.email || '';
const mapOrderList = orderList.map(o => { const queryWA = channels?.whatsapp_phone_number || ''
return { value: o.coli_sn, label: o.coli_id } getHistoryOrder(queryEmail, queryWA)
})
setOrderList(mapOrderList)
})
}) })
.finally(() => setLoading(false)) .finally(() => setLoading(false))
.catch(reason => { .catch(reason => {
@ -120,9 +134,13 @@ const CustomerProfile = () => {
width: "100%", width: "100%",
}} }}
variant="borderless" variant="borderless"
value={currentOrderNumber} value={chatOrder}
options={orderList} options={orderList}
/>} onSelect={(x) => {
setChatOrder(x);
updateCurrentConversation({ coli_sn: x });
}}
/>}
actions={[ actions={[
<Select <Select
key={"orderlabel"} key={"orderlabel"}

Loading…
Cancel
Save