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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
import create from 'dd-store'
import pageStore from './store';
import { checkFullScren } from "../../utils/checkFullScren";
import { modifySchedule, addSchedule, getUserScheduleInTime, getHomeUserSchedule } from '../../api/request.js'
// 传给组件 hList 水平排列 所有数据 comHListData
const comHListData = {
contactData: [
{ id: 'dd', text: '钉钉联系人', imageUrl: '../../assests/dingContact.png' },
{ id: 'outlook', text: '手动添加邮箱', imageUrl: '../../assests/emailContact.png' }
]
}
// 传给组件 comPopup 的数据
const comPopupData = {
popupTitle: '添加参会人',
popupShow: false
}
create.Page({
store: pageStore,
useAll: true,
data: {
$data: null,
scheduleItem: '',
conflictPeople: [],
// 登陆当前账户的人 权限
currentPeople: '',
comHListData: comHListData,
comPopupData: comPopupData,
isIPX: false
},
onLoad(event) {
this.reset()
if (event.scheduleItem) {
event.scheduleItem = decodeURIComponent(event.scheduleItem)
let scheduleItem = JSON.parse(event.scheduleItem)
this.setData({
scheduleItem: scheduleItem
})
let contactPeople = []
let contactPeopleId = []
for (let value of this.$store.data.participatorList) {
contactPeople.push(value)
contactPeopleId.push(value.userId)
}
this.store.data.contactPeople = contactPeople
this.store.data.contactPeopleId = contactPeopleId
this.update()
}
this.setData({
isIPX: checkFullScren(),
currentPeople: getApp().globalData.userid
})
},
onShow() {
this.getParticipatorLength()
this.conflictPeople()
},
// 添加参会人 钉钉选人
addParticipator() {
const _that = this
let require = []
let select = []
let outLookConcat = []
for (let participator of _that.$store.data.participatorList) {
if (participator.platform === 'outlook') {
outLookConcat.push(participator)
}
}
// 创建的 可选 必选
if (!_that.data.scheduleItem) {
select = _that.$store.data.participatorUserId
require = [getApp().globalData.userid]
}
// 编辑 发起人的可选必选
else if (this.$store.data.originalData.organizer === getApp().globalData.userid) {
select = _that.store.data.contactPeopleId
require = [getApp().globalData.userid]
}
// 编辑 参会人可选必选
else {
select = _that.store.data.contactPeopleId
require = [...this.$store.data.originUsersId]
}
select = _that.selectedelRequired([...require], [...select]).pickedUsers
dd.complexChoose({
title: "选择参会人", //标题
multiple: true, //是否多选
pickedUsers: select, //已选用户
requiredUsers: require, //必选用户(不可取消选中状态)
responseUserOnly: true, //返回人,或者返回人和部门
success: function (res) {
let people = []
let peopleId = []
if (!_that.data.scheduleItem || _that.$store.data.originalData.organizer === getApp().globalData.userid) {
people.push({ userId: getApp().globalData.userid, username: getApp().globalData.name, headUrl: getApp().globalData.avatar, platform: 'dingtalk' })
res.users.forEach((item, index) => {
people.push({ userId: item.userId, username: item.name, headUrl: item.avatar, platform: 'dingtalk' })
})
} else {
_that.$store.data.originUsers.forEach((item, index) => {
people.push(item)
})
res.users.forEach((item, index) => {
people.push({ userId: item.userId, username: item.name, headUrl: item.avatar, platform: 'dingtalk' })
})
}
people = _that.setArrary(people.concat(outLookConcat))
for (let value of people) {
peopleId.push(value.userId)
}
people = _that.setArrary(people.concat(outLookConcat))
// 创建
if (!_that.data.scheduleItem) {
_that.$store.data.participatorList = people
_that.$store.data.participatorUserId = peopleId
_that.update()
} else {
_that.store.data.contactPeople = people
_that.store.data.contactPeopleId = peopleId
_that.update()
}
},
fail: function (err) {
}
})
},
// 删除参会人
delParticipants(event) {
let userId = event.target.dataset.userId
let userIdList = []
let userList = []
if (!!this.data.scheduleItem) {
userList = this.store.data.contactPeople
userIdList = this.store.data.contactPeopleId
} else {
userList = this.$store.data.participatorList
userIdList = this.$store.data.participatorUserId
}
userList.forEach((item, index) => {
if (userId === item.userId) {
let people = [...userList]
people.splice(index, 1)
if (!!this.data.scheduleItem) {
this.store.data.contactPeople = people
} else {
this.$store.data.participatorList = people
}
this.update()
return
}
})
userIdList.forEach((item, index) => {
if (userId === item) {
let peopleId = [...userIdList]
peopleId.splice(index, 1)
if (!!this.data.scheduleItem) {
this.store.data.contactPeopleId = peopleId
} else {
this.$store.data.participatorUserId = peopleId
}
this.update()
return
}
})
this.getParticipatorLength()
this.conflictPeople()
},
// 编辑时候的保存
editSave() {
if (this.$store.data.originUsers != this.store.data.contactPeople) {
this.$store.data.updateInfo.isUpate = true
this.$store.data.updateInfo.updateType = 'operate_user'
this.$store.data.participatorList = this.store.data.contactPeople
this.$store.data.participatorUserId = this.store.data.contactPeopleId
this.update()
}
dd.navigateBack({
delta: 1
})
},
// 保存信息
saveInfo() {
this.editSave()
},
// 获取参会人长度
getParticipatorLength() {
const length = !!this.data.scheduleItem ? this.store.data.contactPeople.length : this.$store.data.participatorList.length
dd.setNavigationBar({
title: `参会人(${length}人)`
})
},
// 重置参会人
reset() {
this.store.data.contactPeople = []
this.store.data.contactPeopleId = []
this.update()
},
// 展示弹窗
showPopup() {
this.setData({
'comPopupData.popupShow': true
})
},
// 隐藏弹窗
closePopup() {
this.setData({
'comPopupData.popupShow': false
})
},
// 选择添加人员的方式
selectComHList(event) {
switch (event.currentTarget.dataset.item.id) {
// 选择dd加人
case "dd":
this.setData({
'comPopupData.popupShow': false
})
this.addParticipator()
break;
// 选择通过outlook添加邮箱联系人
case "outlook":
this.setData({
'comPopupData.popupShow': false
})
dd.navigateTo({ url: `./../outLookContact/outLookContact?scheduleItem=${encodeURIComponent(JSON.stringify(this.data.scheduleItem))}&toPage=participantsDetail` })
break;
}
},
// 选择弹窗
onSelectPopup(event) {
this.setData({
'conSelectPopupData.showSelectPopup': false,
'conSelectPopupData.selectPopupId': event.currentTarget.dataset.item.id,
'centerPopup.showCenterPopup': true
})
},
// 数组去重
setArrary(arr, userId) {
console.log(arr)
let containt = {}
for (let x of arr) {
containt['id' + x.userId] = x
}
return Object.values(containt)
},
// 会议冲突
conflictPeople() {
let users = []
let userIds = []
if (!!this.data.scheduleItem) {
users = this.store.data.contactPeople
} else {
users = this.$store.data.participatorList
}
for (let item of users) {
userIds.push(item.userId)
}
let data = {
startTime: this.$store.data.startTime.replace(/\//g, "-"),
endTime: this.$store.data.endTime.replace(/\//g, "-"),
userIds: userIds
}
getUserScheduleInTime(data).then(res => {
let conflictPeople = []
for (let value in res.data.data) {
if (!!this.data.scheduleItem) {
const arr = res.data.data[value].filter(function (item) {
return item.confirmAttendance === 1
})
if (arr.length > 1) {
conflictPeople.push(value)
}
} else {
const arr = res.data.data[value].filter(function (item) {
return item.confirmAttendance === 1
})
if (arr.length > 0) {
conflictPeople.push(value)
}
}
}
this.setData({
conflictPeople: conflictPeople
})
})
},
// 已选用户去中去掉必选用户
selectedelRequired([...req], [...pic]) {
for (let i = 0; i < req.length; i++) {
for (let m = 0; m < pic.length; m++) {
if (req[i] == pic[m]) {
pic.splice(m, 1)
m--;
}
}
}
return {
requiredUsers: req,
pickedUsers: pic
}
}
});