历史记录: 搜索顾问

dev/chat
Lei OT 2 years ago
parent df9a5c917d
commit db948b5a4a

@ -1,3 +1,10 @@
import { fetchJSON } from '@/utils/request'; import { fetchJSON } from '@/utils/request';
import { API_HOST } from '@/config'; import { API_HOST } from '@/config';
/**
* 顾问列表
*/
export const fetchSalesAgent = async (q) => {
const { errcode, result } = await fetchJSON(`https://p9axztuwd7x8a7.mycht.cn/service-Analyse2/GetOperatorInfo`, { q });
return errcode !== 0 ? [] : result.map((ele) => ({ ...ele, label: ele.cn_name, value: ele.op_id }));
};

@ -0,0 +1,46 @@
import React, { useMemo, useRef, useState } from 'react';
import { Select, Spin } from 'antd';
import { debounce } from '@/utils/utils';
function DebounceSelect({ fetchOptions, debounceTimeout = 800, ...props }) {
const [fetching, setFetching] = useState(false);
const [options, setOptions] = useState([]);
const fetchRef = useRef(0);
const debounceFetcher = useMemo(() => {
const loadOptions = (value) => {
fetchRef.current += 1;
const fetchId = fetchRef.current;
setOptions([]);
setFetching(true);
fetchOptions(value).then((newOptions) => {
if (fetchId !== fetchRef.current) {
// for fetch callback order
return;
}
setOptions(newOptions);
setFetching(false);
});
};
return debounce(loadOptions, debounceTimeout);
}, [fetchOptions, debounceTimeout]);
return (
<Select
labelInValue
filterOption={false}
showSearch
allowClear
{...props}
onSearch={debounceFetcher}
notFoundContent={fetching ? <Spin size='small' /> : null}
optionFilterProp='label'
>
{options.map((d) => (
<Select.Option key={d.value} title={d.label}>
{d.label}
</Select.Option>
))}
</Select>
);
}
export default DebounceSelect;

