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) => {
return fetchJSON(`${API_HOST}/query_guest_order`, { opisn: userId, whatsappid: '', email: email })
fetchHistoryOrder: (userId, email, whatsappid='') => {
return fetchJSON(`${API_HOST}/query_guest_order`, { opisn: userId, whatsappid, email: email })
.then(json => {
if (json.errcode === 0) {
return json.result

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

@ -24,6 +24,7 @@ const CustomerProfile = () => {
const currentOrder = useConversationStore(state => state.currentConversation?.coli_sn || "");
const currentConversationID = useConversationStore(state => state.currentConversation?.sn || "");
const channels = useConversationStore(state => state.currentConversation?.channels);
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 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
]);
const [chatOrder, setChatOrder] = useState(currentOrder);
const orderLabelOptions = copy(OrderLabelDefaultOptions);
orderLabelOptions.unshift({ value: 0, label: "未设置", disabled: true });
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(() => {
setChatOrder(currentOrder)
if (currentOrder) {
setLoading(true);
fetchOrderDetail(currentOrder)
.then(result => {
setOrderNumber(result.orderDetail.order_no)
fetchHistoryOrder(result.orderDetail.order_no, result.customerDetail.email)
.then(orderList => {
const mapOrderList = orderList.map(o => {
return { value: o.coli_sn, label: o.coli_id }
})
setOrderList(mapOrderList)
})
setChatOrder(result.orderDetail.order_no)
const queryEmail = result.customerDetail.email || channels?.email || '';
const queryWA = channels?.whatsapp_phone_number || ''
getHistoryOrder(queryEmail, queryWA)
})
.finally(() => setLoading(false))
.catch(reason => {
@ -120,9 +134,13 @@ const CustomerProfile = () => {
width: "100%",
}}
variant="borderless"
value={currentOrderNumber}
options={orderList}
/>}
value={chatOrder}
options={orderList}
onSelect={(x) => {
setChatOrder(x);
updateCurrentConversation({ coli_sn: x });
}}
/>}
actions={[
<Select
key={"orderlabel"}

Loading…
Cancel
Save