diff --git a/src/stores/OrderStore.js b/src/stores/OrderStore.js new file mode 100644 index 0000000..fd8c83f --- /dev/null +++ b/src/stores/OrderStore.js @@ -0,0 +1,27 @@ +import { create } from 'zustand' +import { devtools } from 'zustand/middleware' +import { fetchJSON, postJSON } from '@/utils/request' + +const API_HOST = 'https://p9axztuwd7x8a7.mycht.cn/whatsapp_callback'; + +const useOrderStore = create((set, get) => ({ + + orderDetail: {}, + + customerDetail: {}, + + lastQuotation: {}, + + fetchOrderDetail: async (colisn) => { + const json = await fetchJSON(`${API_HOST}/getorderinfo`, { colisn }) + if (json.errcode === 0 && json.result.length > 0) { + set(() => ({ + orderDetail: json.result[0], + customerDetail: json.result[0].contact[0], + lastQuotation: json.result[0].quotes.length > 0 ? json.result[0].quotes[0] : {}, + })) + } + } +})) + +export default useOrderStore \ No newline at end of file diff --git a/src/views/Conversations/Components/CustomerProfile.jsx b/src/views/Conversations/Components/CustomerProfile.jsx index 689b64c..69ac45c 100644 --- a/src/views/Conversations/Components/CustomerProfile.jsx +++ b/src/views/Conversations/Components/CustomerProfile.jsx @@ -1,53 +1,40 @@ -import { Card, Flex, Select, Typography, Radio, Button, Table } from 'antd'; -import { useAuthContext } from '@/stores/AuthContext.js'; -// import { useConversationState } from '@/stores/ConversationContext'; +import { useEffect } from 'react' import { useLocation, useParams } from 'react-router-dom' -import { UserOutlined, EditOutlined, EllipsisOutlined, SmileOutlined, SyncOutlined, PhoneOutlined, MailOutlined, WhatsAppOutlined, SmileTwoTone } from '@ant-design/icons'; +import { Card, Flex, Select, Typography, Radio, Button, Table } from 'antd' +import { useAuthContext } from '@/stores/AuthContext.js' +import { UserOutlined, LinkOutlined, EllipsisOutlined, SmileOutlined, SyncOutlined, PhoneOutlined, MailOutlined, WhatsAppOutlined, SmileTwoTone } from '@ant-design/icons' -import CreatePayment from './CreatePayment'; -import QuotesHistory from './QuotesHistory'; - -const orderTags = [ - { value: 'potential', label: '潜力' }, - { value: 'important', label: '重点' }, - { label: '休眠', value: 'snooze' }, -]; - -const orderStatus = [ - { value: 'pending', label: '报价中' }, - // { value: 'in-progress', label: '处理中' }, - { value: 'lost', label: '丢失' }, - { value: 'later', label: '以后联系' }, -]; - -const { Meta } = Card; +import CreatePayment from './CreatePayment' +import QuotesHistory from './QuotesHistory' +import useOrderStore from '@/stores/OrderStore' const CustomerProfile = (() => { let { state } = useLocation() - console.info(state) - console.log(useParams()); - const { order_sn: colisn } = useParams(); - console.log('invoke customer profile+++++++++++++++++++++++++++++++++++++++++++++', colisn); - // const { customerOrderProfile: orderInfo } = useConversationState(); - const { loginUser: currentUser } = useAuthContext(); - const { quotes, contact, last_contact, ...order } = {}; // orderInfo; + const { order_sn: order_sn } = useParams() + const { orderDetail, customerDetail, lastQuotation, fetchOrderDetail } = useOrderStore() + const { loginUser: currentUser } = useAuthContext() + + useEffect(() => { + fetchOrderDetail(order_sn) + }, []) return (