import * as React from 'react'; import { PageHeaderFoot, Button, Modal, message, } from 'kts-xui'; import { WrapperDrop } from 'kts-components'; import { Tag, Menu, Space, } from 'kts-components-antd-x4'; import Icon, { InfoCircleOutlined, CheckCircleOutlined, CloseCircleOutlined } from '@ant-design/icons'; // import agent from '../Server'; import moment from 'moment'; import { DigitalAssetVerification as agent } from '../..'; import InvoiceImport from '../SlaveInvoiceList/invoiceImport'; interface IProps { list: [] } const AddBatch = (props: IProps) => { const [visible, setVisible] = React.useState(false); const [tip, setTip] = React.useState(''); const [downloadFilePath, setDownlad] = React.useState(''); const [successNo, setSuccess] = React.useState(0); const [failureNo, setfailure] = React.useState(0); const [errorModal, setModal] = React.useState(false); const handleMenuClick = React.useCallback((e) => { if (e.key === 'create') { setVisible(true); } else if (e.key === 'send') { sendBatch() } }, [props.list]) const sendBatch = React.useCallback(async () => { if (props.list.length > 0) { const res: any = await agent.server.post(`${agent.prefix_path}/web/verifierTask/batch/send`, { includeManyTaskUuid: props.list }).resFs(agent.server.resFs.filter(v => v !== agent.serviceTools.verificationResponse)).end(null); if (res.err) { if (res.err.body?.status.description.indexOf('只有草稿状态的任务才能发送') >= 0) { Modal.confirm({ title:'操作失败!', icon: , content: ( <> 只有任务状态为草稿的任务才可以发送,请重新勾选。 ), }) } else { Modal.confirm({ title:'操作失败!', icon: null, content: ( <> 网络异常,请稍后重试 ), }) } } else { setDownlad(res.res.downloadUrl); setSuccess(res.res.successNo); setfailure(res.res.failureNo); if (res.res.failureNo === res.res.failureNo + res.res.successNo) { setTip('failure') } else if (res.res.successNo === res.res.failureNo + res.res.successNo) { setTip('success') } else { setTip('half') } setModal(true) } }else{ message.error('请勾选发送任务'); } }, [props.list]) const menu = ( 批量创建 批量发送 ) const uploadExcel = async (values) => { const res: any = await agent.server .post(`${agent.prefix_path}/web/verifierTask/import`) .reqFs(agent.server.reqFs.filter(v => v !== agent.serviceTools.addContentType)) .resFs(agent.server.resFs.filter(v => v !== agent.serviceTools.verificationResponse)) .field('fileName', values.name) .attach('file', values, values.name).end(this); if (res.err) { Modal.confirm({ title:'操作失败!', icon: null, content: ( <> 网络异常,请稍后重试 ), }) } return res; } const downloadExcel = async () => { const res: any = await agent.server.post(`${agent.prefix_path}/web/verifierTask/import-template`, {}).reqFs(agent.server.reqFs.filter(v => v !== agent.serviceTools.addContentType)).resFs([]).responseType('blob').end(null);; if (res.err) { return; } else { const blob = res.res.body; let url = URL.createObjectURL(blob); let link = document.createElement('a'); link.style.display = 'none'; link.href = url; link.setAttribute('download', `模板-${moment(new Date()).format('YYYYMMDDHHmmss')}.xls`); link.click(); } } const urlData = { commonUploadCb: uploadExcel, commonDownloadCb: downloadExcel } const onCloseExcel = React.useCallback(() => { setVisible(false); }, []) const onRefresh = React.useCallback(() => { }, []); const handleOk = async () => { if (downloadFilePath.indexOf('http') >= 0 || downloadFilePath.indexOf('//') === 0) { window.open(downloadFilePath); } else { const response: any = await agent.server.post(`${agent.prefix_path}/web/verifiedTask/getFileDownloadUrl`, { fileNameList: [downloadFilePath] }).end(this); const res = response.res[0]; const href = `${res}`; let a = window.document.createElement('a'); a.setAttribute('href', href); a.setAttribute('target', '_blank'); a.setAttribute('download', `下载文件_${moment(new Date()).format('YYYYMMDDHHmmss')}.xls`); a.click(); } } const handleCancel = () => { setModal(false) } const gotoDID = () => { let url = ''; if (window.top) { url = window.top.location.host + agent.didPath window.top.location!.href = '//' + url } else { url = window.location.host + agent.didPath; window!.location!.href = '//' + url } } const tipModal = () => { let info; let title = '已发送'; let icon, download; if (tip === 'success') { icon = ; info = 勾选任务{successNo + failureNo}个,已发送{successNo}个,请稍后查看发送结果。 } else if (tip === 'failure') { download = 下载失败结果 title = '发送失败'; icon = ; info = 勾选任务{successNo + failureNo}个,发送失败{failureNo}个!失败原因:未找到采集方DID。 } else { download = 下载失败结果 title = '发送结果'; icon = ; info = 勾选任务{successNo + failureNo}个,已发送{successNo}个,发送失败{failureNo}个!失败原因:未找到采集方DID。 } return (

{icon} {title}

{info}
{download}
{tip !== 'success' && 前往客商管理 } {tip === 'success' && 确认} 取消
) } return ( <> {visible && } {tipModal()} ) } export default AddBatch;