cuiqian2004
9 天以前 2db331628bbf94deee446d6e172e98f4db474a33
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<template>
 
    <view class="page-calendar-set">
        <view class="uni-panel-content">
            <view v-for="(item,index) in calendarLst" class="uni-panel-calendar-item"
                :class="item.IsDefault ? 'uni-panel-item-default' : ''" :key="item.ID">
                <view class="uni-panel-item-title">
                    <view class="uni-panel-item">
                        <text class="uni-panel-item-ico fs-calendar"></text>
                        <text class="uni-panel-item-text">{{item.Name}}</text>
                    </view>
                    <view class="uni-panel-item-right" @click="clickShowShareUser(item)">
                        <text class="uni-panel-button" @click.prevent.stop="clickSetDefault(item)">设置默认日历</text>
                        <text class="blue-text uni-panel-right-icon uni-panel-max-icon"
                            :class="item.HasShare ? 'fs-user_group' : 'fs-person4'" />
                    </view>
                </view>
                <view class="uni-panel-item-share" v-if="item.expand">
                    <view class="uni-panel-h">日历共享给:</view>
                    <view class="uni-panel-share-user uni-panel-h">
                        <view v-for="(user,index2) in item.ShareUsers || []" class="uni-panel-user-item"
                            :key="user.Login" @longpress="clickRemoveShareUser(item,user)">
                            <image :src="user.Img" @error="imageShareUserError(index,item,user)" />
                            <text>{{user.Name}}</text>
                        </view>
                        <text class="uni-panel-share-text" v-if="(item.ShareUsers || []).length == 0">
                            还没有共享给任何人
                        </text>
                        <text
                            :class="(item.ShareUsers || []).length > 0 ? 'uni-panel-share-add' :'uni-panel-share-no-add'"
                            class="fs-CirclPlus blue-text" @click="clickAddShareUser(item)"></text>
                    </view>
                </view>
            </view>
        </view>
        <view class="uni-panel-safe-bottom" :style="{height:safeAreaBottom + 'px'}" />
    </view>
</template>
 
