import { Badge, Descriptions } from 'kts-components-antd-x4';
import React from 'react';
import agent from '../../Server';
import { Table, Pagination, Button, PageHeaderFoot, Radio, AutoTableContainer } from 'kts-xui';
interface TaxCreditInfo{ 
    evalDepartment: string;
    grade: string;
    idNumber: string;
    name: string;
    type: string;
    year:string;
} 
interface IMeta {
    total?: number;
    pageSize?: number;
    pageNum?: number
}
export default function App (props: {id: number}) {   
    const [pageMeta, setMeta] = React.useState<IMeta>({ pageNum: 1, pageSize: 10 });
    const [list, setList] = React.useState<TaxCreditInfo[]>();
    React.useEffect(()=>{
        if(props.id){
            (async () => {
                const res: any = await agent.post('/web/verifierparty/risk/query-taxcredit', {id: props.id, pageNum: pageMeta.pageNum, pageSize: pageMeta.pageSize}, null);
                if (res.err) {
                    return;
                } else {  
                    setList(res.res.items.map((item, index)=>{
                        return {
                            ...item,
                            index: (res.res.pageMeta.pageNum - 1) * res.res.pageMeta.pageSize + index + 1
                        } 
                    }
                    ));  
                    setMeta(res.res.pageMeta);
                }
            })()
        }
    }, [props.id, pageMeta.pageNum, pageMeta.pageSize])

    const onPageChange = React.useCallback((pageNum, pageSize) => {
        const data = {
            ...pageMeta,
            pageNum,
            pageSize
        }; 
        setMeta(data);
    }, []);

    const columns = [
        {
            title: '序号',
            dataIndex: 'index',
            width: 80,
            ellipsis: true, 
        }, {
            title: '评价年度',
            dataIndex: 'year',
            width: 120,
            ellipsis: true,
        }, {
            title: '纳税人信用级别',
            dataIndex: 'grade',
            width: 100,
        }, {
            title: '类型',
            dataIndex: 'type',
            width: 100,
        }, {
            title: '纳税人识别号',
            dataIndex: 'idNumber',
            width: 120,
        }, {
            title: '评价单位',
            dataIndex: 'evalDepartment',
            width: 220,
        }];

    return <div style={{ height: 'calc(100vh - 109px)', display: 'flex', flexDirection: 'column', overflow: 'auto'}}>
            <AutoTableContainer style={{ flex: 1, padding: '0 20px', background: '#F4F4F4' }} >
                <Table
                    className='fixheight'
                    bordered={true}
                    dataSource={list}
                    columns={columns as any}
                    scroll={{ x: '1500', y: 'max-content' }}
                    pagination={false}
                /> 
            </AutoTableContainer>
            {pageMeta && <Pagination onChange={onPageChange} showTotal={(total, range) => `第 ${range[0]}-${range[1]} 条,  共有 ${total} 条`} style={{ padding: '16px 0', flex: 'none', background: 'white', textAlign: 'center' }} total={pageMeta.total} pageSize={pageMeta.pageSize} current={pageMeta.pageNum} showSizeChanger={true} />}
    </div>
}; 