Blame view

src/pages/pms/comonents/PartModal.tsx 3.65 KB
d25dfb85   by1642146903   配件指定采购供应商
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  import React, {useEffect, useState} from 'react';
  import {Modal, Table, Input, message, Button} from 'antd';
  import Column from 'antd/lib/table/Column';
  import { debounce } from 'lodash';
  import { PartVO } from '../partPlan/MinRatioPlan/api';
  
  const Search = Input.Search;
  interface Props {
    onCancel: () => any,
    visible: boolean,
    parts: any[]
    onOk: (parts: any[]) => any
  }
  
  export default function Index({ onCancel, visible, parts=[], onOk }: Props) {
    const [selectedParts, setSelectedParts] = useState<PartVO[]>([]);
    const [partList, setPartList] = useState(parts);
  
    useEffect(() => {
      if (!visible) {
        setSelectedParts([]);
        setPartList(parts);
      }
    }, [visible, parts]);
  
    function handSave() {
      if (selectedParts.length == 0) {
        message.error("请选择配件");
        return;
      }
      onOk && onOk(selectedParts);
      onCancel && onCancel();
    }
  
    const handleChange = debounce((value) => {
dccb02bf   by1642146903   订件
36
      setPartList(parts.filter(it => {
d25dfb85   by1642146903   配件指定采购供应商
37
38
39
40
41
42
43
44
        return (it.partCode || '').includes(value)
        || (it.partName || '').includes(value)
        || (it.supplierName || '').includes(value);
      }));
    }, 500);
  
    return (
      <Modal
b69f442c   baiyun   配件计划
45
        width={800}
d25dfb85   by1642146903   配件指定采购供应商
46
47
        visible={visible}
        title="配件采购品牌"
c9fd5311   by1642146903   配件计划
48
        onCancel={onCancel}
d25dfb85   by1642146903   配件指定采购供应商
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
        footer={[
          <Button key="cancel" onClick={onCancel}>取消</Button>,
          <Button
            key="submit"
            disabled={selectedParts.length == 0}
            onClick={handSave}
            type="primary"
            htmlType="submit"
          >
            确认
          </Button>
        ]}
      >
        <Search
          enterButton
          allowClear
          placeholder="请输入配件名称/编码"
          onChange={e => handleChange(e.target.value)}
          onSearch={handleChange}
          style={{ maxWidth: 240, marginBottom: 20 }}
        />
        <Table
          dataSource={partList}
          scroll={{y: 600}}
          style={{width: '100%'}}
          pagination={false}
          rowSelection={{
            type: "checkbox",
dccb02bf   by1642146903   订件
77
            selectedRowKeys: selectedParts.map(part => `${part.partCode}-${part.storageId}`),
d25dfb85   by1642146903   配件指定采购供应商
78
            onSelect: (row: PartVO, _selected: boolean) => {
dccb02bf   by1642146903   订件
79
              const index = selectedParts.findIndex(_row => _row.partCode == row.partCode && _row.storageId == row.storageId);
d25dfb85   by1642146903   配件指定采购供应商
80
81
82
83
84
85
86
87
88
              let newData = [...selectedParts];
              if (_selected) {
                newData.unshift(row);
              } else if (index > -1) {
                newData.splice(index, 1);
              }
              setSelectedParts([...newData]);
            },
            onSelectAll: (selected, selectedRows, changeRows) => {
dccb02bf   by1642146903   订件
89
              const changedKeys = changeRows.map(row => `${row.partCode}-${row.storageId}`);
d25dfb85   by1642146903   配件指定采购供应商
90
91
92
93
              let newData = [...selectedParts];
              // 全选
              if (selected) {
                // 过滤掉已选的
dccb02bf   by1642146903   订件
94
                newData = selectedParts.concat(changeRows.filter(row => !selectedParts.some(item => item.partCode == row.partCode && item.storageId == row.storageId)),);
d25dfb85   by1642146903   配件指定采购供应商
95
96
              } else {
                // 全不选 - 去掉已选的
dccb02bf   by1642146903   订件
97
                newData = selectedParts.filter(row => !changedKeys.includes(`${row.partCode}-${row.storageId}`));
d25dfb85   by1642146903   配件指定采购供应商
98
99
100
101
              }
              setSelectedParts(newData);
            },
          }}
dccb02bf   by1642146903   订件
102
          rowKey={(record) => `${record.partCode}-${record.storageId}`}
d25dfb85   by1642146903   配件指定采购供应商
103
104
105
        >
          <Column title="配件编码" dataIndex="partCode" />
          <Column title="配件名称" dataIndex="partName" />
dccb02bf   by1642146903   订件
106
107
          <Column title="库房名称" dataIndex="storageName" />
          <Column title="门店名称" dataIndex="shopName" />
d25dfb85   by1642146903   配件指定采购供应商
108
109
110
111
112
113
          <Column title="配件数量" dataIndex="count" />
          <Column title="上次采购供应商" dataIndex="supplierName" />
        </Table>
      </Modal>
    );
  }