Blame view

src/pages/pms/partPlan/PlanShipping/components/UploadExcel.tsx 5.74 KB
e3946366   baiyun   配件设置、采购供应商、月度任务联调
1
2
3
  import React, { useEffect, useState } from 'react';
  import { InboxOutlined } from '@ant-design/icons';
  import { Button, Modal, Upload, message } from 'antd';
26e052d0   baiyun   配件发运
4
  import ConfirmDetailModal from '@/pages/pms/partPlan/PlanShipping/components/ConfirmDetailModal';
2d451216   baiyun   配件计划联调
5
6
7
8
  import usePagination from '@/hooks/usePagination';
  import { getStoragePage } from '@/pages/pms/storage/StorageManage/api';
  import { getPageListApi, Item } from '@/pages/pms/partPlan/PlanSupplier/api';
  import SelectRow from '@/pages/pms/comonents/SelectRow';
55a01e03   by1642146903   发运调整
9
  import useInitail from "@/hooks/useInitail";
c0ee8807   jiangwei   发运单导入参数调整为结算门店
10
  import { getShopApi } from '@/pages/pms/storage/partShop/api';
e3946366   baiyun   配件设置、采购供应商、月度任务联调
11
12
13
14
  
  const Dragger = Upload.Dragger;
  
  interface Props {
38e3fe2f   baiyun   配件计划
15
    getList: () => any
38e3fe2f   baiyun   配件计划
16
    importVisible: boolean
2d451216   baiyun   配件计划联调
17
    brands: any[]
38e3fe2f   baiyun   配件计划
18
    setImportVisible: (v: boolean) => any
e3946366   baiyun   配件设置、采购供应商、月度任务联调
19
20
  }
  
