import AuditContent from '@/components/AuditContent' import { ZhAuditBackButton, ZhCloseButton, ZhSubmitButton, ZhUploadButton } from '@/components/Button' import DatePicker from '@/components/DatePicker' import Header from '@/components/Header' import Slot from '@/components/Header/slot' import OssUploadModal from '@/components/OssUpload' import SvgIcon from '@/components/SvgIcon' import { userStore } from '@/store/mobx' import { iDetailState } from '@/types/auditDetail' import { iFile } from '@/types/file' import { iAuditor } from '@/types/safe' import { iUserInfo } from '@/types/setting' import { apiDelFile, apiGetFileList, apiSaveFileInfo } from '@/utils/common/api' import { auditProgress } from '@/utils/common/constStatus' import consts from '@/utils/consts' import { dayjsFormat } from '@/utils/util' import { Button, Input, message, Pagination, Tooltip } from 'antd' import locale from 'antd/es/date-picker/locale/zh_CN' import dayjs from 'dayjs' import React, { useEffect, useState, useMemo } from 'react' import { RouteComponentProps } from 'react-router' import { apiGetSafeDetail, apiResfulSafeAudit } from './api' import AuditModal from './components/Modal' import styles from './index.module.scss' const { TextArea } = Input interface iModalObj { ossModal: boolean auditModal: boolean auditType: string curPage: number } const Detail: React.FC = props => { const { saveId = '' } = props.location.state as any const [ visible, setVisible ] = useState({ ossModal: false, auditModal: false, auditType: '', curPage: 1 }) const [ detail, setDetail ] = useState({ auditName: '', uid: '', auditors: [], bidsectionId: '', code: '', createTime: new Date().toDateString(), demand: '', file: { fileList: [], total: 0 }, id: '', inspection: '', inspectionDetail: '', position: '', status: 0, checkOrder: { // 整改单 name: '', status: 0, opinion: '', create_time: new Date().toDateString() }, auditHistory: [], rectifiedInfo: [], latestAuditor: { audit_id: '', audit_order: 0, bidsection_id: '', data_id: '', data_type: 0, id: '', progress: '', project_id: '', status: 0 }, times: 0 }) const isEdited = useMemo(() => { return !!detail.status }, [ detail.status ]) useEffect(() => { initData() }, [ saveId ]) const initData = async () => { const { code = -1, data = {} } = await apiGetSafeDetail(saveId) if (code === consts.RET_CODE.SUCCESS) { setDetail({ ...detail, ...data }) } if (!userStore.groupList.length) { userStore.getGroupList() } } const onCreate = async (fileList: iFile[]) => { const { code = -1 } = await apiSaveFileInfo(fileList, consts.DATA_TYPE.SAFE, detail.id) if (code === consts.RET_CODE.SUCCESS) { const newFiles = detail.file.fileList.concat( fileList.map(file => { return { ...file, accountName: userStore.userInfo.name } }) ) setDetail({ ...detail, file: { ...detail.file, total: newFiles.length } }) await fileListChange(visible.curPage) } } const onOssModalShow = (show: boolean) => setVisible({ ...visible, ossModal: show }) const fileListChange = async (pageNo: number = 1, pageSize: number = 10) => { const { code = -1, data, total } = await apiGetFileList(consts.DATA_TYPE.SAFE, detail.id, pageNo, pageSize) if (code === consts.RET_CODE.SUCCESS) { setVisible({ ...visible, curPage: pageNo, ossModal: false }) setDetail({ ...detail, file: { ...detail.file, fileList: data, total } }) } } const delFile = async (id: string, isLast: boolean) => { const { code = -1 } = await apiDelFile(id) if (code === consts.RET_CODE.SUCCESS) { console.log(visible.curPage - 1) await fileListChange(isLast ? visible.curPage - 1 : visible.curPage) isLast && (setVisible({ ...visible, curPage: visible.curPage - 1 })) } } const addAuditor = (type: string, user: iUserInfo) => { if (detail.auditors.find(item => item.progress === (type === 'check' ? '0' : '2') && item.audit_id === user.id)) { return message.error('该审批组下已存在该审批人,请勿重复添加!') } if (type === "check") { const newAuditors = detail.auditors const len = detail.auditors.filter((item: iAuditor) => item.progress === "0").length newAuditors.push({ id: '', mobile:'', audit_id: user.id, audit_order: len + 1,position: user.position, progress: "0", name: user.name,accountGroup: user.accountGroup, company: user.company, status: 0 }) setDetail({ ...detail, auditors: newAuditors }) } else { const newAuditors = detail.auditors const len = detail.auditors.filter((item: iAuditor) => item.progress === "2").length newAuditors.push({ id: '', audit_id: user.id, mobile:'', audit_order: len + 1,position: user.position, progress: "2", name: user.name, accountGroup: user.accountGroup, company: user.company, status: 0 }) setDetail({ ...detail, auditors: newAuditors }) } } const delAuditor = (id: string, progress: string) => { const newAuditors = detail.auditors.filter(item => item.progress !== progress) const auditor = detail.auditors.find(item => item.progress === progress && item.audit_id !== id) if (auditor) { newAuditors.push(auditor) } setDetail({ ...detail, auditors: newAuditors }) } const btnClick = (type: string) => { setVisible({ ...visible, auditType: type, auditModal: true }) } const onModalConfirm = (values?: object) => { let payload: any = { safe_id: detail.id, bidsection_id: detail.bidsectionId, ...values } if (visible.auditType === 'start') { payload.auditors = detail.auditors.filter(item => item.progress === '0').map(item => item.audit_id) payload.reAuditors = detail.auditors.filter(item => item.progress === '2').map(item => item.audit_id) payload.times = detail.times if (!payload.auditors.length || !payload.reAuditors.length) { return message.error('审批人或复查人不能为空!') } } if (visible.auditType === 'delete') { payload = { id: detail.id } } if (visible.auditType === 'pass' || visible.auditType === 'back') { payload.id = detail.latestAuditor.id if (detail.latestAuditor.progress === '1') { if (!detail.checkOrder.opinion) { return message.error("请填写整改单!") } else { payload.rectifiedInfo = detail.checkOrder.opinion } } } if (visible.auditType === 'close') { payload.id = detail.latestAuditor.id } apiResful(visible.auditType, payload) } const apiResful = async (type: string, payload: any) => { const { code } = await apiResfulSafeAudit(type, payload) if (code === consts.RET_CODE.SUCCESS) { setVisible({ ...visible, auditModal: false }) if (type === 'delete') { props.history.goBack() } else { initData() } } } const renderHeaderBtn = (status: number) => { if (!detail.latestAuditor.audit_id && userStore.userInfo.id !== detail.uid) return null if (detail.latestAuditor.audit_id && userStore.userInfo.id !== detail.latestAuditor.audit_id) return null if (!status) { return (
btnClick('delete')}>删除巡检 btnClick('start')}>提交审批
) } else if(status === auditProgress.checking || status === auditProgress.checkNo) { return (
btnClick('back')}>审批退回 btnClick('pass')}>审批通过
) } else if (status === auditProgress.checked) { return (
btnClick('back')}>审批退回 btnClick('pass')}>整改完成
) } } return (
{renderHeaderBtn(detail.status)}

{detail.code}

安全巡检单
检查项目 { isEdited ? {detail.inspection} : }
现场检查情况 { isEdited ? {detail.inspectionDetail} : }
处理要求及措施 { isEdited ? {detail.demand} : }
检查日期 { isEdited ? {detail.createTime && dayjsFormat(detail.createTime, 'YYYY-MM-DD')} : setDetail({ ...detail, createTime: value?.format() })}> }
质检员 {detail.auditName}
{ detail.status === auditProgress.checked && detail.latestAuditor.progress === '1'?
整改单
整改情况
整改日期 setDetail({ ...detail, checkOrder: { ...detail.checkOrder, create_time: value?.format() } })}>
整改人 {detail.auditors.find(item => item.progress === '1')?.name}
: detail.rectifiedInfo.map(item => (
整改单
整改情况 {item.opinion}
整改日期 {dayjsFormat(item.create_time, 'YYYY-MM-DD')}
整改人 {item.name}
)) } {detail.file.fileList?.map((file, idx) => ( ))} {detail.file.total > consts.PAGE_SIZE ? ( ) : null}
附件 上传者 上传时间 操作
} onClick={() => setVisible({ ...visible, ossModal: true })}> 上传附件
{idx + 1} {file.filename} {file.accountName} {dayjsFormat(file.createTime)}
fileListChange(page, pageSize)}>
setVisible({ ...visible, ossModal: false })} onCreate={onCreate} onShow={onOssModalShow}> setVisible({ ...visible, auditModal: false })} onCreate={onModalConfirm} auditors={detail.auditors} curAuditor={detail.latestAuditor} >
) } export default Detail