Blame view

src/pages/pms/partPlan/PlanManage/subpages/Apply/components/PartModal.tsx 8.96 KB
12f15fa6   by1642146903   fix
1
  import React, {useEffect, useMemo, useState} from 'react';
f21c07ed   jiangwei   计划管理筛选
2
  import {Modal, Table, Input, message, Button, Select, Switch} from 'antd';
d25dfb85   by1642146903   配件指定采购供应商
3
4
  import Column from 'antd/lib/table/Column';
  import { debounce } from 'lodash';
6e99691c   jiangwei   配件系统配件类型数据来源更改
5
6
  import {getPartTypeApi} from '@/pages/pms/part/Repertory/api';
  import useInitail from '@/hooks/useInitail';
00502ebb   jiangwei   测试问题修改2.0
7
  import {planPoolTypeData} from '@/pages/pms/entity';
d25dfb85   by1642146903   配件指定采购供应商
8
9
10
11
12
13
14
  
  const Search = Input.Search;
  interface Props {
    onCancel: () => any,
    visible: boolean,
    parts: any[]
    onOk: (parts: any[]) => any
f21c07ed   jiangwei   计划管理筛选
15
    setParams: Function
21c88431   jiangwei   加入计划配件上次供应商与本次供应商...
16
    _supplierId: number | undefined
d25dfb85   by1642146903   配件指定采购供应商
17
  }
12f15fa6   by1642146903   fix
18
  const {Option} = Select;
