Blame view

src/pages/pms/partPlan/PlanManage/subpages/Apply/index.tsx 15.2 KB
da356727   jiangwei   配件计划调整
1
  import {Card, ConfigProvider, Select, Button, message, Popconfirm, Input} from 'antd';
12f15fa6   by1642146903   fix
2
3
  import { PageHeaderWrapper } from '@ant-design/pro-layout';
  import React, {useEffect, useState} from "react";
ebd701f2   by1642146903   配件计划申请页面联调
4
5
6
7
  import DealerModal from './components/DealerModal';
  import SuppModal from './components/SuppModal';
  import PartDetailModal from './components/PartDetailModal';
  import {throttle, sum} from 'lodash';
12f15fa6   by1642146903   fix
8
9
  import useInitial from "@/hooks/useInitail";
  import * as API from "@/common/api";
12f15fa6   by1642146903   fix
10
  import {getList, Params, ListVO} from "@/pages/pms/partPlan/PlanPool/api";
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
11
  import {saveApi, draftApi} from './api';
12f15fa6   by1642146903   fix
12
13
  import zhCN from "antd/lib/locale-provider/zh_CN";
  import st from "@/pages/pms/partPlan/PlanManage/style.less";
ebd701f2   by1642146903   配件计划申请页面联调
14
15
  import PartModal from "@/pages/pms/partPlan/PlanManage/subpages/Apply/components/PartModal";
  import {groupBys, flattenDeep} from '@/pages/pms/entity';
1a88d6f6   jiangwei   小bug
16
  import {PartDetail} from '../../api';
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
17
  import { history } from 'umi';
da356727   jiangwei   配件计划调整
18
  import { getDetail, Params as detailParams, Item } from '../Detail/api';
c6f9c477   jiangwei   库房流水导出
19
  import ImageUpload from '@/pages/pms/comonents/ImageUpload';
12f15fa6   by1642146903   fix
20
  
12f15fa6   by1642146903   fix
21
  const { Option } = Select;
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
22
23
24
25
  const apiObj: { [key: number]: any } = {
    1: saveApi,
    2: draftApi
  };
