<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>
|