tag.js
8.58 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import { getCustomersList, exportLabelList } from '@/api/modules/tagsManage'
import { getStaffList } from '@/api/modules/clientManage'
export default {
data() {
return {
tagHeight: 0,
tagHeightStatus: false,
tagCheckItem: [],
allListParams: [],
crowdForm: {
crowdName: '',
crowdDesc: ''
}
}
},
mounted() {
this.getStaffList()
this.getCustomersListData()
},
watch: {
tagCheckItem: {
handler() {
if (this.tagCheckItem.length == 0) {
this.tagHeight = 0
}
this.allListParams = []
const tagNode = this.$common.utils.deepClone(this.tagCheckItem)
tagNode.forEach(group_item => {
group_item.children.forEach(label_item => {
if (label_item) {
this.allListParams.push({
groupId: group_item.id,
groupName: group_item.name,
groupType: group_item.labelType,
labelId: label_item.id,
labelName: label_item.name
})
}
})
})
this.getCustomersListData()
},
deep: true
},
tagHeight: {
handler(val) {
if (val == 0) {
setTimeout(() => {
this.tagHeightStatus = false
}, 300)
} else {
this.tagHeightStatus = true
}
},
deep: true
}
},
methods: {
//获取跟进员工
getStaffList() {
getStaffList({}).then(res => {
if (res.length == 0) {
return ''
}
const id = this.tagsPartFormList.findIndex(item => {
return item.name == 'followStaff'
})
const staff = res.map(item => {
return {
label: item.staffName,
value: item.staffName
}
})
staff.unshift({ label: '全部', value: '' })
this.$nextTick(() => {
this.tagsPartFormList[id].optionList = staff
})
})
},
tagLength(children) {
return children.filter(item => item).length
},
goDetail(scope) {
this.$router.push('/clientManage/clientDetail?id=' + scope.oneId)
},
jumpGroup() {
this.$router.push({
path: '/crowdManage/index',
query: {
selectTab: 1
}
})
},
//删除标签组
removeItem(index) {
this.tagCheckItem.splice(index, 1)
this.$refs.tagTree.getTreeNode(this.tagCheckItem)
},
treeScroll(id) {
const h = document.querySelector('.node_' + id).offsetTop
this.$refs.tagTree.handleScroll(h)
},
//获取选中的标签并排序
getCheckItem(item) {
const tree_id = []
const labelTree = this.$common.utils.deepClone(this.$refs.tagTree.labelTree)
labelTree.forEach(tree_node => {
tree_node.children.forEach(t_node => {
tree_id.push(t_node.id)
})
})
this.tagCheckItem = []
let group_all = item.getCheckedNodes().filter(item => item.labelType)
let group_Label = item.getCheckedNodes().filter(item => !item.children)
let label_id = []
group_Label.forEach(item => {
label_id.push(item.id)
})
let group_half = item.getHalfCheckedNodes().filter(item => item.labelType)
let group = [...group_half, ...group_all].sort((a, b) => {
return tree_id.indexOf(a.id) - tree_id.indexOf(b.id)
})
this.tagCheckItem = this.$common.utils.deepClone(group)
group.forEach((tag, idx) => {
tag.children.forEach((item, index) => {
if (!label_id.includes(item.id)) {
this.tagCheckItem[idx].children[index] = null
}
})
})
this.tagCheckItem.forEach(tag => {
tag.children = tag.children.filter(item => item)
})
},
//导出
handleExport() {
const params = {
...JSON.parse(JSON.stringify({ tagLists: this.allListParams })),
combineType: 2
}
exportLabelList(params).then(res => {
this.$Utils.exportFn(res)
})
},
//客户列表
getCustomersListData() {
if (this.searchForm.createTime) {
this.searchForm.beginTime = new Date(this.searchForm.createTime[0]).toLocaleDateString().replace(/-/g, '/')
this.searchForm.endTime = new Date(this.searchForm.createTime[1]).toLocaleDateString().replace(/-/g, '/')
}
delete this.searchForm.createTime
const tagLists = this.$common.utils.deepClone(this.allListParams)
this.userLoading = true
const params = {
...JSON.parse(JSON.stringify({ tagLists })),
...JSON.parse(JSON.stringify(this.searchForm)),
combineType: 2,
pageSize: this.$refs.viewCustomers.page.pageSize,
pageNum: this.$refs.viewCustomers.page.pageNum
}
getCustomersList(params)
.then(res => {
this.userLoading = false
this.tableData = res.data
this.tableTotal = res.count
this.$nextTick(() => {
if (tagLists.length == 0) {
document.querySelector('.noDataText').innerText = '当前未选择标签,快去选择标签查看客户吧!'
} else {
document.querySelector('.noDataText') ? (document.querySelector('.noDataText').innerText = '暂无数据') : ''
}
})
if (this.tableData == 0) {
this.$refs.viewCustomers.setTableHeightFun()
} else {
this.$refs.viewCustomers.tableHeightValues = ''
}
})
.catch(err => {
this.userLoading = false
})
},
//创建人群
groupConfirmDialog() {
if (this.tagCheckItem.length == 0) {
this.$message.error('必须选择一个标签')
return
}
if (!this.crowdForm.crowdName) {
this.$message.error('请输入人群名称')
return
}
const tagCombine = this.allListParams.reduce((prev, cur) => {
const index = prev.findIndex(group => cur.groupId == group.groupId)
if (index == -1) {
return prev.concat({ groupId: cur.groupId, labelIdList: [cur.labelId] })
} else {
prev[index].labelIdList.push(cur.labelId)
return prev
}
}, [])
const params = {
'req.merchantId': this.merchantId,
'req.crowdType': 2, //类型 1-推荐 2-自定义
'req.crowdName': this.crowdForm.crowdName,
'req.crowdDesc': this.crowdForm.crowdDesc,
'req.tagCombine': JSON.stringify(tagCombine)
}
this.$apis.crowdManage
.addCrowd(params)
.then(res => {
if (res.data.code == 0) {
this.groupVisible = false
this.successVisible = true
} else {
this.$message({
type: 'error',
message: res.data.message
})
}
})
.catch(err => {
this.$message({
type: 'error',
message: err.message
})
})
}
}
}