2d451216   baiyun   配件计划联调
21
22
  export default function UploadExcel({ getList, importVisible, setImportVisible, brands }: Props) {
    const [delay, setDelay] = useState(true);
e3946366   baiyun   配件设置、采购供应商、月度任务联调
23
    const [fileList, setFileList] = useState<any[]>([]);
2d451216   baiyun   配件计划联调
24
    const { list: storages } = usePagination<PartStorageSpace.PageVO>(getStoragePage, {pageSize: 1000});
a32f89b3   jiangwei   发运单导入供应商查询参数改动
25
    const { list: suppliers, setParams, innerParams } = usePagination<Item>(getPageListApi, { pageSize: 500, supplierType: 10 }, {delay});
c0ee8807   jiangwei   发运单导入参数调整为结算门店
26
27
    const { data: shops } = useInitail<PmsStoragePartShop.Option[], {}>(getShopApi, [], {});
    const [param, setParam] = useState({ brandId: null, storageId: null, supplierId: null, settleShopId: null});
26e052d0   baiyun   配件发运
28
    const [visibleDetail, setVisibleDetail] = useState(false);
e3946366   baiyun   配件设置、采购供应商、月度任务联调
29
30
31
    const [uploadResult, setUploadResult] = useState<any>();
  
    useEffect(() => {
38e3fe2f   baiyun   配件计划
32
      if (!importVisible) {
e3946366   baiyun   配件设置、采购供应商、月度任务联调
33
        setUploadResult(null);
81339a3c   jiangwei   客户订件进度增加筛选条件
34
35
        setParam({ brandId: null, storageId: null, supplierId: null, settleShopId: null });
        setFileList([]);
e3946366   baiyun   配件设置、采购供应商、月度任务联调
36
      }
38e3fe2f   baiyun   配件计划
37
    }, [importVisible]);
e3946366   baiyun   配件设置、采购供应商、月度任务联调
38
  
d7be03e2   jiangwei   发运导入弹框无法关闭问题修复
39
40
41
42
43
44
    useEffect(() => {
      if (!visibleDetail) {
        setImportVisible(false);
      }
    }, [visibleDetail]);
  
e3946366   baiyun   配件设置、采购供应商、月度任务联调
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    function beforeUpload(file: any) {
      const isLt2M = file.size / 1024 / 1024 < 20;
      if (!isLt2M) {
        message.error('文件不能超过20MB!');
      }
      return isLt2M;
    }
  
    function handleChange(info: any) {
      const { file: { status, response }, fileList } = info;
      if (status !== 'uploading' && response) {
        const { success, result, data } = response;
        if (status === 'done' && success) {
          message.success(`${info.file.name} 上传成功`);
          // 调用上传接口
          setUploadResult(data);
38e3fe2f   baiyun   配件计划
61
          getList();
e3946366   baiyun   配件设置、采购供应商、月度任务联调
62
63
64
65
66
67
68
69
70
71
72
        } else if (response && !success) {
          message.error(`${info.file.name} 上传失败: ${result}`);
        }
      }
      setFileList(fileList.splice(-1));
    }
    const uploadProps = {
      accept: '.xls, .xlsx',
      name: 'file',
      fileList,
      multiple: false,
2d451216   baiyun   配件计划联调
73
      data: param,
e3946366   baiyun   配件设置、采购供应商、月度任务联调
74
75
76
77
78
79
      action: `/api/pms/app/part/shipping/save`,
      onChange: (file: any) => handleChange(file),
      beforeUpload: (info: any) => beforeUpload(info)
    };
    return (
      <Modal
38e3fe2f   baiyun   配件计划
80
        visible={importVisible}
e3946366   baiyun   配件设置、采购供应商、月度任务联调
81
82
        maskClosable={false}
        title={uploadResult ? '导入结果' : '文件导入'}
38e3fe2f   baiyun   配件计划
83
        onCancel={() => { setImportVisible(false); setUploadResult(null); }}
e3946366   baiyun   配件设置、采购供应商、月度任务联调
84
        footer={
38e3fe2f   baiyun   配件计划
85
          <Button onClick={() => { setImportVisible(false); setUploadResult(null); }}>取消</Button>
e3946366   baiyun   配件设置、采购供应商、月度任务联调
86
87
        }
      >
2d451216   baiyun   配件计划联调
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
        <div style={{ display: 'flex', flexDirection: 'column'}}>
          <SelectRow
            title="品牌"
            value={param.brandId}
            data={brands}
            id="id"
            name="name"
            onChange={brandId => {
              setParam({...param, brandId});
              setParams({ ...innerParams, brandId, current: 1 }, true);
              setDelay(false);
            }}
          />
          <SelectRow
            title="供应商"
            value={param.supplierId}
            data={suppliers}
            id="supplierId"
            name="supplierName"
            onChange={supplierId => setParam({ ...param, supplierId })}
          />
          <SelectRow
            title="库房"
            value={param.storageId}
            data={storages}
            id="id"
            name="storageName"
            onChange={storageId => setParam({ ...param, storageId })}
          />
55a01e03   by1642146903   发运调整
117
          <SelectRow
c0ee8807   jiangwei   发运单导入参数调整为结算门店
118
119
120
            title="结算门店"
            value={param.settleShopId}
            data={shops}
55a01e03   by1642146903   发运调整
121
122
            id="id"
            name="name"
c0ee8807   jiangwei   发运单导入参数调整为结算门店
123
            onChange={settleShopId => setParam({ ...param, settleShopId })}
55a01e03   by1642146903   发运调整
124
          />
2d451216   baiyun   配件计划联调
125
126
        </div>
        {!uploadResult ? !!param.brandId && !!param.storageId && !!param.supplierId && (
e3946366   baiyun   配件设置、采购供应商、月度任务联调
127
128
129
130
131
132
133
134
135
          <div>
            <Dragger {...uploadProps}>
              <p className="ant-upload-drag-icon">
                <InboxOutlined />
              </p>
              <p className="ant-upload-text">将文件拖到此处上传</p>
            </Dragger>
          </div>
        ) : (
38e3fe2f   baiyun   配件计划
136
137
138
139
140
          <div>
            <p>数据总条数:{uploadResult.totalCount}条</p>
            <p>成功条数:{uploadResult.successCount}条</p>
            <p>失败条数:<span style={{ color: 'red' }}>{uploadResult.failedCount}</span>条</p>
            {uploadResult.filePath ? (<a href={uploadResult.filePath} target="_blank" rel="noopener noreferrer">下载错误文件</a>) : null}
26e052d0   baiyun   配件发运
141
142
143
144
145
146
147
148
149
            {!!uploadResult.data && !!uploadResult.successCount && (
              <div style={{marginTop: 10}}>
                <p>供应商:{uploadResult.data?.supplierName || '--'}</p>
                <p>发运单号:{uploadResult.data?.shippingNo || '--'}</p>
                <p>发运品种:{uploadResult.data?.cnt || 0}种</p>
                <p>本次导入金额:{uploadResult.data?.importAmount || 0}元</p>
                <a onClick={() => { setVisibleDetail(true); }}>去确认</a>
              </div>
            )}
38e3fe2f   baiyun   配件计划
150
151
          </div>
        )}
26e052d0   baiyun   配件发运
152
153
154
        <ConfirmDetailModal
          visible={visibleDetail}
          item={uploadResult?.data || {}}
2d451216   baiyun   配件计划联调
155
          confirm
d7be03e2   jiangwei   发运导入弹框无法关闭问题修复
156
          onCancel={() => setVisibleDetail(false)}
26e052d0   baiyun   配件发运
157
158
          fetchList={() => { setUploadResult(null); getList(); }}
        />
e3946366   baiyun   配件设置、采购供应商、月度任务联调
159
160
161
      </Modal>
    );
  }