@ -311,6 +311,20 @@ export const stringToColour = (str) => {
return color; return color;
}; };
export const debounce = (func, wait, immediate) => {
var timeout;
return function () {
var context = this,
args = arguments;
clearTimeout(timeout);
if (immediate && !timeout) func.apply(context, args);
timeout = setTimeout(function () {
timeout = null;
if (!immediate) func.apply(context, args);
}, wait);
};
}
export const olog = (text, ...args) => { export const olog = (text, ...args) => {
console.log( console.log(
`%c ${text} `, `%c ${text} `,

@ -8,62 +8,15 @@ import { isEmpty } from '@/utils/utils';
import useFormStore from '@/stores/FormStore'; import useFormStore from '@/stores/FormStore';
import { useShallow } from 'zustand/react/shallow'; import { useShallow } from 'zustand/react/shallow';
import { fetchSalesAgent } from '@/actions/CommonActions';
// import SearchInput from '@/components/SearchInput2';
import SearchInput from '@/components/SearchInput';
const { Sider, Content, Header, Footer } = Layout; const { Sider, Content, Header, Footer } = Layout;
const { Search } = Input; const { Search } = Input;
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
// https://media-xsp2-1.cdn.whatsapp.net/v/t61.24694-24/424735646_380563021285029_2962758854250800176_n.jpg?ccb=11-4&oh=01_AdTogiVdUE-ToI9uH-VQKTTLyDbP7bocXUQe1OETOeCgcg&oe=65F7C6AB&_nc_sid=e6ed6c&_nc_cat=104 // https://media-xsp2-1.cdn.whatsapp.net/v/t61.24694-24/424735646_380563021285029_2962758854250800176_n.jpg?ccb=11-4&oh=01_AdTogiVdUE-ToI9uH-VQKTTLyDbP7bocXUQe1OETOeCgcg&oe=65F7C6AB&_nc_sid=e6ed6c&_nc_cat=104
const data = [
{
title: 'Ann',
avatarUrl: 'https://api.dicebear.com/7.x/miniavs/svg?seed=0',
msgTime: '03-04 13:45:29',
content:
'Hi, this is Ann from China Highlights travel and it is my pleasure to help your Beijing trip. I have sent you an email with the general idea about you trip. Please check it and if any question or new idea just let me know. We are specailized in customizing tour and I would like to work with you to create a tour itinerary that you like. Look forward to your reply.',
},
{
title: 'David Azhari',
avatarUrl: 'https://api.dicebear.com/7.x/miniavs/svg?seed=2',
msgTime: '03-04 16:33:08',
content: 'Hi! I just replied to your email saying that I have a few questions and notes',
},
{
title: 'David Azhari',
avatarUrl: 'https://api.dicebear.com/7.x/miniavs/svg?seed=2',
msgTime: '03-04 16:33:34',
content: 'So first, is it possible for you guys to write a PU Invitation letter for visas or no?',
},
{
title: 'Ann',
avatarUrl: 'https://api.dicebear.com/7.x/miniavs/svg?seed=0',
msgTime: '03-04 16:33:41',
content: 'you prefer we discuss here or go on by mail ?',
},
{
title: 'David Azhari',
avatarUrl: 'https://api.dicebear.com/7.x/miniavs/svg?seed=2',
msgTime: '03-04 16:34:03',
content: 'I prefer by mail if its ok with you',
},
{
title: 'Ann',
avatarUrl: 'https://api.dicebear.com/7.x/miniavs/svg?seed=0',
msgTime: '03-04 16:34:28',
content: 'both is okay ,I am typing mail to you now lol and receive your message here.',
},
{
title: 'David Azhari',
avatarUrl: 'https://api.dicebear.com/7.x/miniavs/svg?seed=2',
msgTime: '03-05 02:56:37',
content: 'Ok thank you so much',
},
{
title: 'Ann',
avatarUrl: 'https://api.dicebear.com/7.x/miniavs/svg?seed=0',
msgTime: '03-04 16:44:03',
content: 'you are welcome I have sent the mail to you ,please check.it is my pleasure to assist you with your tour.',
},
];
// eslint-disable-next-line react/display-name // eslint-disable-next-line react/display-name
const SearchForm = memo(function ({ initialValues, onSubmit }) { const SearchForm = memo(function ({ initialValues, onSubmit }) {
@ -80,51 +33,8 @@ const SearchForm = memo(function ({ initialValues, onSubmit }) {
style={{ style={{
maxWidth: 'none', maxWidth: 'none',
}}> }}>
<Form.Item label='顾问' name='travel' style={{ width: '200px' }}> <Form.Item label='顾问' name='agent' style={{ width: '200px' }}>
<Select <SearchInput placeholder='搜索顾问' fetchOptions={fetchSalesAgent} />
showSearch
placeholder='请选择'
optionFilterProp='children'
filterOption={(input, option) => (option?.label ?? '').toLowerCase().includes(input.toLowerCase())}
options={[
{
value: 'null',
label: '未知',
},
{
value: '354',
label: '宁艳',
},
{
value: '487',
label: '杨新玲',
},
{
value: '495',
label: '黄雪荣',
},
{
value: '骆梅玉',
label: '骆梅玉',
},
{
value: '586',
label: '秦宇尘',
},
{
value: '606',
label: '莫梦瑶',
},
{
value: '603',
label: '秦雯萱',
},
{
value: '601',
label: '王露加',
},
]}
/>
</Form.Item> </Form.Item>
<Form.Item label='客人' name='orderLabel' style={{ width: '200px' }}> <Form.Item label='客人' name='orderLabel' style={{ width: '200px' }}>
<Select <Select
@ -206,7 +116,7 @@ function ChatHistory() {
const getConversationsList = async () => { const getConversationsList = async () => {
setLoading(true); setLoading(true);
setChatItemMessages([]); setChatItemMessages([]);
const data = await fetchConversationsList({ opisn: formValues.travel }); const data = await fetchConversationsList({ opisn: formValues.agent?.value || -1 });
setLoading(false); setLoading(false);
setConversationsList(data); setConversationsList(data);
if (data.length === 1) { if (data.length === 1) {
@ -241,7 +151,7 @@ function ChatHistory() {
const parts = str.split(/(https?:\/\/[^\s]+|\p{Emoji_Presentation})/gmu).filter((s) => s !== ''); const parts = str.split(/(https?:\/\/[^\s]+|\p{Emoji_Presentation})/gmu).filter((s) => s !== '');
const links = str.match(/https?:\/\/[\S]+/gi) || []; const links = str.match(/https?:\/\/[\S]+/gi) || [];
const emojis = str.match(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g) || []; const emojis = str.match(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g) || [];
const extraClass = isEmpty(emojis) ? '' : 'text-base leading-5 emoji-text'; const extraClass = isEmpty(emojis) ? '' : '';
const objArr = parts.reduce((prev, curr, index) => { const objArr = parts.reduce((prev, curr, index) => {
if (links.includes(curr)) { if (links.includes(curr)) {
prev.push({ type: 'link', key: curr }); prev.push({ type: 'link', key: curr });
@ -253,16 +163,15 @@ function ChatHistory() {
return prev; return prev;
}, []); }, []);
return ( return (
<span className={extraClass}> <span className={`text-base leading-5 emoji-text ${extraClass}`}>
{(objArr || []).map((part, index) => { {(objArr || []).map((part, index) => {
if (part.type === 'link') { if (part.type === 'link') {
return ( return (
<a href={part.key} target='_blank' key={`${part.key}${index}`} rel='noreferrer' className='text-sm'> <a href={part.key} target='_blank' key={`${part.key}${index}`} rel='noreferrer' className='text-base'>
{part.key} {part.key}
</a> </a>
); );
} else { } else {
// if (part.type === 'emoji')
return part.key; return part.key;
} }
})} })}
@ -292,7 +201,7 @@ function ChatHistory() {
}; };
// eslint-disable-next-line react/display-name // eslint-disable-next-line react/display-name
const MessageBoxWithRef = forwardRef((props, ref) => ( const MessageBoxWithRef = forwardRef((props, ref) => (
<li ref={ref} key={props.key}> <li ref={ref} >
<MessageBox {...props} /> <MessageBox {...props} />
</li> </li>
)); ));

Loading…
Cancel
Save