import React, { useState, useEffect } from 'react'; import {Table, Button, Spin, Space, Modal, Form, Upload, Image, notification} from 'antd'; import TextArea from "antd/es/input/TextArea"; import {getCustomerRetPage, saveCustomerRet} from "../../api/statistical"; import {serverUrl} from "../../api/axios"; type NotificationPlacement = 'top' | 'bottom' | 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight'; type NotificationType = 'success' | 'info' | 'warning' | 'error'; interface CustomerRetentionProps { customer: any; } interface Enterprise { key: string; uploadTime: string; description: string; fileUid: string; } interface FormData { num: number; page: number; } interface FileRes { fileId: string; fileName: string; } const CustomerRetention: React.FC = ({ customer }) => { // if (!customer) { // // @ts-ignore // const { history } = this.props; // history.push({ // pathname: '/customer' // }); // return (
); // } if (!customer) { customer = { customerId: 0, customerName: 'asda' } } const [data, setData] = useState([]); const [loading, setLoading] = useState(false); const [query, setQuery] = useState(null); const [total, setTotal] = useState(0); const [fileList, setFileList] = useState([]); const [fileUrl, setFileUrl] = useState(null); const [fileRes, setFileRes] = useState(null); const [form] = Form.useForm(); // Simulate data fetching on component mount useEffect(() => { const query = {page: 1, num: 20}; setQuery(query); getListApi({}, query.page, query.num) }, []); const columns = [ { title: '序号', dataIndex: 'key', render: (text: string, record: any, index: number) => index + 1 }, { title: '说明描述', dataIndex: 'description', key: 'description', }, { title: '上传时间', dataIndex: 'uploadTime', key: 'uploadTime', }, { title: '附件', dataIndex: 'file', key: 'file', sorter: true, render: (text: any, record: { fileUid: string; }) => ( showModal2(record.fileUid)}>服务声明扫描图片文件链接 ), }, ]; const [isModalOpen, setIsModalOpen] = useState(false); const showModal = () => { setIsModalOpen(true); }; const handleOk = () => { setLoading(true); if (fileList.length == 0) { openNotification('top', '请上传文件', 'info'); return; } var formData = { customerId: customer.customerId, fileId: fileRes?.fileId, fileName: fileRes?.fileName, description: form.getFieldValue('description') } saveCustomerRet(formData).then(res => { openNotification('top', '保存成功', 'success'); const query = {page: 1, num: 20}; setQuery(query); getListApi({}, query.page, query.num) setFileList([]); // 清空文件列表 form.resetFields(['description']); // 重置description字段 setIsModalOpen(false); }).catch(() => { }) }; const handleCancel = () => { setFileList([]); // 清空文件列表 form.resetFields(['description']); // 重置description字段 setIsModalOpen(false); }; const [isModalOpen2, setIsModalOpen2] = useState(false); const showModal2 = (fileUid: string) => { console.log(fileUid) setFileUrl('./ex/file/download?fileName=' + fileUid); setIsModalOpen2(true); }; const handleOk2 = () => { debugger const url = serverUrl + fileUrl; const link = document.createElement('a'); link.href = url; // link.download = 'file.png'; link.click(); setFileUrl(null); setIsModalOpen2(false); }; const handleCancel2 = () => { setFileUrl(null); setIsModalOpen2(false); }; // 多少每页 const selectChange = (page: number, num: number) => { const query = { page, num } setQuery(query); getListApi({}, query.page, query.num) } // 条数切换 const changePage = (current: number, pageSize?: number) => { debugger const query = { page: current, num: pageSize || 20 } setTimeout(() => { setQuery(query); getListApi({}, query.page, query.num) }, 0) } // 列表接口 const getListApi = (formData: object, page: number, num: number) => { setLoading(true); var formObj = JSON.parse(JSON.stringify(formData)); formObj.customerId = customer.customerId; getCustomerRetPage(formObj, page, num).then(res => { setData(res.data.records); setTotal(res.data.total); setLoading(false); }).catch(() => { }) } const clickUpload = () => { const uploadButton = document.querySelector('.ant-upload-drag-container') as HTMLDivElement; if (uploadButton) { uploadButton.click(); } } const [api, contextHolder] = notification.useNotification(); const openNotification = (placement: NotificationPlacement, msg: string, type: NotificationType) => { api[type]({ message: '提示', description: msg, placement, }); return false; }; const beforeUpload = (file: File) => { }; const handleChange = (info: any) => { var file = info.file; // 限制文件类型 const isImage = file.type === 'image/jpeg' || file.type === 'image/png'; if (!isImage) { openNotification('top', '只支持上传JPG或PNG格式的文件','info'); return; } setFileList(info.fileList); }; // 自定义字段,包含 fileType const customRequest = async (options: any) => { const { onSuccess, onError, file } = options; const formData = new FormData(); formData.append('file', file); formData.append('fileType', 'CUSTOMER_RETENTION'); try { const response = await fetch('/ex/file/upload', { method: 'POST', body: formData, }); if (response.ok) { const res = await response.json(); setFileRes({ fileId: res.data.id, fileName: res.data.name }) onSuccess?.({}, file); } else { throw new Error('上传失败'); } } catch (error) { onError?.(error); } }; return (
{contextHolder}
{customer.customerName}
{loading ? ( ) : ( `共 ${total} 条`, onShowSizeChange: selectChange, onChange: changePage }} /> )}
*上传格式为jpg、png文件

点击上方"选择文件"或将文件拖拽到此区域