PartTable.tsx 3.39 KB
import {Table} from 'antd';
import React, {useEffect, useState} from 'react';
import useInitial from "@/hooks/useInitail";
import {getList, ListVO} from "@/pages/pms/partPlan/PlanPool/api";
import DetailModal from './DetailModal';
import {useStore} from "@/pages/pms/partPlan/PlanPool";

const { Column } = Table;
interface Props {
  showAnalyse?: boolean
  // eslint-disable-next-line react/no-unused-prop-types
  type?: number, // 类型1区域库2库房3车系4车型5配件
  // eslint-disable-next-line react/no-unused-prop-types
  detailType?: number, // 类型1区域库2库房3车系4车型5配件
  // eslint-disable-next-line react/no-unused-prop-types
  id?: number, // 上一个列表ID
}
export default function Index(props: Props = {}) {
  const { dfParams, key, partTypeData } = useStore();
  const {showAnalyse=true} = props;
  const { data: parts, setParams } = useInitial(getList, [], {...dfParams, ...props});
  const [visible, setVisible] = useState(false);
  // 类型1区域库2库房3车系4车型5配件
  const [detailType, setDetailType] = useState<number>();
  const [id, setId] = useState<number>();

  useEffect(() => {
    if (key == props.type) {
      setParams(dfParams, true);
    }
  }, [dfParams, key]);

  return (
    <div>
      <Table rowKey={(v: ListVO) => `${v.id}`} scroll={{y: 500, x: 2000}} dataSource={parts || []} pagination={false}>
        <Column title="配件编码" dataIndex="code" fixed="left" />
        <Column title="配件名称" dataIndex="name" />
        <Column title="来源类型" dataIndex="typeName" />
        <Column title="配件类型" dataIndex="partType" render={t => partTypeData.find(i => i.value == t)?.label} />
        <Column title="采购单价" dataIndex="price" />
        <Column title="采购数量" dataIndex="cnt" />
        <Column title="采购规格" dataIndex="unit" />
        <Column title="动态库销比" dataIndex="ratio" render={t => (t || 0).toFixed(2)} />
        <Column title="库存数量" dataIndex="stockCnt" render={t => (t || 0).toFixed(2)} />
        <Column title="滚动90天月均出库数量" dataIndex="outCnt" render={t => (t || 0).toFixed(2)} />
        {showAnalyse && (
          <>
            <Column
              title="区域库分析"
              render={(t, _: ListVO) => (
                <a onClick={() => {
                  setVisible(true);
                  setId(_.id);
                  setDetailType(1);
                }}
                >
                  查看
                </a>
              )}
            />
            <Column
              title="库房分析"
              render={(t, _: ListVO) => (
                <a onClick={() => {
                  setVisible(true);
                  setId(_.id);
                  setDetailType(2);
                }}
                >
                  查看
                </a>
              )}
            />
            <Column
              title="车系分析"
              render={(t, _: ListVO) => (
                <a onClick={() => {
                  setVisible(true);
                  setId(_.id);
                  setDetailType(3);
                }}
                >
                  查看
                </a>
              )}
            />
          </>
        )}
      </Table>
      <DetailModal
        visible={visible}
        onCancel={() => setVisible(false)}
        id={id}
        detailType={detailType}
        type={5}
      />
    </div>
  );
}