UploadMoreModal.tsx 3.43 KB
import React, {useEffect, useState} from 'react';
import {Modal, Button, InputNumber, Select} from 'antd';
import { getList } from './api';
import useInitial from "@/hooks/useInitail";
import { useStore } from '../index';

interface Props {
  islock?:boolean,
  setIslock: Function,
  visible: boolean,
  onCancel: () => any,
}
const Option = Select.Option;
export default function Upload(props: Props) {
  const { storages: storageList } = useStore();
  const { visible, onCancel, islock, setIslock } = props;
  const [storageid, setStorageid] = useState<number>();
  const [storageName, setStorageName] = useState<string>();
  const [delay, setDelay] = useState(true);
  const { data: total, setParams } = useInitial(getList, 0, {}, delay);
  const [pagesize, setPagesize] = useState(1000);
  const [list, setList] = useState<number[]>([]);

  async function f(s:number, a: Array<number>) {
    for (let i = 0; i < s; i++) {
        a.push(i+1);
      }
      return a;
  }

  useEffect(() => {
    if (total && pagesize) {
      const sum = Math.ceil(Number(total) / pagesize);
      const arr:Array<number>= [];
      f(sum, arr).then(a => setList(a));
    } else {
      setList([]);
    }
  }, [total, pagesize, storageid]);

  useEffect(() => {
    if (!visible) {
      setStorageid(undefined);
      setList([]);
      setIslock(false);
    }
  }, [visible]);
  
  const handOnChange = (value: number) => {
    const storagename = storageList.find(it => it.id==value);
    setStorageid(value);
    setStorageName(storagename?.storageName);
    setDelay(false);
    setParams({storageId: value}, true);
  };
  
  return (
    <Modal
      maskClosable
      title={islock ? "锁定库存导出" : "库存导出"}
      visible={visible}
      onCancel={onCancel}
      width={800}
      footer={[
        <Button onClick={onCancel}>取消</Button>,
      ]}
    >
      <div style={{display: 'flex', flexDirection: 'row', alignItems: 'center', marginBottom: 20}}>
        <span style={{paddingLeft: 29}}>选择库房:</span>
        <Select
          placeholder="请选择库房"
          value={storageid}
          style={{ width: 250 }}
          onChange={(value: number) => handOnChange(value)}
          showSearch
          optionFilterProp="children"
        >
          {storageList.map(it => (
            <Option key={it.id} value={it.id || -1}>{it.storageName || ''}</Option>
          ))}
        </Select>
      </div>
      <div style={{display: 'flex', flexDirection: 'row', alignItems: 'center', marginBottom: 20}}>
        <span>表格数据条数:</span>
        <InputNumber
          value={pagesize}
          min={1}
          step={1}
          onChange={v => setPagesize(v)}
          style={{ width: 250 }}
        />
      </div>
      <div style={{display: 'flex', flexDirection: 'row', flexWrap: 'wrap'}}>
        {islock ? list.map((it, index) => (
          <a key={index} href={`/api/pms/erp/part/shop/export/lock/stock?storageId=${storageid}&current=${it}&pageSize=${pagesize}`} style={{ marginRight: 20, marginBottom: 10 }} target="_blank" rel="noopener noreferrer">{`${storageName}锁定库存${it}.xlsx`}</a>
        )) :
        list.map((it, index) => (
          <a key={index} href={`/api/pms/erp/part/shop/export/stock?storageId=${storageid}&current=${it}&pageSize=${pagesize}`} style={{marginRight: 20, marginBottom: 10}} target="_blank" rel="noopener noreferrer">{`${storageName}库存${it}.xlsx`}</a>
        ))}
       
      </div>
    </Modal>
  );
}