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
19
  import { getDetail, Params as detailParams, Item } from '../Detail/api';
  import ImageUpload from '@/pages/decoration/deco/DeoGoodsManagement/components/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
44
    const [imageVisible, setImageVisible] = useState(true);
    const [info, setInfo] = useState<{ remark?: string, fids?: any }>();
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
55
56
      if (data.list?.length) {
        setImageVisible(false);
        setDfParams({brandId: data.list[0].brandId});
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
57
58
        setParams({}, true);
        setDelay(false);
da356727   jiangwei   配件计划调整
59
60
        setDealerList(data.list);
        setInfo({ remark: data.remark, fids: data.fids?.split(',').map(i => `/api/file/show?fid=${i}`) });
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
61
      }
da356727   jiangwei   配件计划调整
62
    }, [data.list?.length]);
9c4c170d   jiangwei   fix
63
  
ebd701f2   by1642146903   配件计划申请页面联调
64
65
    function onOk(parts: ListVO[] = []) {
      setDealerList(dealerList.map(it => {
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
66
        if (it.settleDealerId == dealer.settleDealerId) {
ebd701f2   by1642146903   配件计划申请页面联调
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
95
          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   计划管理增加草稿和继续编辑功能
96
        if (it.settleDealerId == dealer.settleDealerId) {
ebd701f2   by1642146903   配件计划申请页面联调
97
98
99
100
101
102
103
104
105
106
107
          return {
            ...it,
            suppliers: [...(it.suppliers || []), supplier]
          };
        }
        return it;
      }));
    }
  
    function deleteSupplier(dealer: any = {}, supplier: any = {}) {
      setDealerList(dealerList.map(it => {
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
108
        if (it.settleDealerId == dealer.settleDealerId) {
ebd701f2   by1642146903   配件计划申请页面联调
109
110
111
112
113
114
115
116
117
118
119
          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   计划管理增加草稿和继续编辑功能
120
        if (it.settleDealerId == dealer.settleDealerId) {
ebd701f2   by1642146903   配件计划申请页面联调
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
147
          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   计划管理增加草稿和继续编辑功能
148
        if (it.settleDealerId == dealer.settleDealerId) {
ebd701f2   by1642146903   配件计划申请页面联调
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
          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
164
165
    }
  
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
166
    const onSubmit = throttle((isSave) => {
12f15fa6   by1642146903   fix
167
      setLoading(true);
ebd701f2   by1642146903   配件计划申请页面联调
168
169
170
      let suppliers = flattenDeep(dealerList.map(de => (de.suppliers || []).map((su: any) => ({...de, ...su}))));
      suppliers = suppliers.map(su => ({
        ...su,
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
171
        settleDealerId: su.settleDealerId,
ebd701f2   by1642146903   配件计划申请页面联调
172
173
174
175
176
        storages: (su.storages || []).map((st: any) => ({
          storageId: st.storageId,
          poolIds: (st.parts || []).map((pa: any) => pa.poolId)
        }))
      }));
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
177
178
      const type = isSave ? 1 : 2;
      apiObj[type]({
57b51c35   jiangwei   配件计划池增加查看90天出库详情和...
179
        planId: Number(planId?.planId),
12f15fa6   by1642146903   fix
180
        ...dfParams,
da356727   jiangwei   配件计划调整
181
182
183
184
185
186
187
188
189
        suppliers,
        remark: info?.remark,
        fids: info?.fids.map((i: any) => {
          if (typeof i == 'object') {
            return i.url.split('=')[1];
          } else {
            return i;
          }
        }).join()
12f15fa6   by1642146903   fix
190
191
      }).then(() => {
        setLoading(false);
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
192
193
        history.goBack();
      }).catch((e: any) => {
12f15fa6   by1642146903   fix
194
        setLoading(false);
ebd701f2   by1642146903   配件计划申请页面联调
195
196
        message.error(e.message);
      });
12f15fa6   by1642146903   fix
197
198
199
200
201
202
203
    }, 3000);
  
    return (
      <PageHeaderWrapper title="配件计划管理">
        <ConfigProvider locale={zhCN}>
          <Card className={st.page}>
            <div style={{ display: 'flex', flexDirection: 'column', marginTop: 20, marginBottom: 20 }}>
ebd701f2   by1642146903   配件计划申请页面联调
204
              <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center'}}>
12f15fa6   by1642146903   fix
205
                <Select
ebd701f2   by1642146903   配件计划申请页面联调
206
207
208
209
210
211
212
                  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
213
                    setDfParams({ ...dfParams, brandId });
80920026   jiangwei   配件池参数fix
214
215
                    setParams({}, true);
                    setDelay(false);
ebd701f2   by1642146903   配件计划申请页面联调
216
                    setDealerList([]);
12f15fa6   by1642146903   fix
217
                  }}
12f15fa6   by1642146903   fix
218
                >
ebd701f2   by1642146903   配件计划申请页面联调
219
220
221
                  {brands.map((item: any) => (
                    <Option value={item.id} key={item.id}>
                      {item.name}
12f15fa6   by1642146903   fix
222
223
224
                    </Option>
                  ))}
                </Select>
ebd701f2   by1642146903   配件计划申请页面联调
225
226
227
228
229
230
231
232
233
234
235
236
                <a
                  style={{marginLeft: 20, marginBottom: 20}}
                  onClick={() => {
                    if (!dfParams.brandId) {
                      message.error('请选择品牌');
                      return;
                    }
                    setVisibleDealer(true);
                  }}
                >
                  添加采购商家
                </a>
12f15fa6   by1642146903   fix
237
              </div>
ebd701f2   by1642146903   配件计划申请页面联调
238
              {dealerList.map((dealer: any = {}) => (
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
239
                <div key={`dealer${dealer.settleDealerId}`} style={{ marginTop: 10 }}>
ebd701f2   by1642146903   配件计划申请页面联调
240
                  <div style={{ display: 'flex', flexDirection: 'row', alignItems: 'center'}}>
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
241
                    <div style={{ fontWeight: "bold" }}>{`商家: ${dealer.settleDealerName || ''}`}</div>
ebd701f2   by1642146903   配件计划申请页面联调
242
243
244
245
246
                    <a style={{marginLeft: 40}} onClick={() => { setVisibleSupplier(true); setDealer(dealer); }}>
                      添加指定供应商
                    </a>
                    <Popconfirm
                      title="是否删除"
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
247
                      onConfirm={() => setDealerList(dealerList.filter(it => it.settleDealerId!=dealer.settleDealerId))}
ebd701f2   by1642146903   配件计划申请页面联调
248
249
250
251
252
253
254
255
256
257
258
                      okText="确定"
                      cancelText="取消"
                      style={{marginLeft: 20}}
                    >
                      <Button type="link" danger>
                        删除
                      </Button>
                    </Popconfirm>
                  </div>
                  {(dealer.suppliers || []).map((supplier: any = {}) => {
                    const paList: any[] = flattenDeep((supplier.storages || []).map((st: any) => (st.parts || [])));
ebd701f2   by1642146903   配件计划申请页面联调
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
                    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>
                          <a style={{marginLeft: 20}} onClick={() => { setVisiblePart(true); setDealer({...dealer, ...supplier}); }}>
                            添加采购配件
                          </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   计划管理增加草稿和继续编辑功能
280
                            {`总金额: ${sum(paList.map((it: any) => (it.price || 0) * (it.count || it.partCnt || 0))).toFixed(2)}元`}
ebd701f2   by1642146903   配件计划申请页面联调
281
                          </div>
1a88d6f6   jiangwei   小bug
282
                          <div>{`品种数: ${[...new Set((paList || []).map((i: PartDetail) => i.partCode))].length}种`}</div>
ebd701f2   by1642146903   配件计划申请页面联调
283
284
285
286
287
                        </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   计划管理增加草稿和继续编辑功能
288
                              <div style={{marginLeft: 20}}>{`总金额: ${sum((storage.parts || []).map((it: any) => (it.price || 0) * (it.count || it.partCnt || 0))).toFixed(2)}元`}</div>
1a88d6f6   jiangwei   小bug
289
                              <div style={{marginLeft: 20}}>{`品种数: ${[...new Set((storage.parts || []).map((i: PartDetail) => i.partCode))].length}种`}</div>
ebd701f2   by1642146903   配件计划申请页面联调
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
                              <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>
                    );
                  })}
                </div>
              ))}
              <DealerModal
                dealerList={dealerList}
                visible={visibleDealer}
                onCancel={() => setVisibleDealer(false)}
                onOk={onOkDealer}
              />
              <SuppModal
12f15fa6   by1642146903   fix
319
                brandId={dfParams.brandId}
ebd701f2   by1642146903   配件计划申请页面联调
320
                supplierList={dealer.suppliers || []}
12f15fa6   by1642146903   fix
321
                visible={visibleSupplier}
12f15fa6   by1642146903   fix
322
                onCancel={() => setVisibleSupplier(false)}
ebd701f2   by1642146903   配件计划申请页面联调
323
324
325
326
327
328
                onOk={onOkSupplier}
              />
              <PartModal
                visible={visiblePart}
                onCancel={() => setVisiblePart(false)}
                parts={parts.filter(it => !poolIds.includes(it.poolId))}
12f15fa6   by1642146903   fix
329
                onOk={onOk}
f21c07ed   jiangwei   计划管理筛选
330
                setParams={setParams}
12f15fa6   by1642146903   fix
331
              />
ebd701f2   by1642146903   配件计划申请页面联调
332
333
334
335
336
337
338
339
              <PartDetailModal
                visible={visiblePartDetail}
                onCancel={() => setVisiblePartDetail(false)}
                dealer={dealer.dealer}
                supplier={dealer.supplier}
                storage={dealer.storage}
                deletePart={deletePart}
              />
12f15fa6   by1642146903   fix
340
            </div>
da356727   jiangwei   配件计划调整
341
342
343
344
345
346
347
348
349
350
351
352
353
            <div style={{display: 'flex', alignItems: 'flex-start', marginBottom: 20}}>
              <span style={{marginRight: 10}}>备注:</span>
              <Input.TextArea rows={2} style={{ width: 250 }} value={info?.remark} onChange={e => setInfo({...info, remark: e.target.value})} />
            </div>
            <div style={{ display: 'flex', alignItems: 'flex-start' }}>
              <span style={{ marginRight: 10 }}>附件:</span>
              <ImageUpload 
                length={6} 
                clear={imageVisible} 
                value={info?.fids} 
                onChange={v => { 
                  const ids = v.fileList.map(it => it?.response?.data || it);
                  setInfo({ ...info, fids: ids });
da356727   jiangwei   配件计划调整
354
355
356
              }} 
              />
            </div>
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
357
            <div style={{display: 'flex', justifyContent: 'center'}}>
57b51c35   jiangwei   配件计划池增加查看90天出库详情和...
358
359
360
361
              <Button
                disabled={loading}
                loading={loading}
                style={{marginRight: 20}}
da356727   jiangwei   配件计划调整
362
                onClick={() => { setImageVisible(true); history.goBack(); }}
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
363
              >
57b51c35   jiangwei   配件计划池增加查看90天出库详情和...
364
365
                取消
              </Button>
79d4a3b6   jiangwei   计划管理增加草稿和继续编辑功能
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
              <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
384
385
386
387
388
          </Card>
        </ConfigProvider>
      </PageHeaderWrapper>
    );
  }