<script>
    import Session from "@/common/utils.js"
    import {
        list as calendarList,
        shareRemove as calendarShareRemove,
        shareAdd as calendarShareAdd,
        shareGet as calendarShareGet,
        update as calendarUpdate,
    } from "@/api/gungho/calendar.js"
 
    import {
        showModal,
        showToast,
        showLoading,
        hideLoading
    } from "@/common/Page.js"
    export default {
        name: "pageCalendarSet",
        data() {
            return {
                safeAreaBottom: getApp().globalData.safeAreaBottom,
                options: {},
                calendarLst: [],
                selCalendarID: "",
                defaultUserPhoto: getApp().globalData.defaultuserphoto
            }
        },
        methods: {
            setData: function(obj) {
                let that = this;
                let keys = [];
                let val, data;
 
                Object.keys(obj).forEach(function(key) {
                    keys = key.split(".");
                    val = obj[key];
                    data = that.$data;
                    keys.forEach(function(key2, index) {
                        if (index + 1 == keys.length) {
                            that.$set(data, key2, val);
                        } else {
                            if (!data[key2]) {
                                that.$set(data, key2, {});
                            }
                        }
                        data = data[key2];
                    });
                });
            },
            loadCalendarList() {
                var _this = this
                let year = new Date().getFullYear()
                showLoading("加载中,请稍后...")
                calendarList().then((res) => {
                    _this.setData({
                        calendarLst: res || []
                    })
                    hideLoading()
                }).catch((rej) => {
                    _this.setData({
                        calendarLst: []
                    })
                    hideLoading()
                    console.log("calendarList catch", rej)
                })
            },
            clickSetDefault(item) {
                const _this = this
                calendarUpdate({
                    id: item.ID,
                    type: item.Type || "0",
                    order: item.Order || "1",
                    name: item.Name || "",
                    isDefault: '1'
                }).then((res) => {
                    let curIndex = _this.calendarLst.findIndex((item2, index, arr) => {
                        return item2.IsDefault;
                    })
                    showToast("设置默认日历成功", "success")
                    if (curIndex < 0) {
                        return
                    }
                    _this.calendarLst[curIndex].IsDefault = false
                    item.IsDefault = true
 
                }).catch((rej) => {
                    console.log("setDefaultCalendar failed", rej)
                    showModal(rej, "出错", false)
                })
            },
            clickShowShareUser(item) {
                if (item.expand)
                    item.expand = false
                else
                    item.expand = true
                const app = getApp()
                if (!item.ShareUsers) {
                    calendarShareGet(item.ID).then((res) => {
                        const list = res || []
                        const users = []
                        if (list.length > 0) {
                            list.forEach(function(user) {
                                user.Img = `${app.globalData.apiurl.org}/userphoto?login=${user.Login}`;
    
                            })
                        } 
                        item.ShareUsers =list
                    }).catch((rej) => {
                        item.ShareUsers = []
                        console.log("calendarShareGet catch", rej)
                    })
 
                }
 
            },
            imageShareUserError(index, item, user) {
                user.Img = getApp().globalData.defaultuserphoto
                this.$set(this.calendarLst, index, item)
            },
            clickRemoveShareUser(item, user) {
                calendarShareRemove(item.ID, user.Login).then((res) => {
                    let curIndex = item.ShareUsers.findIndex((item2, index, arr) => {
                        return item2.Login == user.Login;
                    })
                    if (curIndex < 0) {
                        return
                    }
                    item.ShareUsers.splice(curIndex,1)
                    showToast("删除日历分享成功", "success")
                }).catch((rej) => {
                    console.log("calendarShareRemove failed", rej)
                    showModal(rej, "出错", false)
                })
            },
            clickAddShareUser(item) {
                const _this = this
                this.selCalendarID = item.ID
                uni.navigateTo({
                    url: "/pages/org/selpsn?multiselect=true&title=日历分享给",
                    events: {
                        selPsnOk: function(data) {
                            _this.getBackUser(data)
                        }
                    }
                })
            },
 
            getBackUser(data) {
                const _this = this
                setTimeout(() => {
                    _this.addCalendarShare(data)
                }, 10)
 
            },
            addCalendarShare(users) {
                const _this = this
                const shareUsers = []
                const app = getApp()
                if (users.length > 0) {
                    let curIndex = _this.calendarLst.findIndex((item2, index, arr) => {
                        return item2.ID == _this.selCalendarID;
                    })
                    if (curIndex < 0) {
                        return
                    }
                    const calendarItem = _this.calendarLst[curIndex]
                    const list = calendarItem.ShareUsers || []
                    users.forEach(function(item) {
 
                        let curIndex = list.findIndex((item2, index, arr) => {
                            return item2.Login == item.login;
                        })
                            console.log(users)
                        if (curIndex < 0) {
                            shareUsers.push({
                                login: item.login,
                                name: item.name
                            })
                        }
 
                    })
                    if (shareUsers.length > 0) {
                        calendarShareAdd({
                            id: _this.selCalendarID,
                            users: shareUsers
                        }).then((res) => {
                            shareUsers.forEach(function(item) {
                                list.push({
                                    Login: item.login,
                                    Name: item.name,
                                    Img :`${app.globalData.apiurl.org}/userphoto?login=${item.login}`,
                                })
                            })
                            calendarItem.ShareUsers = list
                            showToast("日历分享成功", "success")
                        }).catch((rej) => {
                            console.log("calendarShareAdd failed", rej)
                            showModal(rej, "出错", false)
                        })
                    }
 
                }
 
            },
            showError(ex) {
                let tip = typeof ex == 'string' ? ex : typeof ex.err_msg == 'string' ? ex.err_msg : typeof ex.errMsg ==
                    'string' ? ex.errMsg : ""
                showModal(tip, "提示", false)
            },
        },
        onLoad(option) {
            // #ifdef MP-DINGTALK
 
            my.setNavigationBar({
                backgroundColor: "#007AFF",
                frontColor: "#ffffff"
            })
            // #endif
            this.loadCalendarList()
        }
    }
</script>
 
