|
@@ -0,0 +1,158 @@
|
|
1
|
+import React, { Component, useState, useEffect } from 'react';
|
|
2
|
+import {
|
|
3
|
+ Radio,
|
|
4
|
+ DatePicker,
|
|
5
|
+ Form,
|
|
6
|
+ Input,
|
|
7
|
+ Button,
|
|
8
|
+ Icon,
|
|
9
|
+ Select,
|
|
10
|
+ message,
|
|
11
|
+ Table,
|
|
12
|
+ Divider,
|
|
13
|
+ Tag,
|
|
14
|
+ Pagination,
|
|
15
|
+ Modal,
|
|
16
|
+ Breadcrumb,
|
|
17
|
+} from 'antd';
|
|
18
|
+import { Row, Col, Menu, Dropdown } from 'antd';
|
|
19
|
+
|
|
20
|
+// import XForm, { FieldTypes } from '../../components/XForm';
|
|
21
|
+import moment from 'moment';
|
|
22
|
+import router from 'umi/router';
|
|
23
|
+// import EChart from '../../components/EchartsTest/EChart';
|
|
24
|
+import request from '@/utils/request';
|
|
25
|
+import apis from '@/services/apis';
|
|
26
|
+
|
|
27
|
+const formatDate = (start, end) => {
|
|
28
|
+ const startDate = moment(start).format('YYYY-MM-DDT00:00:00.000') + 'Z';
|
|
29
|
+ const endDate = moment(end).format('YYYY-MM-DDT23:59:59.999') + 'Z';
|
|
30
|
+ return { startDate, endDate };
|
|
31
|
+ };
|
|
32
|
+
|
|
33
|
+let columns = [
|
|
34
|
+ {
|
|
35
|
+ title: '日期',
|
|
36
|
+ dataIndex: 'createTime',
|
|
37
|
+ key: 'createTime',
|
|
38
|
+ },
|
|
39
|
+];
|
|
40
|
+
|
|
41
|
+let daterange = [];
|
|
42
|
+
|
|
43
|
+const header = props => {
|
|
44
|
+ const {
|
|
45
|
+ startDate = moment().subtract(7, 'day').format('YYYY-MM-DDT00:00:00.000') + 'Z',
|
|
46
|
+ endDate = moment().format('YYYY-MM-DDT23:59:59.999') + 'Z',
|
|
47
|
+ } = props;
|
|
48
|
+ const [data, setData] = useState({ records: [] });
|
|
49
|
+
|
|
50
|
+ const [tableData, setTableData] = useState([]);
|
|
51
|
+// const [endDate, setEndDate] = useState({});
|
|
52
|
+ const [userType, setUserType] = useState('all');
|
|
53
|
+// const [startDate, setStartDate] = useState({});
|
|
54
|
+
|
|
55
|
+ useEffect(() => {
|
|
56
|
+ userResource({startDate, endDate,userType});
|
|
57
|
+ }, [startDate, endDate,userType]);
|
|
58
|
+
|
|
59
|
+ function userResource(params) {
|
|
60
|
+ request({
|
|
61
|
+ ...apis.indexEcharts.selectPersonFrom,
|
|
62
|
+ params,
|
|
63
|
+ }).then(data => {
|
|
64
|
+ // setDate(data);
|
|
65
|
+ onTabledatas(data, 'all');
|
|
66
|
+ });
|
|
67
|
+ }
|
|
68
|
+
|
|
69
|
+ const onTabledatas = (e, changeType) => {
|
|
70
|
+ e.tdWxDicts.map(x => {
|
|
71
|
+ columns = columns
|
|
72
|
+ .filter(y => y.key != x.sceneType)
|
|
73
|
+ .concat({
|
|
74
|
+ title: x.sceneAlias,
|
|
75
|
+ dataIndex: x.sceneType,
|
|
76
|
+ key: x.sceneType,
|
|
77
|
+ });
|
|
78
|
+ });
|
|
79
|
+ const data = (e.list || []).reduce((acc, item) => {
|
|
80
|
+ const { sceneType, fromNum, registeredNum, createTime } = item;
|
|
81
|
+ const num = changeType === 'registered' ? registeredNum : fromNum;
|
|
82
|
+ acc[createTime] = { ...acc[createTime], ...item, [`${sceneType}`]: !num ? 0 : num };
|
|
83
|
+ return acc;
|
|
84
|
+ }, {});
|
|
85
|
+
|
|
86
|
+ const dictData = e.tdWxDicts.reduce((acc, item, index) => {
|
|
87
|
+ const { sceneType } = item;
|
|
88
|
+ acc[sceneType] = 0;
|
|
89
|
+ return acc;
|
|
90
|
+ }, {});
|
|
91
|
+
|
|
92
|
+ const tableData = Object.keys(data)
|
|
93
|
+ .map(k => data[k])
|
|
94
|
+ .reduce((acc, item, index) => {
|
|
95
|
+ acc[index] = { ...dictData, ...item };
|
|
96
|
+ return acc;
|
|
97
|
+ }, []);
|
|
98
|
+
|
|
99
|
+ setTableData(tableData);
|
|
100
|
+ };
|
|
101
|
+
|
|
102
|
+ function handleSelectChange(e) {
|
|
103
|
+ setUserType(e);
|
|
104
|
+ }
|
|
105
|
+
|
|
106
|
+ function exportUserStats() {
|
|
107
|
+ console.log(startDate, endDate, userType);
|
|
108
|
+ request({
|
|
109
|
+ ...apis.indexEcharts.exportUserStats,
|
|
110
|
+ params: { startDate, endDate, userType },
|
|
111
|
+ }).then(data => {
|
|
112
|
+ if (!data) {
|
|
113
|
+ return;
|
|
114
|
+ }
|
|
115
|
+ const url = window.URL.createObjectURL(new Blob([data]));
|
|
116
|
+ const link = document.createElement('a');
|
|
117
|
+ link.style.display = 'none';
|
|
118
|
+ link.href = url;
|
|
119
|
+ link.setAttribute('download', '新增用户.xlsx');
|
|
120
|
+ document.body.append(link);
|
|
121
|
+ link.click();
|
|
122
|
+ });
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ return (
|
|
126
|
+ <>
|
|
127
|
+ <div>
|
|
128
|
+ <Row>
|
|
129
|
+ <Col span={22}>
|
|
130
|
+ <Select
|
|
131
|
+ style={{ width: '180px' }}
|
|
132
|
+ placeholder="所有用户"
|
|
133
|
+ onChange={e => handleSelectChange(e)}
|
|
134
|
+ >
|
|
135
|
+ <Option value="all">所有用户</Option>
|
|
136
|
+ <Option value="registered">注册用户</Option>
|
|
137
|
+ </Select>
|
|
138
|
+ </Col>
|
|
139
|
+ <Col span={2}>
|
|
140
|
+ {/* <Button type="primary" onClick={exportUserStats}>
|
|
141
|
+ 导出
|
|
142
|
+ </Button> */}
|
|
143
|
+ </Col>
|
|
144
|
+ </Row>
|
|
145
|
+
|
|
146
|
+ <Table
|
|
147
|
+ style={{ marginTop: '20px' }}
|
|
148
|
+ dataSource={tableData}
|
|
149
|
+ columns={columns}
|
|
150
|
+ pagination={false}
|
|
151
|
+ scroll={{ y: 500 }}
|
|
152
|
+ ></Table>
|
|
153
|
+ </div>
|
|
154
|
+ </>
|
|
155
|
+ );
|
|
156
|
+};
|
|
157
|
+
|
|
158
|
+export default header;
|