|
@@ -4,73 +4,51 @@ import moment from 'moment';
|
4
|
4
|
import EChart from '../../../components/EchartsTest/EChart';
|
5
|
5
|
import request from '../../../utils/request';
|
6
|
6
|
import apis from '../../../services/apis';
|
|
7
|
+import StatsChart from './component/StatsChart';
|
|
8
|
+import BuildSelect from '../../../components/SelectButton/BuildSelect'
|
7
|
9
|
import router from 'umi/router';
|
8
|
10
|
|
9
|
11
|
|
10
|
12
|
const { RangePicker } = DatePicker;
|
11
|
13
|
const { Option } = Select
|
12
|
14
|
|
13
|
|
-
|
14
|
|
-// const formatDate = (start, end) => {
|
15
|
|
-// const startDate = moment(start).format('YYYY-MM-DDT00:00:00.000') + 'Z'
|
16
|
|
-// const endDate = moment(end).format('YYYY-MM-DDT23:59:59.999') + 'Z'
|
17
|
|
-// return { startDate, endDate }
|
18
|
|
-// }
|
19
|
|
-
|
20
|
15
|
let daterange = []
|
21
|
16
|
let tableTitle = ['类型']
|
22
|
17
|
|
23
|
|
-let columns = [
|
24
|
|
- {
|
25
|
|
- title: '日期',
|
26
|
|
- dataIndex: 'createTime',
|
27
|
|
- key: 'createTime',
|
28
|
|
- },
|
29
|
|
- // {
|
30
|
|
- // title: '名片分享',
|
31
|
|
- // dataIndex: '名片分享',
|
32
|
|
- // key: '名片分享',
|
33
|
|
- // },
|
34
|
|
- // {
|
35
|
|
- // title: '生成海报',
|
36
|
|
- // dataIndex: '生成海报',
|
37
|
|
- // key: '生成海报',
|
38
|
|
- // },
|
39
|
|
- // {
|
40
|
|
- // title: '小程序搜索',
|
41
|
|
- // dataIndex: '小程序搜索',
|
42
|
|
- // key: '小程序搜索',
|
43
|
|
- // },
|
44
|
|
- // {
|
45
|
|
- // title: '好友分享',
|
46
|
|
- // dataIndex: '好友分享',
|
47
|
|
- // key: '好友分享',
|
48
|
|
- // },
|
49
|
|
-]
|
50
|
|
-
|
51
|
|
-// let columns = [
|
52
|
|
-// {
|
53
|
|
-// title: '类型',
|
54
|
|
-// dataIndex: 'value',
|
55
|
|
-// key: 'value',
|
56
|
|
-// }
|
57
|
|
-// ]
|
58
|
|
-
|
59
|
18
|
class buildingStats extends React.Component {
|
60
|
19
|
|
61
|
20
|
constructor(props) {
|
62
|
21
|
super(props)
|
63
|
22
|
this.state = {
|
64
|
|
- dataSoures: [],
|
|
23
|
+ barData: {},
|
65
|
24
|
tableData: [],
|
|
25
|
+ total: 0,
|
66
|
26
|
userType: 'all',
|
67
|
27
|
endDate: {},
|
68
|
|
- startDate: {}
|
|
28
|
+ startDate: {},
|
|
29
|
+ buildingId: ''
|
69
|
30
|
}
|
70
|
31
|
}
|
71
|
32
|
|
72
|
33
|
componentDidMount() {
|
73
|
|
- this.setState({ endDate: new Date(), startDate: moment().subtract(7, 'day').toDate() })
|
|
34
|
+ this.getBarData(moment().subtract(7, 'day').toDate(),new Date())
|
|
35
|
+ this.getTableData(moment().subtract(7, 'day').toDate(),new Date(),this.state.buildingId)
|
|
36
|
+ this.setState({...this.state, endDate: new Date(), startDate: moment().subtract(7, 'day').toDate() })
|
|
37
|
+
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ // 获取图表数据
|
|
41
|
+ getBarData = (startDate, endDate) => {
|
|
42
|
+ request({ ...apis.stats.barList, params: { startDate, endDate } }).then((data) => {
|
|
43
|
+ this.setState({...this.state, barData: data})
|
|
44
|
+ })
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+ //获取表格数据
|
|
48
|
+ getTableData = (startDate, endDate, buildingId,pageNum,pageSize,sortField,sortOrder) => {
|
|
49
|
+ request({ ...apis.stats.tableList, params: { startDate, endDate, buildingId,pageNum,pageSize,sortField,sortOrder } }).then((data) => {
|
|
50
|
+ this.setState({...this.state, tableData: data.records, total: data.total})
|
|
51
|
+ })
|
74
|
52
|
}
|
75
|
53
|
|
76
|
54
|
formatDate = (start, end) => {
|
|
@@ -79,84 +57,122 @@ class buildingStats extends React.Component {
|
79
|
57
|
return { startDate: tempStartDate, endDate: tempEndDate }
|
80
|
58
|
}
|
81
|
59
|
|
|
60
|
+ //时间选择器改变的时候
|
82
|
61
|
onChangetime = (_dates, dateStrings) => {
|
83
|
|
- daterange[1] = dateStrings[1]
|
84
|
|
- daterange[0] = dateStrings[0]
|
85
|
|
- }
|
86
|
|
-
|
87
|
|
- handleSubmit = (e, props) => {
|
88
|
|
-
|
89
|
|
- e.preventDefault();
|
90
|
|
-
|
|
62
|
+ daterange[0] = `${moment(dateStrings[0]).format('YYYY-MM-DDT00:00:00.000')}Z`
|
|
63
|
+ daterange[1] = `${moment(dateStrings[1]).format('YYYY-MM-DDT23:59:59.999')}Z`
|
91
|
64
|
}
|
92
|
65
|
|
|
66
|
+ //切换三个标签页
|
93
|
67
|
getDataOf = (days) => {
|
94
|
|
- this.setState({ endDate: new Date(), startDate: moment().subtract(days, 'day').toDate() })
|
|
68
|
+ this.getBarData(moment().subtract(days, 'day').toDate(),new Date())
|
|
69
|
+ this.getTableData(moment().subtract(days, 'day').toDate(),new Date(),this.state.buildingId)
|
|
70
|
+ this.setState({ ...this.state, endDate: new Date(), startDate: moment().subtract(days, 'day').toDate() })
|
95
|
71
|
}
|
96
|
72
|
|
|
73
|
+ //点击查询
|
97
|
74
|
datalist = () => {
|
98
|
|
- console.log()
|
|
75
|
+ this.getBarData(daterange[0] === undefined ? moment().subtract(7, 'day').toDate() : daterange[0],daterange[1] === undefined ? new Date() : daterange[1])
|
|
76
|
+ this.getTableData(daterange[0] === undefined ? moment().subtract(7, 'day').toDate() : daterange[0],daterange[1] === undefined ? new Date() : daterange[1],this.state.buildingId)
|
99
|
77
|
this.setState({
|
100
|
|
- endDate: daterange[1] === '' ? new Date() : daterange[1],
|
101
|
|
- startDate: daterange[0] === '' ? moment().subtract(7, 'day').toDate() : daterange[0],
|
|
78
|
+ ...this.state,
|
|
79
|
+ endDate: daterange[1] === undefined ? new Date() : daterange[1],
|
|
80
|
+ startDate: daterange[0] === undefined ? moment().subtract(7, 'day').toDate() : daterange[0],
|
102
|
81
|
})
|
|
82
|
+
|
103
|
83
|
}
|
104
|
|
-
|
105
|
|
- onSuccess = e => {
|
106
|
|
- this.setState({ dataSoures: e }, () => {
|
107
|
|
- this.onTabledatas(e)
|
108
|
|
- })
|
|
84
|
+
|
|
85
|
+ //切换楼盘信息
|
|
86
|
+ handleBuildingChange = (e) => {
|
|
87
|
+ this.getTableData(this.state.startDate,this.state.endDate,e)
|
|
88
|
+ this.setState({...this.state, buildingId: e})
|
109
|
89
|
}
|
110
|
90
|
|
111
|
|
- onTabledatas = (e) => {
|
112
|
|
- console.log('this.state.userType: ', this.state.userType)
|
113
|
|
- e.tdWxDicts.map(x => {
|
114
|
|
- columns = columns.filter(y => y.key != x.sceneType).concat({
|
115
|
|
- title: x.sceneAlias,
|
116
|
|
- dataIndex: x.sceneType,
|
117
|
|
- key: x.sceneType,
|
118
|
|
- })
|
119
|
|
- })
|
120
|
|
- const data = (e.list || []).reduce((acc, item) => {
|
121
|
|
- const { sceneType, fromNum, registeredNum, createTime } = item
|
122
|
|
- const num = this.state.userType === 'registered' ? registeredNum : fromNum
|
123
|
|
- acc[createTime] = { ...acc[createTime], ...item, [`${sceneType}`]: !num ? 0 : num }
|
124
|
|
- return acc
|
125
|
|
- }, {})
|
126
|
|
-
|
127
|
|
- const dictData = e.tdWxDicts.reduce((acc,item,index) => {
|
128
|
|
- const { sceneType } = item
|
129
|
|
- acc[sceneType] = 0
|
130
|
|
- return acc
|
131
|
|
- },{})
|
132
|
|
-
|
133
|
|
- const tableData = Object.keys(data).map(k => data[k]).reduce((acc,item,index) => {
|
134
|
|
- acc[index] = { ...dictData, ...item }
|
135
|
|
- return acc
|
136
|
|
- },[])
|
137
|
|
-
|
138
|
|
- this.setState({ tableData })
|
139
|
|
-
|
|
91
|
+ //排序
|
|
92
|
+ handleTableChange = (pagination, filters, sorter) => {
|
|
93
|
+ console.log(pagination, filters, sorter)
|
|
94
|
+ this.getTableData(this.state.startDate,this.state.endDate,this.state.buildingId,pagination.current,10,sorter.columnKey,sorter.order)
|
|
95
|
+ };
|
|
96
|
+
|
|
97
|
+ //导出
|
|
98
|
+ exportBuildingStats = () => {
|
|
99
|
+ request({ ...apis.stats.buildingExport, params: { startDate: this.state.startDate, endDate: this.state.endDate, buildingId: this.state.buildingId } })
|
|
100
|
+ .then(data => {
|
|
101
|
+ if (!data) {
|
|
102
|
+ return
|
|
103
|
+ }
|
|
104
|
+ const url = window.URL.createObjectURL(new Blob([data]))
|
|
105
|
+ const link = document.createElement('a')
|
|
106
|
+ link.style.display = 'none'
|
|
107
|
+ link.href = url
|
|
108
|
+ link.setAttribute('download', '项目统计.xlsx')
|
|
109
|
+ document.body.append(link)
|
|
110
|
+ link.click()
|
|
111
|
+ }).catch(() => {
|
|
112
|
+
|
|
113
|
+ })
|
140
|
114
|
}
|
141
|
115
|
|
142
|
|
- handleSelectChange = (e) => {
|
143
|
|
- this.setState({ userType: e }, () => {
|
144
|
|
- this.onTabledatas(this.state.dataSoures)
|
145
|
|
- })
|
|
116
|
+ //去详情页面
|
|
117
|
+ toDetailPage = (record) => {
|
|
118
|
+ router.push({
|
|
119
|
+ pathname: '/statistical/building/detail',
|
|
120
|
+ query: {
|
|
121
|
+ buildingId: record.buildingId,
|
|
122
|
+ buildingName: record.buildingName
|
|
123
|
+ },
|
|
124
|
+ });
|
146
|
125
|
}
|
147
|
126
|
|
148
|
|
-
|
149
|
127
|
render() {
|
|
128
|
+ const columns = [
|
|
129
|
+ {
|
|
130
|
+ title: '项目名称',
|
|
131
|
+ dataIndex: 'buildingName',
|
|
132
|
+ key: 'buildingName',
|
|
133
|
+ },
|
|
134
|
+ {
|
|
135
|
+ title: '新增客户',
|
|
136
|
+ dataIndex: 'khNum',
|
|
137
|
+ key: 'kh_num',
|
|
138
|
+ sorter: true,
|
|
139
|
+ },
|
|
140
|
+ {
|
|
141
|
+ title: '公客',
|
|
142
|
+ dataIndex: 'gkNum',
|
|
143
|
+ key: 'gk_num',
|
|
144
|
+ sorter: true,
|
|
145
|
+ },
|
|
146
|
+ {
|
|
147
|
+ title: '私客',
|
|
148
|
+ dataIndex: 'skNum',
|
|
149
|
+ key: 'sk_num',
|
|
150
|
+ sorter: true,
|
|
151
|
+ },
|
|
152
|
+ {
|
|
153
|
+ title: '访问人数',
|
|
154
|
+ dataIndex: 'uvNum',
|
|
155
|
+ key: 'uv_num',
|
|
156
|
+ sorter: true,
|
|
157
|
+ },
|
|
158
|
+ {
|
|
159
|
+ title: '访问次数',
|
|
160
|
+ dataIndex: 'pvNum',
|
|
161
|
+ key: 'pv_num',
|
|
162
|
+ sorter: true,
|
|
163
|
+ },
|
|
164
|
+ {
|
|
165
|
+ title: '详情',
|
|
166
|
+ render: (_, record) => (
|
|
167
|
+ <Button type="link" style={{ color: 'red' }} onClick={() => this.toDetailPage(record)}>查看详情</Button>
|
|
168
|
+ ),
|
|
169
|
+ },
|
|
170
|
+ ];
|
|
171
|
+
|
150
|
172
|
return (
|
151
|
|
- <>
|
152
|
|
- <div style={{
|
153
|
|
- backgroundColor: '#fff',
|
154
|
|
- padding: '32PX 28px',
|
155
|
|
- boxShadow: '0px 0px 16px 2px rgba(0,0,0,0.12)',
|
156
|
|
- borderRadius: '12px',
|
157
|
|
- minHeight: '60vh'
|
158
|
|
- }}>
|
159
|
|
- <Radio.Group buttonStyle="solid" defaultValue="a">
|
|
173
|
+ <div>
|
|
174
|
+ <Radio.Group buttonStyle="solid" defaultValue="a">
|
|
175
|
+ <Radio.Button value="c" onClick={() => this.getDataOf(0)}>今日</Radio.Button>
|
160
|
176
|
<Radio.Button value="a" onClick={() => this.getDataOf(7)}>最近7天</Radio.Button>
|
161
|
177
|
<Radio.Button value="b" onClick={() => this.getDataOf(30)}>最近1月</Radio.Button>
|
162
|
178
|
</Radio.Group>
|
|
@@ -166,24 +182,42 @@ class buildingStats extends React.Component {
|
166
|
182
|
Today: [moment(), moment()],
|
167
|
183
|
'This Month': [moment().startOf('month'), moment().endOf('month')],
|
168
|
184
|
}}
|
169
|
|
- // showTime
|
170
|
|
- // format="YYYY/MM/DD HH:mm:ss"
|
171
|
185
|
onChange={(_dates, dateStrings) => this.onChangetime(_dates, dateStrings)}
|
172
|
186
|
/>
|
173
|
187
|
<Button type="primary" htmlType="submit" style={{ marginLeft: '30px' }} onClick={() => this.datalist()}>
|
174
|
188
|
查询
|
175
|
189
|
</Button>
|
176
|
|
- <Button type="danger" onClick={() => router.go(-1)} style={{ marginBottom: '18px', marginLeft: '30px' }}>返回</Button>
|
177
|
|
- <div>
|
178
|
|
- <Select style={{ width: '180px' }} placeholder="所有用户" onChange={(e) => this.handleSelectChange(e)}>
|
179
|
|
- <Option value='all'>所有用户</Option>
|
180
|
|
- <Option value='registered'>注册用户</Option>
|
181
|
|
- </Select>
|
182
|
|
-
|
183
|
|
- <Table style={{marginTop:'20px'}} dataSource={this.state.tableData} columns={columns} pagination={false} scroll={{ y: 500 }}></Table>
|
184
|
|
- </div>
|
185
|
|
- </div>
|
186
|
|
- </>
|
|
190
|
+ <Button type="danger" onClick={() => router.go(-1)} style={{ marginBottom: '18px', marginLeft: '30px' }}>重置</Button>
|
|
191
|
+
|
|
192
|
+ <Row>
|
|
193
|
+ <Col span={12}>
|
|
194
|
+ <StatsChart title="项目公客排行" data={this.state.barData.gkBarMap} />
|
|
195
|
+ </Col>
|
|
196
|
+ <Col span={12}>
|
|
197
|
+ <StatsChart title="项目私客排行" data={this.state.barData.skBarMap} />
|
|
198
|
+ </Col>
|
|
199
|
+ </Row>
|
|
200
|
+ <Row>
|
|
201
|
+ <Col span={12}>
|
|
202
|
+ <StatsChart title="项目访问人数排行" subtext="项目详情访问情况" data={this.state.barData.wgBarMap} />
|
|
203
|
+ </Col>
|
|
204
|
+ <Col span={12}>
|
|
205
|
+ <StatsChart title="项目访问次数排行" subtext="项目详情访问情况,与上方时间筛选无关" data={this.state.barData.fwBarMap} />
|
|
206
|
+ </Col>
|
|
207
|
+ </Row>
|
|
208
|
+ <Row>
|
|
209
|
+ <Col span={22}>
|
|
210
|
+ <span style={{marginRight: '10px'}} >详细数据</span>
|
|
211
|
+ <BuildSelect slot='action' onChange={(e => this.handleBuildingChange(e))} value={this.state.buildingId}></BuildSelect>
|
|
212
|
+ </Col>
|
|
213
|
+ <Col span={2}>
|
|
214
|
+ <Button type="primary" onClick={this.exportBuildingStats}>导出</Button>
|
|
215
|
+ </Col>
|
|
216
|
+ </Row>
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+ <Table style={{marginTop:'20px'}} dataSource={this.state.tableData} columns={columns} pagination={{ total: this.state.total}} onChange={this.handleTableChange} scroll={{ y: 500 }}></Table>
|
|
220
|
+ </div>
|
187
|
221
|
)
|
188
|
222
|
}
|
189
|
223
|
}
|