import React, { useMemo } from 'react';
import styles from './BusinessInfo.less';
import StandardTable from '@/components/StandardTable';
const BusinessInfo = ({ data }) => {
    const mockData = {
        // 合同信息
        currentContract: 'CONTRACT-2023-001',
        contractPeriod: '2023-01-01 至 2023-12-31',
        paymentTerms: '月结30天',
        contractAmount: 18000000,

        // 财务信息
        creditLimit: 2000000,
        taxRegistrationNo: '91110000100012345X',
        bankAccount: '0200 0045 0910 1234 567',
        bankName: '中国工商银行北京分行'
    }
    const safe = (v) => (v ?? '-')
    const currency = (n) => {
        if (typeof n === 'number') return `¥${n.toLocaleString()}`;
        if (typeof n === 'string') return n;
        return '-';
    }

    // 近期交易记录 - 列定义与数据（参考 second_oil_components/BasicInfo.less 的表格样式）
    const columns = useMemo(() => ([
        { title: '订单号', dataIndex: 'orderId', key: 'orderId', width: 160 },
        { title: '日期', dataIndex: 'date', key: 'date', width: 200 },
        { title: '产品', dataIndex: 'product', key: 'product', width: 140 },
        { title: '数量（吨）', dataIndex: 'quantity', key: 'quantity', width: 120 },
        { title: '金额（元）', dataIndex: 'amount', key: 'amount', width: 140, render: (val) => val.toLocaleString() },
    ]), []);

    const tableData = [
        { key: '1', orderId: 'ORDER-2023-1025', date: '2025-11-15 20:02:14', product: '92#汽油', quantity: 500, amount: 3850000 },
        { key: '2', orderId: 'ORDER-2023-1012', date: '2025-11-15 18:22:58', product: '92#汽油', quantity: 200, amount: 2050000 },
        { key: '3', orderId: 'ORDER-2023-1005', date: '2025-11-15 15:38:26', product: '95#汽油', quantity: 300, amount: 1620000 },
        { key: '4', orderId: 'ORDER-2023-1021', date: '2025-11-10 10:42:08', product: '92#汽油', quantity: 500, amount: 3850000 },
    ];

    return (
        <div className={styles.container}>
            <div className={styles.section}>
                <div className={styles.sectionTitle}>合同信息</div>
                <div className={styles.grid}>
                    <div className={styles.item}><span className={styles.label}>当前合同：</span><span className={styles.value}>{safe(mockData?.currentContract)}</span></div>
                    <div className={styles.item}><span className={styles.label}>合同有效期：</span><span className={styles.value}>{safe(mockData?.contractPeriod)}</span></div>
                    <div className={styles.item}><span className={styles.label}>付款条款：</span><span className={styles.value}>{safe(mockData?.paymentTerms)}</span></div>

                    <div className={styles.item}><span className={styles.label}>合同金额：</span><span className={styles.value}>{currency(mockData?.contractAmount)}</span></div>
                </div>
            </div>

            <div className={styles.section}>
                <div className={styles.sectionTitle}>财务信息</div>
                <div className={styles.grid}>
                    <div className={styles.item}><span className={styles.label}>信用额度：</span><span className={styles.value}>{currency(mockData?.creditLimit)}</span></div>
                    <div className={styles.item}><span className={styles.label}>税务登记号：</span><span className={styles.value}>{safe(mockData?.taxRegistrationNo)}</span></div>
                    <div className={styles.item}><span className={styles.label}>开户银行：</span><span className={styles.value}>{safe(mockData?.bankName)}</span></div>

                    <div className={styles.item}><span className={styles.label}>银行账户：</span><span className={styles.value}>{safe(mockData?.bankAccount)}</span></div>
                </div>
            </div>

            <div className={styles.section}>
                <div className={styles.sectionTitle}>近期交易记录</div>
                <div className={styles.tableWrapper}>
                    <StandardTable
                        rowKey="key"
                        columns={columns}
                        data={{
                            list: tableData,
                            pagination: {
                                total: tableData.length,
                                pageSize: 10,
                                current: 1,
                                showTotal: (total) => `共 ${total} 条`,
                            },
                        }}
                    />
                </div>
            </div>
        </div>
    );
};

export default BusinessInfo;


