Blame view

src/pages/OrderReport/index.tsx 5.21 KB
zhongnanhuang authored
1
2
import { postServiceOrderQueryReportFormsInformation } from '@/services';
import { enumToSelect } from '@/utils';
zhongnanhuang authored
3
import { getUserInfo } from '@/utils/user';
zhongnanhuang authored
4
import { EllipsisOutlined } from '@ant-design/icons';
zhongnanhuang authored
5
6
7
import {
  PageContainer,
  ProCard,
8
  ProFormDigit,
zhongnanhuang authored
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  ProFormSelect,
  QueryFilter,
} from '@ant-design/pro-components';
import { history } from '@umijs/max';
import {
  Avatar,
  Button,
  Dropdown,
  Flex,
  Form,
  Space,
  Spin,
  Tabs,
  TabsProps,
  Tag,
} from 'antd';
import { useEffect, useState } from 'react';
import {
  PRODUCT_BELONG_DEPARTMENT_OPTIONS,
  SALES_CODE_OPTIONS,
} from '../Order/constant';
zhongnanhuang authored
30
31
import OrderDualAxes from './components/OrderDualAxes';
import OrderStatisticCard from './components/OrderStatisticCard';
zhongnanhuang authored
32
import './index.less';
zhongnanhuang authored
33
const userInfo = getUserInfo();
zhongnanhuang authored
34
zhongnanhuang authored
35
const OrderReportPage = () => {
zhongnanhuang authored
36
37
38
39
40
41
42
  const [form] = Form.useForm<{
    salesCode: '';
    productBelongBusiness: '';
    dateRange: '';
  }>();
  const [statisticData, setStatisticData] = useState([]);
  const [loading, setLoading] = useState(false);
zhongnanhuang authored
43
  const [statisticsMethod, setStatisticsMethod] = useState('MONTH_STATISTICS');
zhongnanhuang authored
44
  const onChange = (key: string) => {
zhongnanhuang authored
45
    setStatisticsMethod(key);
zhongnanhuang authored
46
47
48
49
50
51
52
53
54
55
56
  };

  /**
   * 加载页面数据
   */
  const loadData = async () => {
    setLoading(true);
    let body = {
      statisticsMethod: '',
      salesCode: form.getFieldValue('salesCode'),
      productBelongBusiness: form.getFieldValue('productBelongBusiness'),
57
      maxAccount: form.getFieldValue('maxAccount'),
zhongnanhuang authored
58
59
60
61
62
63
64
65
      // beginTime:"",
      // endTime:""
    };

    // if(form.getFieldValue("dateRange")!==undefined){
    //   body.beginTime=formatDate(form.getFieldValue("dateRange")[0]),
    //   body.endTime=formatDate(form.getFieldValue("dateRange")[1])
    // }
zhongnanhuang authored
66
    body.statisticsMethod = statisticsMethod;
zhongnanhuang authored
67
68
69
    const { data } = await postServiceOrderQueryReportFormsInformation({
      data: body,
    });
zhongnanhuang authored
70
71
72
73
    if (data !== undefined) {
      setStatisticData(data);
    }
zhongnanhuang authored
74
75
76
77
78
    setLoading(false);
  };

  useEffect(() => {
    loadData();
zhongnanhuang authored
79
80
81
82
  }, [statisticsMethod]);

  useEffect(() => {
    loadData();
zhongnanhuang authored
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  }, []);

  const items: TabsProps['items'] = [
    {
      key: 'MONTH_STATISTICS',
      label: '本月统计',
      children: '',
    },
    {
      key: 'YEAR_STATISTICS',
      label: '本年统计',
      children: '',
    },
  ];
zhongnanhuang authored
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
  return (
    <PageContainer
      header={{
        title: '订单汇总',
        extra: [
          <Avatar key="0" style={{ verticalAlign: 'middle' }} size="large">
            {userInfo?.username}
          </Avatar>,
          <Tag key="nickName">{userInfo?.nickName}</Tag>,
          <Dropdown
            key="dropdown"
            trigger={['click']}
            menu={{
              items: [
                {
                  label: '退出登录',
                  key: '1',
                  onClick: () => {
                    localStorage.removeItem('token');
                    history.push('/login');
                  },
                },
                // {
                //   label: '修改密码',
                //   key: '2',
                // },
              ],
            }}
          >
            <Button key="4" style={{ padding: '0 8px' }}>
              <EllipsisOutlined />
            </Button>
          </Dropdown>,
        ],
      }}
    >
      <Space direction="vertical" size="middle" className="flex">
zhongnanhuang authored
134
        <Spin spinning={loading}>
zhongnanhuang authored
135
136
137
138
139
          <OrderStatisticCard
            data={statisticData}
            statisticsMethod={statisticsMethod}
            reFreshData={loadData}
          />
zhongnanhuang authored
140
141
        </Spin>
zhongnanhuang authored
142
        <ProCard tooltip="这是提示" bordered>
zhongnanhuang authored
143
144
145
146
          <QueryFilter
            split
            className="!p-0 order-statistic-search"
            labelWidth="auto"
147
            defaultCollapsed={false}
zhongnanhuang authored
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
            form={form}
            onFinish={async () => {
              loadData();
              return true;
            }}
          >
            <ProFormSelect
              name="salesCode"
              key="salesCode"
              showSearch
              label="销售代表"
              placeholder="请输入销售代表"
              options={SALES_CODE_OPTIONS}
            />
            <ProFormSelect
              key="productBelongBusiness"
              placeholder="请输入所属事业部"
              name="productBelongBusiness"
              label="所属事业部"
              options={enumToSelect(PRODUCT_BELONG_DEPARTMENT_OPTIONS)}
            />
169
170
            <ProFormDigit label="排除大订单金额" name="maxAccount" min={0} />
zhongnanhuang authored
171
172
173
174
175
176
            {/* <ProFormDateRangePicker
              key="dateRange"
              name="dateRange"
              label="时间"
            /> */}
          </QueryFilter>
zhongnanhuang authored
177
178
        </ProCard>
zhongnanhuang authored
179
180
181
182
183
184
185
186
187
188
189
        <ProCard
          id="order-dual-axes-card"
          title="统计图表"
          extra={
            <Flex>
              <Tabs defaultActiveKey="1" items={items} onChange={onChange} />
            </Flex>
          }
          bordered
        >
          <Spin spinning={loading}>
zhongnanhuang authored
190
191
192
193
            <OrderDualAxes
              data={statisticData}
              statisticMethod={statisticsMethod}
            />
zhongnanhuang authored
194
          </Spin>
zhongnanhuang authored
195
196
197
198
        </ProCard>
      </Space>
    </PageContainer>
  );
zhongnanhuang authored
199
};
zhongnanhuang authored
200
201

export default OrderReportPage;