import React from 'react';
import { Table } from 'antd';
import {useStore} from '../index';
import {PoolItem} from '../api';

const {Column} = Table;
export default function Index() {
  const {data, loading, setListItem, setAnalysisVisible} = useStore();

  const analysis = (r:PoolItem, dt:number) => {
    setListItem({type: 3, detailType: dt, _item: r});
    setAnalysisVisible(true);
  };

  return (
    <>
      <Table
        dataSource={data}
        loading={loading}
        pagination={false}
        rowKey={r => `${r.id}`}
        scroll={{y: 500}}
      >
        <Column title="车系" dataIndex="name" />
        <Column title="动态库销比" dataIndex="ratio" render={t => (t ? t.toFixed(2) : '--')} />
        <Column title="调出池配件品种" dataIndex="transferKind" />
        <Column title="调出池配件数量" dataIndex="transferCnt" />
        <Column title="调出库房分析" render={(r) => <a onClick={() => analysis(r, 6)}>查看</a>} />
        <Column title="调入库房分析" render={(r) => <a onClick={() => analysis(r, 7)}>查看</a>} />
        <Column title="配件分析" render={(r) => <a onClick={() => analysis(r, 5)}>查看</a>} />
      </Table>
    </>
  );
}