Blame view

src/pages/order3/RetailTask/component/Modal.tsx 4 KB
308ed534   舒述军   零售任务手动调整
1
2
3
  import React, { useState } from 'react';
  import { Row, Modal, Table, Button, InputNumber, message } from 'antd';
  import Column from 'antd/lib/table/Column';
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
4
  import { ShopTaskList, ListItem } from '../api';
308ed534   舒述军   零售任务手动调整
5
  import { isNil } from 'lodash';
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  
  interface Props {
    setVisible: any,
    visible: boolean,
    current: ShopTaskList,
    index?: number,
    setList: (value: any) => any,
    list: ListItem,
    setCurrent: (value: any) => any,
    isHandledit: boolean
  }
  
  export default function EModal({ setVisible, visible, current = {}, index, setList, list = {}, setCurrent, isHandledit }: Props) {
    const [editable, setEditable] = useState<boolean>(false);
  
    function _onChange(e: number, innerIndex: number) {
      //改变整体外层数据
308ed534   舒述军   零售任务手动调整
23
24
      const data = JSON.parse(JSON.stringify(list));
      const currentData = JSON.parse(JSON.stringify(current));
99a9040f   舒述军   fix 零售台数输入
25
26
      if (!isNil(index)) {
        data.shopTaskList![index].staffTaskList![innerIndex].taskCount = e || 0;
308ed534   舒述军   零售任务手动调整
27
        data.shopTaskList![index].staffTaskList![innerIndex].clueDealTaskCount = Math.ceil((data.shopTaskList![index].clueDealTaskRate || 0)/100 *(e || 0));
99a9040f   舒述军   fix 零售台数输入
28
        currentData.staffTaskList![innerIndex].taskCount = e || 0;
308ed534   舒述军   零售任务手动调整
29
30
31
        currentData.staffTaskList![innerIndex].clueDealTaskCount = Math.ceil((data.shopTaskList![index].clueDealTaskRate || 0)/100 *(e || 0));
      }
      setList({ ...data });
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
32
      //回显改变数据
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
33
34
      setCurrent({ ...currentData });
    }
308ed534   舒述军   零售任务手动调整
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  
    /**
     * 修改零售任务
     * @param e 
     * @param innerIndex 
     */
    function hanldeChangeClue(e: number, innerIndex: number) {
      //改变整体外层数据
      const data = JSON.parse(JSON.stringify(list));
      const currentData = JSON.parse(JSON.stringify(current));
      if (!isNil(index) && data.shopTaskList![index].staffTaskList[innerIndex].taskCount < e) {
        message.error("线索到店零售台数不能大于零售任务!");
        return;
      }
99a9040f   舒述军   fix 零售台数输入
49
50
51
      if (!isNil(index)) {
        data.shopTaskList![index].staffTaskList![innerIndex].clueDealTaskCount = e || 0;
        currentData.staffTaskList![innerIndex].clueDealTaskCount = e || 0;
308ed534   舒述军   零售任务手动调整
52
53
54
55
56
57
      }
      setList({ ...data });
      //回显改变数据
      setCurrent({ ...currentData });
    }
  
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
    function handleClick() {
      setVisible(false);
      setEditable(false);
    }
  
    return (
      <Modal
        visible={visible}
        onCancel={() => setVisible(false)}
        maskClosable={false}
        width={600}
        footer={null}
      >
        <Table
          style={{ marginTop: 20 }}
          dataSource={current.staffTaskList}
          rowKey="staffId"
          pagination={false}
        >
903d06d8   舒述军   零售任务手动调整bugfix
77
78
79
          <Column 
            title="销售顾问" 
            align="center"
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
80
81
            render={(value: any) => {
              if (value.regularMonth) {
308ed534   舒述军   零售任务手动调整
82
                return <span>{value.staffName}(转正第{value.regularMonth}个月)</span>;
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
83
              } else {
308ed534   舒述军   零售任务手动调整
84
                return <span>{value.staffName}</span>;
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
85
86
87
              }
            }}
          />
903d06d8   舒述军   零售任务手动调整bugfix
88
89
90
91
          <Column 
            title="零售任务(台)" 
            dataIndex="taskCount" 
            align="center"
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
92
93
            render={(value, record, index) => {
              if (editable) {
308ed534   舒述军   零售任务手动调整
94
95
96
97
98
99
100
101
102
103
104
105
106
                return <InputNumber min={0} value={value} onChange={(e: any) => _onChange(e, index)} />;
              } else {
                return <span>{value}</span>;
              }
            }}
          />
          <Column 
            title="线索到店零售台数"
            dataIndex="clueDealTaskCount" 
            align="center"
            render={(value, record, index) => {
              if (editable) {
                return <InputNumber min={0} value={value} onChange={(e: any) => hanldeChangeClue(e, index)} />;
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
107
              } else {
308ed534   舒述军   零售任务手动调整
108
                return <span>{value}</span>;
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
109
110
111
112
113
              }
            }}
          />
        </Table>
        <Row justify="center" style={{ marginTop: 20 }}>
903d06d8   舒述军   零售任务手动调整bugfix
114
          {isHandledit ? (
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
115
            <>
903d06d8   舒述军   零售任务手动调整bugfix
116
117
118
119
              <Button type="primary" style={{ marginRight: 15, width: 110 }} onClick={handleClick}>确定</Button>
              <Button type="default" style={{ width: 110 }} onClick={() => setEditable(!editable)}>手动编辑</Button>
            </>
          ) : null}
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
120
121
        </Row>
      </Modal>
308ed534   舒述军   零售任务手动调整
122
    );
cc26d1fc   张志伟   🎉 重新构建项目,解决项目过大的问题
123
  }