import { contractStore } from '@/store/mobx' import { apiDelFile, apiGetFileList } from '@/utils/common/api' import consts from '@/utils/consts' import { dayjsFormat } from '@/utils/util' import { Popconfirm } from 'antd' import Table, { ColumnsType } from 'antd/lib/table' import { observer } from 'mobx-react' import React, { useEffect, useState } from 'react' interface iFileState { id: string filename: string filepath: string accountName: string createTime: string } const File: React.FC<{ type: 'income' | 'expenditure' }> = ({ type }) => { const [ data, setData ] = useState>([]) const [ total, setTotal ] = useState(0) const [ id, setId ] = useState('') const [ pagination, setPagination ] = useState({ pageNo: 1, pageSize: 7 }) useEffect(() => { if (contractStore.contract.id) { if (contractStore.contract.id !== id) { setId(contractStore.contract.id) initData() } else if (contractStore.shouldUpdate && contractStore.shouldUpdate === '3') { initData(pagination.pageNo, pagination.pageSize) } contractStore.shouldUpdate && (contractStore.changeUpdate('')) } }, [ contractStore.contract.id, contractStore.shouldUpdate ]) const initData = async (pageNo: number = 1, pageSize: number = 7) => { setPagination({ ...pagination, pageNo, pageSize }) const { code = -1, data = [], total = 0 } = await apiGetFileList(type === 'income' ? consts.DATA_TYPE.CONTRACT_RETURN : consts.DATA_TYPE.CONTRACT_PAID, contractStore.contract.id, pageNo, pageSize) if (code === consts.RET_CODE.SUCCESS) { setData(data) setTotal(total) } } const deleteFile = async (id: string) => { const { code = -1 } = await apiDelFile(id) if (code === consts.RET_CODE.SUCCESS) { const newData = data.filter((file: iFileState) => file.id !== id) setData(newData) } } const columns: ColumnsType = [ { dataIndex: 'sort', // eslint-disable-next-line react/display-name render: (_: any, record: iFileState, idx: number) => {idx + 1}, width: 5 }, { title: '名称', dataIndex: 'filename', // eslint-disable-next-line react/display-name render: (text: string, record: iFileState) => {text}, width: 50 }, { title: '上传者', dataIndex: 'accountName', width: 10 }, { title: '上传时间', dataIndex: 'createTime', // eslint-disable-next-line react/display-name render: (time: string) => {dayjsFormat(time, 'YYYY-MM-DD')}, width: 20 }, { title: '操作', dataIndex: 'opreate', // eslint-disable-next-line react/display-name render: (_: string, record: iFileState) => { return
下载 deleteFile(record.id)}> 删除
}, width: 15 } ] return ( record.id} pagination={{ hideOnSinglePage: true, size: "small", pageSize: 7, onChange: (page, pageSize) => initData(page, pageSize), total }} /> ) } export default observer(File)