21c88431   jiangwei   加入计划配件上次供应商与本次供应商...
19
  export default function Index({ onCancel, visible, parts = [], onOk, setParams, _supplierId }: Props) {
12f15fa6   by1642146903   fix
20
21
    const [selectedParts, setSelectedParts] = useState<any[]>([]);
    const [dfParam, setDfParam] = useState<any>({keywords: ''});
d25dfb85   by1642146903   配件指定采购供应商
22
    const [partList, setPartList] = useState(parts);
21c88431   jiangwei   加入计划配件上次供应商与本次供应商...
23
24
    const [info, setInfo] = useState<{open: boolean, partName: string, poolId?: number}>({open: false, partName: '', poolId: undefined});
    const [partArr, setPartArr] = useState<any[]>([]);
00502ebb   jiangwei   测试问题修改2.0
25
  
12f15fa6   by1642146903   fix
26
27
28
    const shopNames = useMemo(() => {
      return Array.from(new Set(parts.map(it => it.shopName || '').filter(it => !!it)));
    }, [parts]);
00502ebb   jiangwei   测试问题修改2.0
29
    
12f15fa6   by1642146903   fix
30
31
32
    const storageNames = useMemo(() => {
      return Array.from(new Set(parts.map(it => it.storageName || '').filter(it => !!it)));
    }, [parts]);
d25dfb85   by1642146903   配件指定采购供应商
33
  
f21c07ed   jiangwei   计划管理筛选
34
35
36
37
    const supplierNames = useMemo(() => {
      return Array.from(new Set(parts.map(it => it.supplierName || '').filter(it => !!it)));
    }, [parts]);
  
6e99691c   jiangwei   配件系统配件类型数据来源更改
38
39
    const { data: partTypeData } = useInitail(getPartTypeApi, [], {});
    
d25dfb85   by1642146903   配件指定采购供应商
40
41
42
    useEffect(() => {
      if (!visible) {
        setSelectedParts([]);
21c88431   jiangwei   加入计划配件上次供应商与本次供应商...
43
        setPartArr([]);
d25dfb85   by1642146903   配件指定采购供应商
44
45
46
47
48
49
50
51
52
        setPartList(parts);
      }
    }, [visible, parts]);
  
    function handSave() {
      if (selectedParts.length == 0) {
        message.error("请选择配件");
        return;
      }
21c88431   jiangwei   加入计划配件上次供应商与本次供应商...
53
54
55
56
57
58
59
60
      if (partArr.some(it => !!it.supplierId)) {
        for (const item of partArr) {
          if (!!item.supplierId && item.supplierId != _supplierId) {
            setInfo({ open: true, partName: item.partName, poolId: item.poolId });
            return;
          }
        }
      }
d25dfb85   by1642146903   配件指定采购供应商
61
62
63
64
65
      onOk && onOk(selectedParts);
      onCancel && onCancel();
    }
  
    const handleChange = debounce((value) => {
12f15fa6   by1642146903   fix
66
67
68
69
      setDfParam({...dfParam, keywords: value || ''});
    }, 500);
  
    useEffect(() => {
c52b00d6   jiangwei   Merge branch 'cas...
70
      setPartList(parts.filter(it => {
12f15fa6   by1642146903   fix
71
72
73
        return (it.partCode || '').includes(dfParam.keywords)
          || (it.partName || '').includes(dfParam.keywords)
          || (it.supplierName || '').includes(dfParam.keywords);
e262c695   jiangwei   配件流水展示信息优化
74
75
      })
      .filter(it => {
c8dc9e64   jiangwei   配件类型
76
        return (dfParam.partTypeName && it.partTypeName.includes(dfParam.partTypeName)) || !dfParam.partTypeName;
e262c695   jiangwei   配件流水展示信息优化
77
78
79
80
81
82
83
      })
      .filter(it => {
        return (dfParam.storageName && it.storageName == dfParam.storageName) || !dfParam.storageName;
      })
      .filter(it => {
        return (dfParam.shopName && it.shopName == dfParam.shopName) || !dfParam.shopName;
      })
f21c07ed   jiangwei   计划管理筛选
84
85
86
      .filter(it => {
        return (dfParam.supplierName && it.supplierName == dfParam.supplierName) || !dfParam.supplierName;
      })
e262c695   jiangwei   配件流水展示信息优化
87
      .filter(i => (dfParam.typeName && i.typeName == planPoolTypeData.find(item => item.value == dfParam.typeName)?.label) || !dfParam.typeName));
12f15fa6   by1642146903   fix
88
    }, [dfParam]);
55f44665   jiangwei   测试问题修改3.0
89
    
d25dfb85   by1642146903   配件指定采购供应商
90
91
    return (
      <Modal
f21c07ed   jiangwei   计划管理筛选
92
        width={1300}
d25dfb85   by1642146903   配件指定采购供应商
93
        visible={visible}
119677da   by1642146903   标题调整
94
        title="配件采购明细"
c9fd5311   by1642146903   配件计划
95
        onCancel={onCancel}
21c88431   jiangwei   加入计划配件上次供应商与本次供应商...
96
        maskClosable={false}
d25dfb85   by1642146903   配件指定采购供应商
97
98
99
100
101
102
103
104
105
106
107
108
109
        footer={[
          <Button key="cancel" onClick={onCancel}>取消</Button>,
          <Button
            key="submit"
            disabled={selectedParts.length == 0}
            onClick={handSave}
            type="primary"
            htmlType="submit"
          >
            确认
          </Button>
        ]}
      >
f21c07ed   jiangwei   计划管理筛选
110
        <div style={{display: 'flex', flexWrap: 'wrap', justifyContent: 'flex-start', alignItems: 'center', marginBottom: 10}}>
12f15fa6   by1642146903   fix
111
          <Search
12f15fa6   by1642146903   fix
112
            allowClear
9ca4d316   jiangwei   搜索优化
113
            enterButton
12f15fa6   by1642146903   fix
114
            placeholder="请输入配件名称/编码"
12f15fa6   by1642146903   fix
115
            onSearch={handleChange}
f21c07ed   jiangwei   计划管理筛选
116
            style={{ maxWidth: 200, marginRight: 10 }}
12f15fa6   by1642146903   fix
117
118
119
          />
          <Select
            allowClear
f21c07ed   jiangwei   计划管理筛选
120
            style={{ width: 150, marginRight: 10}}
c8dc9e64   jiangwei   配件类型
121
122
            onChange={(v) => {
              setDfParam({...dfParam, partTypeName: partTypeData.find(i => i.value == v)?.label});
12f15fa6   by1642146903   fix
123
124
            }}
            placeholder="请选择配件类型"
b4b59dc8   jiangwei   配件系统选择器增加搜索功能
125
126
            showSearch
            optionFilterProp="children"
12f15fa6   by1642146903   fix
127
128
129
130
131
132
133
          >
            {partTypeData.map((item: any) => (
              <Option value={item.value} key={item.value}>{item.label}</Option>
            ))}
          </Select>
          <Select
            allowClear
f21c07ed   jiangwei   计划管理筛选
134
            style={{ width: 150, marginRight: 10}}
12f15fa6   by1642146903   fix
135
136
137
138
            onChange={(storageName) => {
              setDfParam({...dfParam, storageName});
            }}
            placeholder="请选择库房"
b4b59dc8   jiangwei   配件系统选择器增加搜索功能
139
140
            showSearch
            optionFilterProp="children"
12f15fa6   by1642146903   fix
141
142
143
144
145
146
147
          >
            {storageNames.map((item: any) => (
              <Option value={item} key={item}>{item}</Option>
            ))}
          </Select>
          <Select
            allowClear
f21c07ed   jiangwei   计划管理筛选
148
            style={{ width: 150, marginRight: 10}}
12f15fa6   by1642146903   fix
149
150
151
152
            onChange={(shopName) => {
              setDfParam({...dfParam, shopName});
            }}
            placeholder="请选择门店"
b4b59dc8   jiangwei   配件系统选择器增加搜索功能
153
154
            showSearch
            optionFilterProp="children"
12f15fa6   by1642146903   fix
155
156
157
158
159
          >
            {shopNames.map((item: any) => (
              <Option value={item} key={item}>{item}</Option>
            ))}
          </Select>
00502ebb   jiangwei   测试问题修改2.0
160
161
          <Select
            allowClear
f21c07ed   jiangwei   计划管理筛选
162
            style={{ width: 150}}
00502ebb   jiangwei   测试问题修改2.0
163
164
165
166
            onChange={(typeName) => {
              setDfParam({...dfParam, typeName});
            }}
            placeholder="配件来源类型"
b4b59dc8   jiangwei   配件系统选择器增加搜索功能
167
168
            showSearch
            optionFilterProp="children"
00502ebb   jiangwei   测试问题修改2.0
169
170
171
172
173
          >
            {planPoolTypeData.map((item: any) => (
              <Option value={item.value} key={item.value}>{item.label}</Option>
            ))}
          </Select>
f21c07ed   jiangwei   计划管理筛选
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
          <Select
            allowClear
            style={{ width: 150, marginLeft: 10}}
            onChange={(supplierName) => {
              setDfParam({...dfParam, supplierName});
            }}
            placeholder="上次采购供应商"
            showSearch
            optionFilterProp="children"
          >
            {supplierNames.map((item: any) => (
              <Option value={item} key={item}>{item}</Option>
            ))}
          </Select>
          <Switch
            checkedChildren="油料" 
            unCheckedChildren="非油料" 
            onChange={checked => setParams({isOil: checked}, true)} 
            style={{marginLeft: 10}}
          />
12f15fa6   by1642146903   fix
194
        </div>
d25dfb85   by1642146903   配件指定采购供应商
195
196
        <Table
          dataSource={partList}
12f15fa6   by1642146903   fix
197
          scroll={{y: 400}}
d25dfb85   by1642146903   配件指定采购供应商
198
199
200
201
          style={{width: '100%'}}
          pagination={false}
          rowSelection={{
            type: "checkbox",
12f15fa6   by1642146903   fix
202
203
204
            selectedRowKeys: selectedParts.map(part => `${part.poolId}`),
            onSelect: (row: any, _selected: boolean) => {
              const index = selectedParts.findIndex(_row => _row.poolId == row.poolId);
d25dfb85   by1642146903   配件指定采购供应商
205
206
207
208
209
210
              let newData = [...selectedParts];
              if (_selected) {
                newData.unshift(row);
              } else if (index > -1) {
                newData.splice(index, 1);
              }
21c88431   jiangwei   加入计划配件上次供应商与本次供应商...
211
              setPartArr(newData);
d25dfb85   by1642146903   配件指定采购供应商
212
213
214
              setSelectedParts([...newData]);
            },
            onSelectAll: (selected, selectedRows, changeRows) => {
12f15fa6   by1642146903   fix
215
              const changedKeys = changeRows.map(row => `${row.poolId}`);
d25dfb85   by1642146903   配件指定采购供应商
216
217
218
              let newData = [...selectedParts];
              // 全选
              if (selected) {
12f15fa6   by1642146903   fix
219
                newData = selectedParts.concat(changeRows.filter(row => !selectedParts.some(item => item.poolId == row.poolId)),);
d25dfb85   by1642146903   配件指定采购供应商
220
              } else {
12f15fa6   by1642146903   fix
221
                newData = selectedParts.filter(row => !changedKeys.includes(`${row.poolId}`));
d25dfb85   by1642146903   配件指定采购供应商
222
              }
21c88431   jiangwei   加入计划配件上次供应商与本次供应商...
223
              setPartArr(newData);
d25dfb85   by1642146903   配件指定采购供应商
224
225
226
              setSelectedParts(newData);
            },
          }}
12f15fa6   by1642146903   fix
227
          rowKey={(record) => `${record.poolId}`}
d25dfb85   by1642146903   配件指定采购供应商
228
229
230
        >
          <Column title="配件编码" dataIndex="partCode" />
          <Column title="配件名称" dataIndex="partName" />
c52b00d6   jiangwei   Merge branch 'cas...
231
232
          <Column title="库房名称" dataIndex="storageName" />
          <Column title="门店名称" dataIndex="shopName" />
d25dfb85   by1642146903   配件指定采购供应商
233
          <Column title="配件数量" dataIndex="count" />
c8dc9e64   jiangwei   配件类型
234
          <Column title="配件类型" dataIndex="partTypeName" />
00502ebb   jiangwei   测试问题修改2.0
235
          <Column title="配件来源类型" dataIndex="typeName" />
d25dfb85   by1642146903   配件指定采购供应商
236
237
          <Column title="上次采购供应商" dataIndex="supplierName" />
        </Table>
21c88431   jiangwei   加入计划配件上次供应商与本次供应商...
238
239
240
241
        <Modal
          title="提示"
          open={info.open}
          maskClosable={false}
f9fa7e97   jiangwei   提示文字更改颜色
242
          closable={false}
21c88431   jiangwei   加入计划配件上次供应商与本次供应商...
243
244
245
246
247
248
249
250
251
252
253
254
          cancelText="重新选择"
          okText="继续"
          onCancel={() => {
            setPartArr(partArr.filter((i => i.poolId != info.poolId)));
            setSelectedParts(selectedParts.filter((i => i.poolId != info.poolId)));
            setInfo({open: false, partName: '', poolId: undefined});
          }}
          onOk={() => {
            setPartArr(partArr.filter((i => i.poolId != info.poolId)));
            setInfo({ open: false, partName: '', poolId: undefined });
          }}
        >
f9fa7e97   jiangwei   提示文字更改颜色
255
          <p style={{ color: 'red' }}><span style={{ color: '#333333', fontWeight: '500', marginRight: 3}}>【{info.partName}】</span>本次采购供应商和上次采购供应商不一致,是否继续?</p>
21c88431   jiangwei   加入计划配件上次供应商与本次供应商...
256
        </Modal>
d25dfb85   by1642146903   配件指定采购供应商
257
258
259
      </Modal>
    );
  }