/* eslint-disable eqeqeq */ import { AddReply } from '@/components/DragModal/formdoms'; import ReplyCard from '@/components/Reply/ReplyCard'; import { doFetch, getFetch } from '@/utils/doFetch'; import { LoadingOutlined, SendOutlined } from '@ant-design/icons'; import { useModel, useParams } from '@umijs/max'; import { useRequest } from 'ahooks'; import { Avatar, Drawer, message, Select, Tooltip } from 'antd'; import { useEffect, useRef, useState } from 'react'; function Reply({ drawer, userList, children, extra, full }) { const { id } = useParams(); const [doreply, setdoreply] = useState(false); const { initialState: { currentUser, curitem }, setInitialState, } = useModel('@@initialState'); const formRef = useRef(); const [submitdata, setsubmitdata] = useState({ project_id: parseInt(id), item_id: null, bereply_userid: drawer?.userInfo?.id, other: [], }); useEffect(() => { setsubmitdata((s) => ({ ...s, project_id: parseInt(id), bereply_userid: drawer?.userInfo?.id, other: drawer?.open ? doreply?.other ?? [] : [], })); }, [drawer?.userInfo?.id, id, doreply?.other, drawer?.open]); const allmsg = useRequest( async () => { if (!drawer.open) return; let res = await getFetch({ url: '/webtool/v1/allmsg', params: { item_id: drawer?.id ?? 0 } }); return res?.data; }, { refreshDeps: [drawer?.id, drawer?.open, curitem], }, ); const { run, loading } = useRequest( (params) => { return doFetch(params); }, { manual: true, debounceWait: 600, onSuccess: (res) => { allmsg?.refresh(); if (res?.code === 0) { formRef.current.setFieldsValue({ reply: '' }); setdoreply(false); setsubmitdata(s=>({ ...s, other:[] })) } }, }, ); return (
{ setdoreply(false); }} >
{children}
{allmsg?.data?.map((it) => { return ( { setdoreply(val); }} /> ); })}
{drawer?.val === 'reply' && currentUser?.user_name && (
{ if (doreply === false) { setdoreply(drawer?.userInfo); } }} >
{currentUser?.head_url ? null : currentUser.user_name?.charAt(0)}
回复 {doreply?.user_name ?? '-'} @
{ e.stopPropagation(); if (loading || !doreply) { setdoreply(drawer?.userInfo); return; } const reply = formRef.current.getFieldFormatValue('reply'); const div = document.createElement('div'); div.innerHTML = reply; if (div.innerText === '' || div.innerText.replace(/\s*/g, '') === '') { message.warning('请至少回复一句话!'); return; } let extra = {}; if (doreply?.curid) { extra = { msg_id: doreply?.curid }; } // 设置提及人员 const other = submitdata?.other?.toString() ?? ''; if (doreply?.type == 'edit2') { run({ url: '/webtool/v1/msg/' + doreply?.curitemid, params: { ...submitdata, ...extra, other, item_id: drawer?.id, reply, }, method: 'PUT', }); return; } if (doreply?.type == 'edit1') { run({ url: '/webtool/v1/msg/' + doreply?.curid, params: { ...submitdata, other, item_id: drawer?.id, reply, }, method: 'PUT', }); return; } run({ url: '/webtool/v1/msg', params: { ...submitdata, ...extra, other, item_id: drawer?.id, reply, bereply_userid: doreply?.id, }, }); }} > 回复   {loading ? ( ) : ( )}
)}
); } export default Reply;