Blame view

src/pages/order3/RetailTask/index.tsx 6.82 KB
308ed534   舒述军   零售任务手动调整
1
  import React, { useState, useEffect, useRef } from 'react';
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
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
  import { PageHeaderWrapper } from '@ant-design/pro-layout';
  import { Card, Table, Button, Row, DatePicker, Col, InputNumber, message } from 'antd';
  import { getRetailList, ListItem, saveHandelTack, ShopTaskList, save, saveParams } from './api';
  import EModal from './component/Modal';
  import moment from 'moment';
  
  const { Column } = Table;
  
  const day = new Date();
  const month = day.getMonth() + 1;
  const year = day.getFullYear();
  const strtime = year + '-' + month;
  let newDate = new Date(strtime);
  const newDay = newDate.getTime();
  
  export default function TacklingCarModels() {
    const [visible, setVisible] = useState<boolean>(false);
    const [loading, setLoading] = useState<boolean>(false);
    const [current, setCurrent] = useState<ShopTaskList>({});
    const [confirmLoading, setConfirmLoading] = useState<boolean>(false);
    const [saveLoading, setSaveLoading] = useState<boolean>(false);
    const [edit, setEdit] = useState<boolean>(false);
    const [date, setDate] = useState<number>(newDay);
    const [list, setList] = useState<ListItem>({});
    const [orginDara, setOrginDara] = useState<ListItem>({});
308ed534   舒述军   零售任务手动调整
27
    const index = useRef(0);
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
  
    useEffect(() => {
      getList(newDay);
    }, []);
  
    function setReset() {
      setList({ ...orginDara });
      getList(newDay);
    }
    //查询列表
    function getList(date: number) {
      const params = {
        taskDate: date.valueOf(),
        autoAssign: false,
      };
      getRetailList(params).then(res => {
        setLoading(false);
        const data = res.data;
        setOrginDara(res.data || {});
        setList(data || {});
        message.success('请求成功!');
      }).catch(e => {
        setLoading(false);
        message.warning(e.message);
      });
    }
  
    function _ChangeMoth(date: any) {
      setLoading(true);
      setDate(date.valueOf());
      getList(date);
    }
308ed534   舒述军   零售任务手动调整
60
  
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
61
    function _onChange(e: number, index: number) {
308ed534   舒述军   零售任务手动调整
62
      const data = JSON.parse(JSON.stringify(list));
903d06d8   舒述军   零售任务手动调整bugfix
63
      data.shopTaskList![index].taskCount = e || 0;
308ed534   舒述军   零售任务手动调整
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
      data.shopTaskList![index].clueDealTaskCount = Math.ceil((e || 0)*((data.shopTaskList![index].clueDealTaskRate || 0)/100));
      setList({ ...data });
    }
  
    /**
     * 修改线索到店零售台数
     * @param e 
     * @param index 
     */
    function handleChangeClue(e: number, index: number) {
      const data = JSON.parse(JSON.stringify(list));
      if (data.shopTaskList[index].taskCount < e) {
        message.error("线索到店零售台数不能大于零售任务!");
        return;
      }
99a9040f   舒述军   fix 零售台数输入
79
      data.shopTaskList![index].clueDealTaskCount = e || 0;
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
80
81
82
83
84
85
86
87
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
      setList({ ...data });
    }
    //保存
    function handleClick() {
      setLoading(true);
      const params = {
        id: list.id,
        shopTaskList: list.shopTaskList
      };
      if (edit) {
        handleSave(params);
      }
    }
    //提交审批
    function saveClick() {
      setLoading(true);
      setSaveLoading(true);
      save(list.id).then(() => {
        setSaveLoading(false);
        setLoading(false);
        setList({ ...list, canModified: false });
        message.success('提交成功!');
      }).catch(e => {
        setLoading(false);
        message.warning(e.message);
        setSaveLoading(false);
      });
    }
    //手动提交
    function handleSave(params: saveParams) {
      setConfirmLoading(true);
      saveHandelTack(params).then(() => {
        message.success('提交成功!');
        getList(date);
        setConfirmLoading(false);
        setEdit(false);
      }).catch(e => {
        message.warning(e.message);
        setLoading(false);
        setConfirmLoading(false);
      });
    }
  
    return (
      <PageHeaderWrapper title="零售任务手动调整">
        <Card>
          <Row style={{ marginTop: 20, marginBottom: 20 }}>
            <Col span={4}><DatePicker defaultValue={moment(newDay)} picker="month" onChange={_ChangeMoth} /></Col>
          </Row>
          <Table
            dataSource={list.shopTaskList}
            loading={loading}
            rowKey="shopId"
            pagination={false}
            summary={pageData => {
              let total = 0;
              pageData.forEach(({ taskCount }) => {
                total += taskCount || 0;
              });
              return (
                <>
48455300   舒述军   零售任务自动调整
141
142
                  {total == 0 ? null : (
                    <Table.Summary.Row>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
143
144
145
146
                      <Table.Summary.Cell index={1}><span style={{ display: 'block', textAlign: 'center' }}>合计</span></Table.Summary.Cell>
                      <Table.Summary.Cell index={2}>
                        <span style={{ display: 'block', textAlign: 'center' }}>{total}</span>
                      </Table.Summary.Cell>
48455300   舒述军   零售任务自动调整
147
                      <Table.Summary.Cell index={3} />
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
148
                    </Table.Summary.Row>
48455300   舒述军   零售任务自动调整
149
                  )}
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
150
151
152
153
154
                </>
              );
            }}
          >
            <Column title="门店" dataIndex="shopName" width={400} align="center" />
48455300   舒述军   零售任务自动调整
155
156
157
158
            <Column
              title="零售任务(台)"
              dataIndex="taskCount"
              align="center"
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
159
160
              render={(value, record, index) => {
                if (edit) {
48455300   舒述军   零售任务自动调整
161
                  return <InputNumber min={0} value={value} onChange={(e: any) => _onChange(e, index)} />;
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
162
                } else {
48455300   舒述军   零售任务自动调整
163
                  return <span>{value}</span>;
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
164
165
166
                }
              }}
            />
48455300   舒述军   零售任务自动调整
167
            <Column
308ed534   舒述军   零售任务手动调整
168
169
170
171
172
173
174
175
176
177
178
179
              title="线索到店零售台数"
              dataIndex="clueDealTaskCount"
              align="center"
              render={(value, record, index) => {
                if (edit) {
                  return <InputNumber min={0} value={value} onChange={(e: any) => handleChangeClue(e, index)} />;
                } else {
                  return <span>{value}</span>;
                }
              }}
            />
            <Column
48455300   舒述军   零售任务自动调整
180
181
182
              title="操作"
              align="center"
              render={(value, record, _index) => (
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
183
                <>
308ed534   舒述军   零售任务手动调整
184
                  <Button type="link" onClick={() => { setVisible(true); setCurrent(value); index.current = _index; }}>销售顾问任务</Button>
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
185
186
187
188
                </>
              )}
            />
          </Table>
308ed534   舒述军   零售任务手动调整
189
          <EModal setVisible={setVisible} visible={visible} current={current} index={index.current} setList={setList} list={list} setCurrent={setCurrent} isHandledit={edit} />
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
190
          <Row justify="center" style={{ marginTop: 15 }}>
48455300   舒述军   零售任务自动调整
191
            {list.canModified ? (
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
192
193
194
              <>
                {edit ?
                  <Button style={{ width: 110 }} type="primary" onClick={handleClick} loading={confirmLoading}>确定</Button> :
48455300   舒述军   零售任务自动调整
195
                  <Button style={{ width: 110 }} type="primary" onClick={saveClick} loading={saveLoading}>提交审批</Button>}
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
196
197
198
                <Button style={{ width: 110, marginLeft: 15, backgroundColor: '#FFF' }} type="default" onClick={() => setEdit(!edit)}>手动编辑</Button>
                {edit ?
                  <Button style={{ width: 110, marginLeft: 15 }} type="default" onClick={setReset} loading={confirmLoading}>取消</Button> :
48455300   舒述军   零售任务自动调整
199
200
201
                  null}
              </>
            ) : null}
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
202
203
          </Row>
        </Card>
48455300   舒述军   零售任务自动调整
204
205
      </PageHeaderWrapper>
    );
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
206
  }