12f15fa6   by1642146903   fix
26
  export default function Index() {
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
27
28
    const planId = history.location.query;
    const [detaildelay, setDetaildelay] = useState(true);
da356727   jiangwei   配件计划调整
29
    const { data, setParams: detailsetParams } = useInitial<Item, detailParams>(getDetail, {}, { ...planId }, detaildelay);
12f15fa6   by1642146903   fix
30
31
    const [delay, setDelay] = useState<boolean>(true);
    const [loading, setLoading] = useState<boolean>(false);
12f15fa6   by1642146903   fix
32
    const { data: brands } = useInitial(API.getBrandFilterApi, [], {});
12f15fa6   by1642146903   fix
33
34
    const [dfParams, setDfParams] = useState<any>({});
    const { data: parts, setParams } = useInitial<ListVO[], Params>(getList, [], dfParams, delay);
ebd701f2   by1642146903   配件计划申请页面联调
35
36
37
    const [dealerList, setDealerList] = useState<any[]>([]);
    const [dealer, setDealer] = useState<any>({});
    const [visibleDealer, setVisibleDealer] = useState(false);
12f15fa6   by1642146903   fix
38
    const [visibleSupplier, setVisibleSupplier] = useState(false);
ebd701f2   by1642146903   配件计划申请页面联调
39
40
41
42
    const [visiblePart, setVisiblePart] = useState(false);
    const [visiblePartDetail, setVisiblePartDetail] = useState(false);
    const partList = flattenDeep(dealerList.map(it => (it.suppliers || []).map((su: any) => (su.storages || []).map((st: any) => (st.parts || [])))));
    const poolIds = partList.map((it: any) => it.poolId);
da356727   jiangwei   配件计划调整
43
    const [info, setInfo] = useState<{ remark?: string, fids?: any }>();
21c88431   jiangwei   加入计划配件上次供应商与本次供应商...
44
    const [_supplierId, setSupplierId] = useState<number| undefined>(undefined);
12f15fa6   by1642146903   fix
45
  
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
46
47
48
49
50
51
52
53
    useEffect(() => {
      if (planId?.planId) {
        setDetaildelay(false);
        detailsetParams({ ...planId }, true);
      }
    }, []);
   
    useEffect(() => {
da356727   jiangwei   配件计划调整
54
      if (data.list?.length) {
da356727   jiangwei   配件计划调整
55
        setDfParams({brandId: data.list[0].brandId});
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
56
57
        setParams({}, true);
        setDelay(false);
da356727   jiangwei   配件计划调整
58
        setDealerList(data.list);
c6f9c477   jiangwei   库房流水导出
59
        setInfo({ remark: data.remark, fids: data.fids?.split(',') });
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
60
      }
da356727   jiangwei   配件计划调整
61
    }, [data.list?.length]);
9c4c170d   jiangwei   fix
62
  
ebd701f2   by1642146903   配件计划申请页面联调
63
64
    function onOk(parts: ListVO[] = []) {
      setDealerList(dealerList.map(it => {
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
65
        if (it.settleDealerId == dealer.settleDealerId) {
ebd701f2   by1642146903   配件计划申请页面联调
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
          return {
            ...it,
            suppliers: (it.suppliers || []).map((su: any) => {
              if (su.supplierId == dealer.supplierId) {
                const pas = [...flattenDeep((su.storages || []).map((st: any) => (st.parts || []))), ...parts];
                const sto = groupBys(pas, 'storageId', 'storageName');
                return {
                  ...su,
                  storages: sto.map(st => ({
                    storageId: st.storageId,
                    storageName: st.storageName,
                    parts: st.list,
                  }))
                };
              }
              return su;
            })
          };
        }
        return it;
      }));
    }
  
    function onOkDealer(dealer: any = {}) {
      setDealerList([...dealerList, dealer]);
    }
  
    function onOkSupplier(supplier: any = {}) {
      setDealerList(dealerList.map(it => {
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
95
        if (it.settleDealerId == dealer.settleDealerId) {
ebd701f2   by1642146903   配件计划申请页面联调
96
97
98
99
100
101
102
103
104
105
106
          return {
            ...it,
            suppliers: [...(it.suppliers || []), supplier]
          };
        }
        return it;
      }));
    }
  
    function deleteSupplier(dealer: any = {}, supplier: any = {}) {
      setDealerList(dealerList.map(it => {
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
107
        if (it.settleDealerId == dealer.settleDealerId) {
ebd701f2   by1642146903   配件计划申请页面联调
108
109
110
111
112
113
114
115
116
117
118
          return {
            ...it,
            suppliers: (it.suppliers || []).filter((su: any) => su.supplierId != supplier.supplierId)
          };
        }
        return it;
      }));
    }
  
    function deletePart(dealer: any = {}, supplier: any = {}, storage: any = {}, part: any = {}) {
      setDealerList(dealerList.map(it => {
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
119
        if (it.settleDealerId == dealer.settleDealerId) {
ebd701f2   by1642146903   配件计划申请页面联调
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
          return {
            ...it,
            suppliers: (it.suppliers || []).map((su: any) => {
              if (su.supplierId == supplier.supplierId) {
                return {
                  ...su,
                  storages: (su.storages || []).map((st: any) => {
                    if (st.storageId==storage.storageId) {
                      return {
                        ...st,
                        parts: (st.parts || []).filter((p: any) => p.poolId!=part.poolId)
                      };
                    }
                    return st;
                  })
                };
              }
              return su;
            })
          };
        }
        return it;
      }));
    }
  
    function deleteStorage(dealer: any = {}, supplier: any = {}, storage: any = {}) {
      setDealerList(dealerList.map(it => {
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
147
        if (it.settleDealerId == dealer.settleDealerId) {
ebd701f2   by1642146903   配件计划申请页面联调
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
          return {
            ...it,
            suppliers: (it.suppliers || []).map((su: any) => {
              if (su.supplierId == supplier.supplierId) {
                return {
                  ...su,
                  storages: (su.storages || []).filter((st: any) => st.storageId!=storage.storageId)
                };
              }
              return su;
            })
          };
        }
        return it;
      }));
12f15fa6   by1642146903   fix
163
164
    }
  
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
165
    const onSubmit = throttle((isSave) => {
12f15fa6   by1642146903   fix
166
      setLoading(true);
ebd701f2   by1642146903   配件计划申请页面联调
167
168
169
      let suppliers = flattenDeep(dealerList.map(de => (de.suppliers || []).map((su: any) => ({...de, ...su}))));
      suppliers = suppliers.map(su => ({
        ...su,
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
170
        settleDealerId: su.settleDealerId,
ebd701f2   by1642146903   配件计划申请页面联调
171
172
173
174
175
        storages: (su.storages || []).map((st: any) => ({
          storageId: st.storageId,
          poolIds: (st.parts || []).map((pa: any) => pa.poolId)
        }))
      }));
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
176
177
      const type = isSave ? 1 : 2;
      apiObj[type]({
57b51c35   jiangwei   配件计划池增加查看90天出库详情和...
178
        planId: Number(planId?.planId),
12f15fa6   by1642146903   fix
179
        ...dfParams,
da356727   jiangwei   配件计划调整
180
181
        suppliers,
        remark: info?.remark,
c6f9c477   jiangwei   库房流水导出
182
        fids: info?.fids.join()
12f15fa6   by1642146903   fix
183
184
      }).then(() => {
        setLoading(false);
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
185
186
        history.goBack();
      }).catch((e: any) => {
12f15fa6   by1642146903   fix
187
        setLoading(false);
ebd701f2   by1642146903   配件计划申请页面联调
188
189
        message.error(e.message);
      });
12f15fa6   by1642146903   fix
190
191
192
193
194
195
    }, 3000);
  
    return (
      <PageHeaderWrapper title="配件计划管理">
        <ConfigProvider locale={zhCN}>
          <Card className={st.page}>
c6f9c477   jiangwei   库房流水导出
196
197
198
199
200
201
202
203
204
205
206
207
            <div style={{ display: 'flex', alignItems: 'flex-start', marginBottom: 20 }}>
              <span style={{ marginRight: 10 }}>配件:</span>
              <div style={{ display: 'flex', flexDirection: 'column' }}>
                <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center'}}>
                  <Select
                    placeholder="请选择品牌"
                    onSearch={() => {}}
                    showSearch
                    filterOption={(input: any, option: any) => option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
                    style={{ width: 200, marginBottom: 20 }}
                    value={dfParams.brandId}
                    onChange={brandId => {
0553a34e   jiangwei   fix
208
                    setDfParams({ ...dfParams, brandId });
80920026   jiangwei   配件池参数fix
209
210
                    setParams({}, true);
                    setDelay(false);
ebd701f2   by1642146903   配件计划申请页面联调
211
                    setDealerList([]);
12f15fa6   by1642146903   fix
212
                  }}
c6f9c477   jiangwei   库房流水导出
213
214
215
216
217
                  >
                    {brands.map((item: any) => (
                      <Option value={item.id} key={item.id}>
                        {item.name}
                      </Option>
12f15fa6   by1642146903   fix
218
                  ))}
c6f9c477   jiangwei   库房流水导出
219
220
221
222
                  </Select>
                  <a
                    style={{marginLeft: 20, marginBottom: 20}}
                    onClick={() => {
ebd701f2   by1642146903   配件计划申请页面联调
223
224
225
226
227
228
                    if (!dfParams.brandId) {
                      message.error('请选择品牌');
                      return;
                    }
                    setVisibleDealer(true);
                  }}
c6f9c477   jiangwei   库房流水导出
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
                  >
                    添加采购商家
                  </a>
                </div>
                {dealerList.map((dealer: any = {}) => (
                  <div key={`dealer${dealer.settleDealerId}`} style={{ marginTop: 10 }}>
                    <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center'}}>
                      <div style={{ fontWeight: "bold" }}>{`商家: ${dealer.settleDealerName || ''}`}</div>
                      <a style={{marginLeft: 40}} onClick={() => { setVisibleSupplier(true); setDealer(dealer); }}>
                        添加指定供应商
                      </a>
                      <Popconfirm
                        title="是否删除"
                        onConfirm={() => setDealerList(dealerList.filter(it => it.settleDealerId!=dealer.settleDealerId))}
                        okText="确定"
                        cancelText="取消"
                        style={{marginLeft: 20}}
                      >
                        <Button type="link" danger>
                          删除
                        </Button>
                      </Popconfirm>
                    </div>
                    {(dealer.suppliers || []).map((supplier: any = {}) => {
ebd701f2   by1642146903   配件计划申请页面联调
253
                    const paList: any[] = flattenDeep((supplier.storages || []).map((st: any) => (st.parts || [])));
ebd701f2   by1642146903   配件计划申请页面联调
254
255
256
257
                    return (
                      <div key={`supplier${supplier.supplierId}`} style={{ marginTop: 10, marginLeft: 40 }}>
                        <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center'}}>
                          <div style={{ fontWeight: "bold" }}>{`供应商: ${supplier.supplierName || ''}`}</div>
21c88431   jiangwei   加入计划配件上次供应商与本次供应商...
258
                          <a style={{ marginLeft: 20 }} onClick={() => { setVisiblePart(true); setDealer({ ...dealer, ...supplier }); setSupplierId(supplier.supplierId); }}>
ebd701f2   by1642146903   配件计划申请页面联调
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
                            添加采购配件
                          </a>
                          <Popconfirm
                            title="是否删除"
                            onConfirm={() => deleteSupplier(dealer, supplier)}
                            okText="确定"
                            cancelText="取消"
                            style={{marginLeft: 20}}
                          >
                            <Button type="link" danger>
                              删除
                            </Button>
                          </Popconfirm>
                        </div>
                        <div style={{display: 'flex', marginLeft: 40, marginTop: 10}}>
                          <div style={{marginRight: 20}}>
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
275
                            {`总金额: ${sum(paList.map((it: any) => (it.price || 0) * (it.count || it.partCnt || 0))).toFixed(2)}元`}
ebd701f2   by1642146903   配件计划申请页面联调
276
                          </div>
1a88d6f6   jiangwei   小bug
277
                          <div>{`品种数: ${[...new Set((paList || []).map((i: PartDetail) => i.partCode))].length}种`}</div>
ebd701f2   by1642146903   配件计划申请页面联调
278
279
280
281
282
                        </div>
                        {(supplier.storages || []).map((storage: any) => (
                          <div key={`storage${storage.storageId}`} style={{ marginTop: 10, marginLeft: 60 }}>
                            <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center'}}>
                              <div style={{ fontWeight: "bold" }}>{`发运库房: ${storage.storageName || ''}`}</div>
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
283
                              <div style={{marginLeft: 20}}>{`总金额: ${sum((storage.parts || []).map((it: any) => (it.price || 0) * (it.count || it.partCnt || 0))).toFixed(2)}元`}</div>
1a88d6f6   jiangwei   小bug
284
                              <div style={{marginLeft: 20}}>{`品种数: ${[...new Set((storage.parts || []).map((i: PartDetail) => i.partCode))].length}种`}</div>
ebd701f2   by1642146903   配件计划申请页面联调
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
                              <a style={{marginLeft: 20}} onClick={() => { setVisiblePartDetail(true); setDealer({dealer, supplier, storage }); }}>
                                查看配件
                              </a>
                              <Popconfirm
                                title="是否删除"
                                onConfirm={() => deleteStorage(dealer, supplier, storage)}
                                okText="确定"
                                cancelText="取消"
                                style={{marginLeft: 20}}
                              >
                                <Button type="link" danger>
                                  删除
                                </Button>
                              </Popconfirm>
                            </div>
                          </div>
                        ))}
                      </div>
                    );
                  })}
c6f9c477   jiangwei   库房流水导出
305
                  </div>
ebd701f2   by1642146903   配件计划申请页面联调
306
              ))}
c6f9c477   jiangwei   库房流水导出
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
                <DealerModal
                  dealerList={dealerList}
                  visible={visibleDealer}
                  onCancel={() => setVisibleDealer(false)}
                  onOk={onOkDealer}
                />
                <SuppModal
                  brandId={dfParams.brandId}
                  supplierList={dealer.suppliers || []}
                  visible={visibleSupplier}
                  onCancel={() => setVisibleSupplier(false)}
                  onOk={onOkSupplier}
                />
                <PartModal
                  visible={visiblePart}
                  onCancel={() => setVisiblePart(false)}
                  parts={parts.filter(it => !poolIds.includes(it.poolId))}
                  onOk={onOk}
                  setParams={setParams}
21c88431   jiangwei   加入计划配件上次供应商与本次供应商...
326
                  _supplierId={_supplierId}
c6f9c477   jiangwei   库房流水导出
327
328
329
330
331
332
333
334
335
336
                />
                <PartDetailModal
                  visible={visiblePartDetail}
                  onCancel={() => setVisiblePartDetail(false)}
                  dealer={dealer.dealer}
                  supplier={dealer.supplier}
                  storage={dealer.storage}
                  deletePart={deletePart}
                />
              </div>
12f15fa6   by1642146903   fix
337
            </div>
da356727   jiangwei   配件计划调整
338
339
            <div style={{display: 'flex', alignItems: 'flex-start', marginBottom: 20}}>
              <span style={{marginRight: 10}}>备注:</span>
c6f9c477   jiangwei   库房流水导出
340
              <Input.TextArea rows={4} style={{ width: 250 }} value={info?.remark} onChange={e => setInfo({...info, remark: e.target.value})} />
da356727   jiangwei   配件计划调整
341
342
343
344
            </div>
            <div style={{ display: 'flex', alignItems: 'flex-start' }}>
              <span style={{ marginRight: 10 }}>附件:</span>
              <ImageUpload 
c6f9c477   jiangwei   库房流水导出
345
                max={6}
da356727   jiangwei   配件计划调整
346
                value={info?.fids} 
c6f9c477   jiangwei   库房流水导出
347
348
                onChange={v => {
                  setInfo({ ...info, fids: v });
da356727   jiangwei   配件计划调整
349
350
351
              }} 
              />
            </div>
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
352
            <div style={{display: 'flex', justifyContent: 'center'}}>
57b51c35   jiangwei   配件计划池增加查看90天出库详情和...
353
354
355
356
              <Button
                disabled={loading}
                loading={loading}
                style={{marginRight: 20}}
c6f9c477   jiangwei   库房流水导出
357
                onClick={() => { history.goBack(); }}
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
358
              >
57b51c35   jiangwei   配件计划池增加查看90天出库详情和...
359
360
                取消
              </Button>
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
              <Button
                disabled={loading}
                loading={loading}
                onClick={() => onSubmit(false)}
                type="primary"
                style={{marginRight: 20}}
              >
                暂存为草稿
              </Button>
              <Button
                disabled={loading}
                loading={loading}
                onClick={() => onSubmit(true)}
                type="primary"
              >
                确认并提交
              </Button>
            </div>
12f15fa6   by1642146903   fix
379
380
381
382
383
          </Card>
        </ConfigProvider>
      </PageHeaderWrapper>
    );
  }