|  | @@ -7,13 +7,13 @@ import {
 | 
	
		
			
				|  |  |  import { useParams, useRequest } from '@umijs/max';
 | 
	
		
			
				|  |  |  import { Table } from 'antd';
 | 
	
		
			
				|  |  |  import dayjs from 'dayjs';
 | 
	
		
			
				|  |  | -import { useEffect } from 'react';
 | 
	
		
			
				|  |  | +import { useEffect, useRef, useState } from 'react';
 | 
	
		
			
				|  |  |  import { PageType } from '.';
 | 
	
		
			
				|  |  |  const SparePartDetail = () => {
 | 
	
		
			
				|  |  |    const { projectId, type } = useParams();
 | 
	
		
			
				|  |  | -  const titles = ['入库详情', '出库详情', '报废详情', '库存详情'];
 | 
	
		
			
				|  |  | +  const titles = ['入库详情', '出库详情', '报废详情', '库存详情', '基础库存'];
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  const params = {
 | 
	
		
			
				|  |  | +  const defaultParams = {
 | 
	
		
			
				|  |  |      type: Number(type),
 | 
	
		
			
				|  |  |      project_id: Number(projectId),
 | 
	
		
			
				|  |  |      check_result: 0,
 | 
	
	
		
			
				|  | @@ -22,27 +22,15 @@ const SparePartDetail = () => {
 | 
	
		
			
				|  |  |      end_time: '',
 | 
	
		
			
				|  |  |      name: '',
 | 
	
		
			
				|  |  |    };
 | 
	
		
			
				|  |  | -  const paramsExit = {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  const defaultParamsOfExit = {
 | 
	
		
			
				|  |  |      category_id: 0,
 | 
	
		
			
				|  |  |      name: '',
 | 
	
		
			
				|  |  | -    warning_state: 0,
 | 
	
		
			
				|  |  | +    model_number: '',
 | 
	
		
			
				|  |  | +    warning_state: Number(type) === PageType.warning ? 2 : 0,
 | 
	
		
			
				|  |  |      project_id: Number(projectId),
 | 
	
		
			
				|  |  |    };
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  useEffect(() => {
 | 
	
		
			
				|  |  | -    type !== PageType.existing ? run(params) : runExist(paramsExit);
 | 
	
		
			
				|  |  | -  }, [type]);
 | 
	
		
			
				|  |  | -  const { data, run, loading } = useRequest((data) => queryStoreList(data), {
 | 
	
		
			
				|  |  | -    manual: true,
 | 
	
		
			
				|  |  | -  });
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -  const {
 | 
	
		
			
				|  |  | -    data: dataExist,
 | 
	
		
			
				|  |  | -    loading: loadingExist,
 | 
	
		
			
				|  |  | -    run: runExist,
 | 
	
		
			
				|  |  | -  } = useRequest((data) => queryInventoryList(data), {
 | 
	
		
			
				|  |  | -    manual: true,
 | 
	
		
			
				|  |  | -  });
 | 
	
		
			
				|  |  |    const columns = [
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  |        title: '仓储类型',
 | 
	
	
		
			
				|  | @@ -63,6 +51,7 @@ const SparePartDetail = () => {
 | 
	
		
			
				|  |  |        align: 'center',
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  |    ];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |    const columnsIn = [
 | 
	
		
			
				|  |  |      ...columns,
 | 
	
		
			
				|  |  |      {
 | 
	
	
		
			
				|  | @@ -91,6 +80,7 @@ const SparePartDetail = () => {
 | 
	
		
			
				|  |  |        align: 'center',
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  |    ];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |    const columnsOut = [
 | 
	
		
			
				|  |  |      ...columns,
 | 
	
		
			
				|  |  |      {
 | 
	
	
		
			
				|  | @@ -125,6 +115,7 @@ const SparePartDetail = () => {
 | 
	
		
			
				|  |  |        align: 'center',
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  |    ];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |    const columnsScrap = [
 | 
	
		
			
				|  |  |      ...columns,
 | 
	
		
			
				|  |  |      {
 | 
	
	
		
			
				|  | @@ -188,6 +179,7 @@ const SparePartDetail = () => {
 | 
	
		
			
				|  |  |        },
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  |    ];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |    const columnsExit = [
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  |        title: '类型',
 | 
	
	
		
			
				|  | @@ -210,12 +202,14 @@ const SparePartDetail = () => {
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  |        title: '在库',
 | 
	
		
			
				|  |  |        align: 'center',
 | 
	
		
			
				|  |  | -      render: (record) => (
 | 
	
		
			
				|  |  | -        <div>
 | 
	
		
			
				|  |  | -          {record.in_amount - record.out_amount - record.scrap_amount}
 | 
	
		
			
				|  |  | -          {record.unit}
 | 
	
		
			
				|  |  | -        </div>
 | 
	
		
			
				|  |  | -      ),
 | 
	
		
			
				|  |  | +      render: (record) => {
 | 
	
		
			
				|  |  | +        return (
 | 
	
		
			
				|  |  | +          <div>
 | 
	
		
			
				|  |  | +            {record.in_amount - record.out_amount - record.scrap_amount}
 | 
	
		
			
				|  |  | +            {record.unit}
 | 
	
		
			
				|  |  | +          </div>
 | 
	
		
			
				|  |  | +        );
 | 
	
		
			
				|  |  | +      },
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  |      {
 | 
	
		
			
				|  |  |        title: '入库',
 | 
	
	
		
			
				|  | @@ -267,27 +261,237 @@ const SparePartDetail = () => {
 | 
	
		
			
				|  |  |        align: 'center',
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  |    ];
 | 
	
		
			
				|  |  | -  const columnsList = [columnsIn, columnsOut, columnsScrap, columnsExit];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  const columnsBase = [
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      title: '类型',
 | 
	
		
			
				|  |  | +      dataIndex: 'category_name',
 | 
	
		
			
				|  |  | +      key: 'category_name',
 | 
	
		
			
				|  |  | +      align: 'center',
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      title: '名称',
 | 
	
		
			
				|  |  | +      dataIndex: 'name',
 | 
	
		
			
				|  |  | +      key: 'name',
 | 
	
		
			
				|  |  | +      align: 'center',
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      title: '型号',
 | 
	
		
			
				|  |  | +      dataIndex: 'model_number',
 | 
	
		
			
				|  |  | +      key: 'model_number',
 | 
	
		
			
				|  |  | +      align: 'center',
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      title: '在库',
 | 
	
		
			
				|  |  | +      align: 'center',
 | 
	
		
			
				|  |  | +      render: (record) => {
 | 
	
		
			
				|  |  | +        return (
 | 
	
		
			
				|  |  | +          <div>
 | 
	
		
			
				|  |  | +            {record.in_amount - record.out_amount - record.scrap_amount}
 | 
	
		
			
				|  |  | +            {record.unit}
 | 
	
		
			
				|  |  | +          </div>
 | 
	
		
			
				|  |  | +        );
 | 
	
		
			
				|  |  | +      },
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      title: '入库',
 | 
	
		
			
				|  |  | +      align: 'center',
 | 
	
		
			
				|  |  | +      render: (recode) => (
 | 
	
		
			
				|  |  | +        <div>
 | 
	
		
			
				|  |  | +          {recode.in_amount}
 | 
	
		
			
				|  |  | +          {recode.unit}
 | 
	
		
			
				|  |  | +        </div>
 | 
	
		
			
				|  |  | +      ),
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      title: '出库',
 | 
	
		
			
				|  |  | +      align: 'center',
 | 
	
		
			
				|  |  | +      render: (recode) => (
 | 
	
		
			
				|  |  | +        <div>
 | 
	
		
			
				|  |  | +          {recode.out_amount}
 | 
	
		
			
				|  |  | +          {recode.unit}
 | 
	
		
			
				|  |  | +        </div>
 | 
	
		
			
				|  |  | +      ),
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      title: '报废',
 | 
	
		
			
				|  |  | +      align: 'center',
 | 
	
		
			
				|  |  | +      render: (recode) => (
 | 
	
		
			
				|  |  | +        <div>
 | 
	
		
			
				|  |  | +          {recode.scrap_amount}
 | 
	
		
			
				|  |  | +          {recode.unit}
 | 
	
		
			
				|  |  | +        </div>
 | 
	
		
			
				|  |  | +      ),
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      title: '预警状态',
 | 
	
		
			
				|  |  | +      dataIndex: 'warning_state',
 | 
	
		
			
				|  |  | +      align: 'warning_state',
 | 
	
		
			
				|  |  | +      align: 'center',
 | 
	
		
			
				|  |  | +      render: (warn) => {
 | 
	
		
			
				|  |  | +        return warn == 2 ? (
 | 
	
		
			
				|  |  | +          <div style={{ color: 'red' }}>报警</div>
 | 
	
		
			
				|  |  | +        ) : (
 | 
	
		
			
				|  |  | +          <div>正常</div>
 | 
	
		
			
				|  |  | +        );
 | 
	
		
			
				|  |  | +      },
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +  ];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  const columnsList = [
 | 
	
		
			
				|  |  | +    columnsIn,
 | 
	
		
			
				|  |  | +    columnsOut,
 | 
	
		
			
				|  |  | +    columnsScrap,
 | 
	
		
			
				|  |  | +    columnsExit,
 | 
	
		
			
				|  |  | +    columnsBase,
 | 
	
		
			
				|  |  | +  ];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  const [dataSource, setDataSource] = useState([]);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  const [pagination, setPagination] = useState({
 | 
	
		
			
				|  |  | +    current: 1,
 | 
	
		
			
				|  |  | +    total: 0,
 | 
	
		
			
				|  |  | +    pageSize: 20,
 | 
	
		
			
				|  |  | +  });
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  const isLoadAll = useRef(false);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  const bottomAreaOfTable = useRef();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  const { run, loading } = useRequest(
 | 
	
		
			
				|  |  | +    (data) => {
 | 
	
		
			
				|  |  | +      data.page = pagination?.current || defaultParams.currentPage;
 | 
	
		
			
				|  |  | +      data.page_size = pagination?.pageSize || defaultParams.pageSize;
 | 
	
		
			
				|  |  | +      return queryStoreList(data);
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      manual: true,
 | 
	
		
			
				|  |  | +      formatResult: (result) => {
 | 
	
		
			
				|  |  | +        if (pagination.current === 1) {
 | 
	
		
			
				|  |  | +          setDataSource(result?.data);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +          setDataSource([...dataSource, ...result?.data]);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (pagination.current * pagination.pageSize >= result.total) {
 | 
	
		
			
				|  |  | +          isLoadAll.current = true;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 每次请求完成后 current + 1
 | 
	
		
			
				|  |  | +        setPagination({
 | 
	
		
			
				|  |  | +          ...pagination,
 | 
	
		
			
				|  |  | +          total: result?.total || 0,
 | 
	
		
			
				|  |  | +          current: pagination.current + 1,
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +      },
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +  );
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  const { loading: loadingExist, run: runExist } = useRequest(
 | 
	
		
			
				|  |  | +    (data) => {
 | 
	
		
			
				|  |  | +      data.page = pagination?.current || defaultParamsOfExit.currentPage;
 | 
	
		
			
				|  |  | +      data.page_size = pagination?.pageSize || defaultParamsOfExit.pageSize;
 | 
	
		
			
				|  |  | +      return queryInventoryList(data);
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      manual: true,
 | 
	
		
			
				|  |  | +      formatResult: (result) => {
 | 
	
		
			
				|  |  | +        if (pagination.current === 1) {
 | 
	
		
			
				|  |  | +          setDataSource(result?.data);
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +          setDataSource([...dataSource, ...result?.data]);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (pagination.current * pagination.pageSize >= result.total) {
 | 
	
		
			
				|  |  | +          isLoadAll.current = true;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 每次请求完成后 current + 1
 | 
	
		
			
				|  |  | +        setPagination({
 | 
	
		
			
				|  |  | +          ...pagination,
 | 
	
		
			
				|  |  | +          total: result?.total || 0,
 | 
	
		
			
				|  |  | +          current: pagination.current + 1,
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +      },
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +  );
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  useEffect(() => {
 | 
	
		
			
				|  |  | +    Number(type) !== PageType.warning && Number(type) !== PageType.base
 | 
	
		
			
				|  |  | +      ? run(defaultParams)
 | 
	
		
			
				|  |  | +      : runExist(defaultParamsOfExit);
 | 
	
		
			
				|  |  | +  }, [type]);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  const handleScroll = () => {
 | 
	
		
			
				|  |  | +    if (bottomAreaOfTable.current === null) {
 | 
	
		
			
				|  |  | +      return;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    const rect = bottomAreaOfTable.current.getBoundingClientRect();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    console.log();
 | 
	
		
			
				|  |  | +    const isVisible =
 | 
	
		
			
				|  |  | +      rect.top >= 0 &&
 | 
	
		
			
				|  |  | +      rect.left >= 0 &&
 | 
	
		
			
				|  |  | +      rect.bottom <=
 | 
	
		
			
				|  |  | +        (window.innerHeight || document.documentElement.clientHeight) &&
 | 
	
		
			
				|  |  | +      rect.right <= (window.innerWidth || document.documentElement.clientWidth);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    if (isVisible) {
 | 
	
		
			
				|  |  | +      if (isLoadAll.current || loadingExist || loading) {
 | 
	
		
			
				|  |  | +        return;
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      if (Number(type) !== PageType.warning && Number(type) !== PageType.base) {
 | 
	
		
			
				|  |  | +        run(defaultParams);
 | 
	
		
			
				|  |  | +      } else {
 | 
	
		
			
				|  |  | +        runExist(defaultParamsOfExit);
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  };
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  // 监听滚动事件
 | 
	
		
			
				|  |  | +  useEffect(() => {
 | 
	
		
			
				|  |  | +    window.addEventListener('scroll', handleScroll);
 | 
	
		
			
				|  |  | +    return () => {
 | 
	
		
			
				|  |  | +      window.removeEventListener('scroll', handleScroll);
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  | +  }, [loadingExist, loading]);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    return (
 | 
	
		
			
				|  |  |      <PageContent closeable={false}>
 | 
	
		
			
				|  |  |        <PageTitle children={titles[type]} returnable />
 | 
	
		
			
				|  |  | -      {type !== PageType.existing ? (
 | 
	
		
			
				|  |  | -        <Table
 | 
	
		
			
				|  |  | -          loading={loading}
 | 
	
		
			
				|  |  | -          style={{ marginTop: '10px' }}
 | 
	
		
			
				|  |  | -          dataSource={data}
 | 
	
		
			
				|  |  | -          columns={columnsList[type]}
 | 
	
		
			
				|  |  | -          pagination={false}
 | 
	
		
			
				|  |  | -        />
 | 
	
		
			
				|  |  | +      {Number(type) !== PageType.warning && Number(type) !== PageType.base ? (
 | 
	
		
			
				|  |  | +        <>
 | 
	
		
			
				|  |  | +          <Table
 | 
	
		
			
				|  |  | +            loading={loading}
 | 
	
		
			
				|  |  | +            style={{ marginTop: '10px' }}
 | 
	
		
			
				|  |  | +            dataSource={dataSource}
 | 
	
		
			
				|  |  | +            columns={columnsList[type]}
 | 
	
		
			
				|  |  | +            pagination={false}
 | 
	
		
			
				|  |  | +          />
 | 
	
		
			
				|  |  | +          <div
 | 
	
		
			
				|  |  | +            ref={bottomAreaOfTable}
 | 
	
		
			
				|  |  | +            style={{
 | 
	
		
			
				|  |  | +              height: '1px',
 | 
	
		
			
				|  |  | +            }}
 | 
	
		
			
				|  |  | +          />
 | 
	
		
			
				|  |  | +        </>
 | 
	
		
			
				|  |  |        ) : (
 | 
	
		
			
				|  |  | -        <Table
 | 
	
		
			
				|  |  | -          loading={loadingExist}
 | 
	
		
			
				|  |  | -          style={{ marginTop: '10px' }}
 | 
	
		
			
				|  |  | -          dataSource={dataExist}
 | 
	
		
			
				|  |  | -          columns={columnsList[type]}
 | 
	
		
			
				|  |  | -          pagination={false}
 | 
	
		
			
				|  |  | -        />
 | 
	
		
			
				|  |  | +        <>
 | 
	
		
			
				|  |  | +          <Table
 | 
	
		
			
				|  |  | +            loading={loadingExist}
 | 
	
		
			
				|  |  | +            style={{ marginTop: '10px' }}
 | 
	
		
			
				|  |  | +            dataSource={dataSource}
 | 
	
		
			
				|  |  | +            columns={columnsList[type]}
 | 
	
		
			
				|  |  | +            pagination={false}
 | 
	
		
			
				|  |  | +          />
 | 
	
		
			
				|  |  | +          <div
 | 
	
		
			
				|  |  | +            ref={bottomAreaOfTable}
 | 
	
		
			
				|  |  | +            style={{
 | 
	
		
			
				|  |  | +              height: '1px',
 | 
	
		
			
				|  |  | +            }}
 | 
	
		
			
				|  |  | +          />
 | 
	
		
			
				|  |  | +        </>
 | 
	
		
			
				|  |  |        )}
 | 
	
		
			
				|  |  |      </PageContent>
 | 
	
		
			
				|  |  |    );
 |