import { iAuditHistoryState, iAuditor, iLatestAuditorState } from '@/types/safe' import { iAccountGroupItem, iUserInfo } from '@/types/setting' import { auditConsts } from '@/utils/common/constStatus' import { getUserGroup } from '@/utils/common/user' import { formatDate } from '@/utils/util' import { Input, Popover } from 'antd' import QueueAnim from 'rc-queue-anim' import React, { ChangeEvent, useEffect, useState } from 'react' import { ExpandButton, ZhButton } from '../Button' import SvgIcon from '../SvgIcon' import './index.scss' interface iGroupItem extends iAccountGroupItem { onSelect: (item: iUserInfo) => void } export const GroupItem: React.FC = props => { const { onSelect } = props const [ visible, setVisible ] = useState(true) const changeVisible = () => { setVisible(!visible) } return props.children.length ? (
setVisible(!visible)}> {props.value}
{visible ? props.children.map((account: iUserInfo) => { return (
onSelect(account)}>
{account.name} {account.position}
{account.mobile}
) }) : null}
) : null } interface iAuditContentProps { onSelect: (type: string, item: iUserInfo) => void onDelete: (id: string, progress: string) => void latest: iLatestAuditorState auditors: iAuditor[] auditHistory: iAuditHistoryState[][] status: number uName: string } const Index: React.FC = props => { const { onSelect, auditors, onDelete, status, auditHistory } = props const [ visible, setVisible ] = useState({ check: false, reCheck: false }) const showPopover = (type: string) => { setVisible({ ...visible, [type]: true }) } const [ searchValue, setSearchValue ] = useState('') const [ groups, setGroups ] = useState>([]) useEffect(() => { if (visible.check || visible.reCheck) { initGroupList() } }, [ visible.check, visible.reCheck ]) const initGroupList = async (serach?: string) => { const data = await getUserGroup(serach) setGroups(data) } const handleVisibleChange = (type: string, isShow: boolean) => { setVisible({ ...visible, [type]: isShow }) } const search = (value: string) => { if (value != searchValue) { setSearchValue(value) initGroupList(value) } } const change = (e: ChangeEvent) => { e.persist() const target = e.target as HTMLTextAreaElement if (!target.value) { initGroupList() } } const itemSelectHandler = (type: string, item: iUserInfo) => { onSelect(type, item) setVisible({ ...visible, [type]: false }) } const renderAuditorSelectItem = (type = 'check') => { return (
    {type === 'check' ? auditors .filter(item => item.progress === '0') .map((item, idx) => { return (
  • {idx + 1} {item.name} {item.position}

    {item.company}
    onDelete(item.audit_id, '0')}> 移除
  • ) }) : auditors .filter(item => item.progress === '2') .map((item, idx) => { return (
  • {idx + 1} {item.name} {item.position}

    {item.company}
    onDelete(item.audit_id, '2')}> 移除
  • ) })}
) } const renderStatusIcon = (status: number, isEnd: boolean) => { let bgColor: string = '' let iconType: string = '' switch (status) { case 0: bgColor = 'pi-bg-green' iconType = 'xxh-check' break case 1: bgColor = 'pi-bg-yellow' iconType = 'xxh-reply' break case 2: bgColor = 'pi-bg-red' iconType = 'xxh-minus' break default: break } if (isEnd) { iconType = 'xxh-caret-down1' } return
{iconType ? : null}
} const renderStatusEle = (status: number, progress: string) => { let text = '' let textClass = 'pi-green' if (progress === '0') { switch (status) { case 0: text = '上报审批' textClass = 'pi-green' break case 1: text = '审批退回' textClass = 'pi-yellow' break case 2: text = '关闭' textClass = 'pi-red' break default: break } } else if (progress === '1' || progress === '3') { switch (status) { case 0: text = '审批通过' textClass = 'pi-green' break case 1: text = '审批退回' textClass = 'pi-yellow' break case 2: text = '关闭' textClass = 'pi-red' break default: break } } else if (progress === '2') { switch (status) { case 0: text = '整改完成' textClass = 'pi-green' break case 1: text = '审批退回' textClass = 'pi-yellow' break case 2: text = '关闭' textClass = 'pi-red' break default: break } } return { text, textClass } } const renderLeftStatus = (status: number) => { let text = '' let textClass = '' switch (status) { case 1: text = '进行中' textClass = 'pi-yellow' break case 2: text = '完成' textClass = 'pi-green' break case 3: text = '关闭' textClass = 'pi-red' break default: break } return { text, textClass } } const renderLeftAuditors = (status: number) => { // 整改人所需信息 const len = auditors.filter(item => item.progress === '0').length return ( 检查人 {auditors[0]?.name} {auditors[0]?.position} {status !== auditConsts.uncheck ? ( 1 ? 2 : 0).textClass}>{renderLeftStatus(auditors.length > 1 ? 2 : 0).text} ) : null} {auditors .filter(item => item.progress === '0') .map((item, idx) => { return idx === 0 ? ( item.progress === '0').length} className="pi-text-center"> 审批 {item.name} {item.position} {status !== auditConsts.uncheck ? ( {renderLeftStatus(item.status).text} ) : null} ) : ( {item.name} {item.position} {status !== auditConsts.uncheck ? ( {renderLeftStatus(item.status).text} ) : null} ) })} 整改人 {status ? ( auditors.find(item => item.progress === '1') ? ( <> {auditors.find(item => item.progress === '1')?.name} {auditors.find(item => item.progress === '1')?.position} ) : ( 由 {auditors.filter(item => item.progress === '0')[len - 1]?.name} 指派 ) ) : ( {auditors.filter(item => item.progress === '0').length ? auditors.filter(item => item.progress === '0')[len - 1]?.name : '最后一个审批人'} 指派 )} {status !== auditConsts.uncheck ? ( item.progress === '1')?.status || 0).textClass}> {renderLeftStatus(auditors.find(item => item.progress === '1')?.status || 0).text} ) : null} {auditors .filter(item => item.progress === '2') .map((item, idx) => { return idx === 0 ? ( item.progress === '2').length} className="pi-text-center"> 复查 {item.name} {item.position} {status !== auditConsts.uncheck ? ( {renderLeftStatus(item.status).text} ) : null} ) : ( {item.name} {item.position} {status !== auditConsts.uncheck ? ( {renderLeftStatus(item.status).text} ) : null} ) })} ) } const renderHistory = () => { return ( <> {auditHistory?.map((item, index) => { return (
    {item?.map((auditor, idx) => (
  • {renderStatusIcon(auditor.status, idx === item.length - 1)}
    {auditor.name} {renderStatusEle(auditor.status, auditor.progress).text}
    {auditor.position}
    {auditor.opinion ? (
    {auditor.opinion}
    ) : null}
  • ))}
) })} ) } return ( {!status ? ( <> ) : ( )}
审批流程
{renderLeftAuditors(status)}
change(e)}>} content={groups.map(item => ( itemSelectHandler('check', item)}> ))} overlayClassName="popover-card" trigger="click" visible={visible.check} onVisibleChange={visible => handleVisibleChange('check', visible)} placement="bottomRight"> showPopover('check')}> 添加审批流程
审批流程
{renderAuditorSelectItem('check')}
整改流程
  • 整改人由最后一位审批人指派
change(e)}>} content={groups.map(item => ( itemSelectHandler('reCheck', item)}> ))} overlayClassName="popover-card" trigger="click" visible={visible.reCheck} onVisibleChange={visible => handleVisibleChange('reCheck', visible)} placement="bottomRight"> showPopover('reCheck')}> 添加审批流程
复查流程
{renderAuditorSelectItem('reCheck')}
{renderLeftAuditors(status)}
{renderHistory()}
) } export default Index