|
@@ -0,0 +1,180 @@
|
|
1
|
+import React, { Component, useState, useEffect } from 'react';
|
|
2
|
+import { Form, Icon, Input, Button, DatePicker, Select, Card, Row, Col, Pagination, Alert, Table, Avatar, Radio, Modal, Descriptions } from 'antd';
|
|
3
|
+import moment from 'moment';
|
|
4
|
+import EChart from '../../../components/EchartsTest/EChart';
|
|
5
|
+import request from '../../../utils/request';
|
|
6
|
+import apis from '../../../services/apis';
|
|
7
|
+import StatsChartLine from './component/StatsChartLine';
|
|
8
|
+import BuildSelect from '../../../components/SelectButton/BuildSelect'
|
|
9
|
+import router from 'umi/router';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+const { RangePicker } = DatePicker;
|
|
13
|
+const { Option } = Select
|
|
14
|
+
|
|
15
|
+let daterange = []
|
|
16
|
+let tableTitle = ['类型']
|
|
17
|
+
|
|
18
|
+class buildingDetailStats extends React.Component {
|
|
19
|
+
|
|
20
|
+ constructor(props) {
|
|
21
|
+ super(props)
|
|
22
|
+ this.state = {
|
|
23
|
+ barData: {},
|
|
24
|
+ tableData: [],
|
|
25
|
+ total: 0,
|
|
26
|
+ userType: 'all',
|
|
27
|
+ endDate: {},
|
|
28
|
+ startDate: {},
|
|
29
|
+ buildingId: props.location.query.buildingId,
|
|
30
|
+ buildingName: props.location.query.buildingName,
|
|
31
|
+ }
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ componentDidMount() {
|
|
35
|
+ this.getTimeBarDate(moment().subtract(7, 'day').toDate(),new Date())
|
|
36
|
+ this.getTimeTableData(moment().subtract(7, 'day').toDate(),new Date())
|
|
37
|
+ this.setState({...this.state, endDate: new Date(), startDate: moment().subtract(7, 'day').toDate() })
|
|
38
|
+
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ // 获取图表数据
|
|
42
|
+ getTimeBarDate = (startDate, endDate) => {
|
|
43
|
+ request({ ...apis.stats.timeBarList, params: { startDate, endDate, buildingId: this.state.buildingId } }).then((data) => {
|
|
44
|
+ this.setState({...this.state, barData: data})
|
|
45
|
+ })
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ //获取表格数据
|
|
49
|
+ getTimeTableData = (startDate, endDate,pageNum,pageSize,sortField,sortOrder) => {
|
|
50
|
+ request({ ...apis.stats.timeTableList, params: { startDate, endDate, buildingId: this.state.buildingId,pageNum,pageSize,sortField,sortOrder } }).then((data) => {
|
|
51
|
+ this.setState({...this.state, tableData: data.records, total: data.total})
|
|
52
|
+ })
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ formatDate = (start, end) => {
|
|
56
|
+ const tempStartDate = `${moment(start).format('YYYY-MM-DDT00:00:00.000')}Z`
|
|
57
|
+ const tempEndDate = `${moment(end).format('YYYY-MM-DDT23:59:59.999')}Z`
|
|
58
|
+ return { startDate: tempStartDate, endDate: tempEndDate }
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ //时间选择器改变的时候
|
|
62
|
+ onChangetime = (_dates, dateStrings) => {
|
|
63
|
+ daterange[0] = `${moment(dateStrings[0]).format('YYYY-MM-DDT00:00:00.000')}Z`
|
|
64
|
+ daterange[1] = `${moment(dateStrings[1]).format('YYYY-MM-DDT23:59:59.999')}Z`
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+ //切换三个标签页
|
|
68
|
+ getDataOf = (days) => {
|
|
69
|
+ this.getTimeBarDate(moment().subtract(days, 'day').toDate(),new Date())
|
|
70
|
+ this.getTimeTableData(moment().subtract(days, 'day').toDate(),new Date())
|
|
71
|
+ this.setState({ ...this.state, endDate: new Date(), startDate: moment().subtract(days, 'day').toDate() })
|
|
72
|
+ }
|
|
73
|
+
|
|
74
|
+ //点击查询
|
|
75
|
+ datalist = () => {
|
|
76
|
+ this.getTimeBarDate(daterange[0] === undefined ? moment().subtract(7, 'day').toDate() : daterange[0],daterange[1] === undefined ? new Date() : daterange[1])
|
|
77
|
+ this.getTimeTableData(daterange[0] === undefined ? moment().subtract(7, 'day').toDate() : daterange[0],daterange[1] === undefined ? new Date() : daterange[1])
|
|
78
|
+ this.setState({
|
|
79
|
+ ...this.state,
|
|
80
|
+ endDate: daterange[1] === undefined ? new Date() : daterange[1],
|
|
81
|
+ startDate: daterange[0] === undefined ? moment().subtract(7, 'day').toDate() : daterange[0],
|
|
82
|
+ })
|
|
83
|
+
|
|
84
|
+ }
|
|
85
|
+
|
|
86
|
+ //排序
|
|
87
|
+ handleTableChange = (pagination, filters, sorter) => {
|
|
88
|
+ console.log(pagination, filters, sorter)
|
|
89
|
+ this.getTimeTableData(this.state.startDate,this.state.endDate,pagination.current,10,sorter.columnKey,sorter.order)
|
|
90
|
+ };
|
|
91
|
+
|
|
92
|
+ //导出
|
|
93
|
+ exportBuildingStats = () => {
|
|
94
|
+ request({ ...apis.stats.buildingExport, params: { startDate: this.state.startDate, endDate: this.state.endDate, buildingId: this.state.buildingId } })
|
|
95
|
+ .then(data => {
|
|
96
|
+ if (!data) {
|
|
97
|
+ return
|
|
98
|
+ }
|
|
99
|
+ const url = window.URL.createObjectURL(new Blob([data]))
|
|
100
|
+ const link = document.createElement('a')
|
|
101
|
+ link.style.display = 'none'
|
|
102
|
+ link.href = url
|
|
103
|
+ link.setAttribute('download', '项目统计.xlsx')
|
|
104
|
+ document.body.append(link)
|
|
105
|
+ link.click()
|
|
106
|
+ }).catch(() => {
|
|
107
|
+
|
|
108
|
+ })
|
|
109
|
+ }
|
|
110
|
+
|
|
111
|
+ render() {
|
|
112
|
+ const columns = [
|
|
113
|
+ {
|
|
114
|
+ title: '日期',
|
|
115
|
+ dataIndex: 'createDate',
|
|
116
|
+ key: 'createDate',
|
|
117
|
+ },
|
|
118
|
+ {
|
|
119
|
+ title: '新增客户',
|
|
120
|
+ dataIndex: 'khNum',
|
|
121
|
+ key: 'kh_num',
|
|
122
|
+ sorter: true,
|
|
123
|
+ },
|
|
124
|
+ {
|
|
125
|
+ title: '公客',
|
|
126
|
+ dataIndex: 'gkNum',
|
|
127
|
+ key: 'gk_num',
|
|
128
|
+ sorter: true,
|
|
129
|
+ },
|
|
130
|
+ {
|
|
131
|
+ title: '私客',
|
|
132
|
+ dataIndex: 'skNum',
|
|
133
|
+ key: 'sk_num',
|
|
134
|
+ sorter: true,
|
|
135
|
+ },
|
|
136
|
+ {
|
|
137
|
+ title: '访问人数',
|
|
138
|
+ dataIndex: 'uvNum',
|
|
139
|
+ key: 'uv_num',
|
|
140
|
+ sorter: true,
|
|
141
|
+ },
|
|
142
|
+ ];
|
|
143
|
+
|
|
144
|
+ return (
|
|
145
|
+ <div>
|
|
146
|
+ <Radio.Group buttonStyle="solid" defaultValue="a">
|
|
147
|
+ <Radio.Button value="c" onClick={() => this.getDataOf(0)}>今日</Radio.Button>
|
|
148
|
+ <Radio.Button value="a" onClick={() => this.getDataOf(7)}>最近7天</Radio.Button>
|
|
149
|
+ <Radio.Button value="b" onClick={() => this.getDataOf(30)}>最近1月</Radio.Button>
|
|
150
|
+ </Radio.Group>
|
|
151
|
+ <RangePicker
|
|
152
|
+ style={{ paddingLeft: '30px' }}
|
|
153
|
+ ranges={{
|
|
154
|
+ Today: [moment(), moment()],
|
|
155
|
+ 'This Month': [moment().startOf('month'), moment().endOf('month')],
|
|
156
|
+ }}
|
|
157
|
+ onChange={(_dates, dateStrings) => this.onChangetime(_dates, dateStrings)}
|
|
158
|
+ />
|
|
159
|
+ <Button type="primary" htmlType="submit" style={{ marginLeft: '30px' }} onClick={() => this.datalist()}>
|
|
160
|
+ 查询
|
|
161
|
+ </Button>
|
|
162
|
+ <Button type="danger" onClick={() => router.go(-1)} style={{ marginBottom: '18px', marginLeft: '30px' }}>重置</Button>
|
|
163
|
+
|
|
164
|
+ <StatsChartLine title={this.state.buildingName} data={this.state.barData} />
|
|
165
|
+ <Row>
|
|
166
|
+ <Col span={22}>
|
|
167
|
+ <span>详细数据</span>
|
|
168
|
+ </Col>
|
|
169
|
+ <Col span={2}>
|
|
170
|
+ <Button type="primary" onClick={this.exportBuildingStats}>导出</Button>
|
|
171
|
+ </Col>
|
|
172
|
+ </Row>
|
|
173
|
+
|
|
174
|
+ <Table style={{marginTop:'20px'}} dataSource={this.state.tableData} columns={columns} pagination={{ total: this.state.total}} onChange={this.handleTableChange} scroll={{ y: 500 }}></Table>
|
|
175
|
+ </div>
|
|
176
|
+ )
|
|
177
|
+ }
|
|
178
|
+}
|
|
179
|
+
|
|
180
|
+export default buildingDetailStats
|