<style lang="scss" scoped>
    @import "../../common/css/button.scss";
 
    page {
        background-color: #e5eaee;
        height: calc(100vh - 10px);
    }
 
    .page-calendar-set {
 
        display: flex;
        width: 750rpx;
        height: 100vh;
        flex-direction: column;
        background-color: #e5eaee;
 
        .justify-center {
            justify-content: center;
        }
 
        .items-center {
            align-items: center
        }
 
        .uni-panel-content {
            display: flex;
            flex: 1;
            width: 100%;
            padding: 8px 0;
            overflow: auto;
            flex-direction: column;
            height: calc(100% - 64px);
        }
 
        .uni-panel-item-default {
            border-left: 5px solid #ff9900;
        }
 
        .uni-panel-calendar-item {
            display: flex;
            flex-direction: column;
            // width: calc( 750rpx - 30px );
            margin: 5px 10px;
            background-color: white;
            border-radius: 8px;
            padding: 5px;
 
            .uni-panel-button {
                display: flex;
                border-radius: 5px;
                margin: 5px 8px;
                padding: 0 5px;
                font-size: 14px;
                background-color: #00aaff;
                color: #fff;
                line-height: 27px;
                height: 27px;
            }
        }
 
        .uni-panel-item-title {
            width: 100%;
            display: flex;
            flex-direction: row;
            padding: 5px 0;
        }
 
        .uni-panel-item {
            width: 100%;
            flex: 1;
 
            .uni-panel-item-ico {
                // display: flex;
                margin: 4px 8px 4px 4px;
                font-size: 16px;
                color: #333;
                line-height: 32px;
            }
 
            .uni-panel-item-text {
                // display: flex;
                margin: 4px 8px 4px 4px;
                font-size: 14px;
                line-height: 32px;
            }
 
 
        }
 
        .blue-text {
            color: #00aaff;
        }
 
        .yellow-text {
            color: #ff9900;
        }
 
        .uni-panel-h {
            margin-top: 8px;
        }
 
        .uni-panel-item-share {
            width: 100%;
            display: flex;
            flex-direction: column;
            padding: 4px 8px;
            font-size: 14px;
            border-top: 1px solid #f0f0f0;
 
            .uni-panel-share-user {
                display: flex;
                width: 100%;
                flex-direction: row;
                flex-wrap: wrap;
            }
 
            .uni-panel-user-item {
                margin: 4px;
                display: flex;
                flex-direction: column;
                height: 50px;
                width: 50px;
            }
 
            .uni-panel-user-item image {
                margin: 2px 8px;
                height: 32px;
                width: 32px;
                border-radius: 16px;
            }
 
            .uni-panel-user-item text {
                width: 50px;
                height: 18px;
                text-align: center;
                font-size: 12px;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: clip;
            }
 
            .uni-panel-share-no-add {
 
                font-size: 24px;
                line-height: 30px;
                margin: 4px;
            }
 
            .uni-panel-share-add {
                font-size: 24px;
                line-height: 50px;
                margin: 4px;
            }
 
            .uni-panel-share-text {
                line-height: 30px;
            }
        }
 
        .uni-panel-item-right {
            display: flex;
            flex-direction: row;
            height: 32px;
            padding: 0px 4px;
            text-align: right;
 
        }
 
        .uni-panel-icon {
            padding: 4px 6px;
            color: #999999;
            font-weight: normal;
            transition-duration: 0s;
            font-size: 20px;
            transition-property: transform;
        }
 
        .uni-panel-max-icon {
            font-size: 36px;
        }
 
        .button-clz {
            display: flex;
            width: 100%;
            flex-direction: row;
            font-size: 17px !important;
            margin-top: 8px;
            margin-bottom: 8px;
            border-radius: 0px;
        }
 
        .uni-panel-bottom {
            display: flex;
            justify-content: flex-end;
            align-items: flex-end;
            min-height: 20px;
            padding: 8px 12px;
            font-size: 14px;
 
            .uni-panel-button {
                width: 100%;
                border-radius: 12px;
                margin: 5px 12px 16px;
                background-color: #00aaff;
                color: #fff;
            }
        }
 
    }
</style>