TabContentRealGroupData.vue
6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<script>
import ChartBar from '@/components/ChartBar'
import ChartLine from '@/components/ChartLine'
import { getRealCnt, getRealCntMember } from '@/api/operateCenter/groupAnalysis'
import { getList as getGroupList } from '@/api/customer/group'
export default {
name: '',
components: { ChartLine, ChartBar },
props: {
type: {
type: String,
default: '',
},
},
data() {
return {
loading: { customerGroup: false, customerGroupMember: false },
timeRange: 7,
// 日期范围
dateRange: [],
dialogVisible: false,
dialogType: 'customerGroup',
// 群聊
groupChats: [],
// 查询参数
query: {
chatIds: '',
ownerIds: '',
beginTime: undefined,
endTime: undefined,
},
legend: {
customerGroup: ['新增客群数', '解散客群数'],
customerGroupMember: ['新增客群成员数', '流失客群成员数'],
},
// 选择人员
selectUsers: {
customerGroup: [],
customerGroupMember: [],
},
customerGroup: {
xData: [],
series: [],
},
customerGroupMember: {
xData: [],
series: [],
},
}
},
computed: {},
watch: {},
created() {
this.setTime(7)
},
mounted() {},
methods: {
getList(type) {
this.query.beginTime = this.dateRange && this.dateRange[0]
this.query.endTime = this.dateRange && this.dateRange[1]
let selectUsers = this.selectUsers[type]
if (Array.isArray(selectUsers)) {
this.query.ownerIds = selectUsers.map((e) => e.userId).join(',')
} else {
this.query.ownerIds = ''
}
this.loading[type] = true
let api = { customerGroup: getRealCnt, customerGroupMember: getRealCntMember }
api[type](this.query)
.then(({ rows }) => {
this[type].series = []
this[type].xData = rows.map((e) => e.xtime)
this[type].series.push(rows.map((e) => e.addCnt))
type === 'customerGroup' && this[type].series.push(rows.map((e) => e.dissolveCnt))
type === 'customerGroupMember' && this[type].series.push(rows.map((e) => e.quitCnt))
})
.catch((error) => {
console.error(error)
})
.finally(() => {
this.loading[type] = false
})
},
getGroupList(params) {
getGroupList(params)
.then(({ rows }) => {
this.groupChats = rows
})
.catch((e) => {
console.error(e)
})
},
getTime(datePar) {
const d = datePar ? new Date(datePar) : new Date()
d.setMinutes(d.getMinutes() - d.getTimezoneOffset())
return d.toJSON().substr(0, 10)
},
setTime(days) {
this.timeRange = days
if (days) {
let date = new Date()
date.setDate(date.getDate() - days)
this.dateRange = [this.getTime(date), this.getTime()]
this.getList('customerGroup')
this.getList('customerGroupMember')
} else {
this.dateRange = null
}
},
showDialog(type) {
this.dialogType = type
this.dialogVisible = true
},
getSelectUser(data) {
this.selectUsers[this.dialogType] = data
this.query[this.dialogType] = data.map((e) => e.userId).join(',')
if (this.dialogType === 'customerGroupMember') {
this.query.chatIds = ''
this.getGroupList({
userIds: this.query[this.dialogType],
})
}
this.getList(this.dialogType)
},
},
}
</script>
<template>
<div>
<div class="operation">
<el-button-group>
<el-button type="primary" :plain="timeRange != 7" @click="setTime(7)">近一周</el-button>
<el-button type="primary" :plain="timeRange != 30" @click="setTime(30)">近一月</el-button>
<el-button type="primary" :plain="!!timeRange" @click="setTime()">自定义</el-button>
</el-button-group>
<el-date-picker
v-if="!timeRange"
v-model="dateRange"
class="ml20"
style="width: 260px"
value-format="yyyy-MM-dd"
type="daterange"
:clearable="false"
range-separator="-"
start-placeholder="开始日期"
end-placeholder="结束日期"
@change="
getList('customerGroup')
getList('customerGroupMember')
"></el-date-picker>
</div>
<el-row :gutter="10">
<el-col :span="12">
<div>
<el-input
style="width: 180px"
:value="selectUsers['customerGroup'].map((e) => e.name) + ''"
readonly
@focus="showDialog('customerGroup')"
placeholder="请选择群主" />
</div>
<ChartLine
v-loading="loading.customerGroup"
:xData="customerGroup.xData"
:legend="legend['customerGroup']"
:series="customerGroup.series"></ChartLine>
</el-col>
<el-col :span="12">
<div>
<el-input
style="width: 180px"
:value="selectUsers['customerGroupMember'].map((e) => e.name) + ''"
readonly
@focus="showDialog('customerGroupMember')"
placeholder="请选择群主" />
<el-select
style="margin-left: 20px"
v-model="query.chatIds"
placeholder="请选择群聊"
clearable
@change="getList('customerGroupMember')">
<el-option
v-for="item in groupChats"
:key="item.chatId"
:label="item.groupName"
:value="item.chatId"></el-option>
</el-select>
</div>
<ChartLine
v-loading="loading.customerGroupMember"
:xData="customerGroupMember.xData"
:legend="legend['customerGroupMember']"
:series="customerGroupMember.series"></ChartLine>
</el-col>
</el-row>
<SelectWeUser
:visible.sync="dialogVisible"
title="组织架构"
:defaultValues="selectUsers[dialogType]"
@success="getSelectUser"
:isOnlyLeaf="true"></SelectWeUser>
</div>
</template>
<style lang="scss" scoped></style>