<template>
|
<view class="page-calendar-add">
|
<view class="uni-panel-content items-center">
|
<form class="calendar-form">
|
<view class="uni-panel-body">
|
<view class="uni-panel-h">
|
<text class="uni-panel-calendar-name">名称:</text>
|
<view class="uni-panel-calendar-value">
|
<input class="input" :focus="formData.name" name="name" comfirm-type="done" type="text"
|
v-model="form.name" placeholder="请输入日历名称" />
|
</view>
|
</view>
|
<view class="uni-panel-h">
|
<text class="uni-panel-calendar-name">类型:</text>
|
<view class="uni-panel-calendar-value" @click="clickCalendarType">
|
<text class="uni-panel-text">{{typeArray[form.type]}}</text>
|
<view class="uni-picker-input">{{ '. . .'}}</view>
|
</view>
|
</view>
|
<view class="uni-panel-h">
|
<text class="uni-panel-calendar-name"></text>
|
<label class="uni-panel-calendar-value">
|
<switch :checked="form.isDefault" color="#007aff" style="transform:scale(0.8)"
|
@change="changeCalendarDefault" />缺省日历
|
</label>
|
</view>
|
</view>
|
<view class="button-clz">
|
<button class="uni-panel-button" @click="submitForm">提交</button>
|
</view>
|
</form>
|
|
</view>
|
<view class="uni-panel-safe-bottom" :style="{height:safeAreaBottom + 'px'}" />
|
</view>
|
|
</template>
|
|
<script>
|
import Session from "@/common/utils.js"
|
import {
|
create as calendarCreate,
|
|
} from "@/api/gungho/calendar.js"
|
|
import {
|
showModal,
|
showToast,
|
showLoading,
|
hideLoading
|
} from "@/common/Page.js"
|
export default {
|
name: "pageCalendarAdd",
|
data() {
|
return {
|
safeAreaBottom: getApp().globalData.safeAreaBottom,
|
form: {
|
name: "",
|
type: 0,
|
isDefault: false,
|
},
|
formData: {
|
nameFocus: false,
|
typeFocus: false
|
},
|
typeArray: ['常规(上级可见)', '公开', '私密'],
|
}
|
},
|
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];
|
});
|
});
|
},
|
clickCalendarType() {
|
const _this = this
|
uni.showActionSheet({
|
itemList: _this.typeArray,
|
success: function(res) {
|
let value = res.tapIndex;
|
if (value < 3 && value >= 0) {
|
_this.form.type = value
|
}
|
},
|
fail: function(res) {
|
console.log(res.errMsg);
|
}
|
})
|
},
|
changeCalendarDefault(evt) {
|
let checked = evt.detail.value;
|
this.form.isDefault = checked
|
},
|
submitForm() {
|
var _this = this
|
let name = _this.form.name.trim()
|
if (name.length < 1) {
|
_this.formData.nameFocus = true
|
showToast("日历名称不能为空!", "none")
|
uni.pageScrollTo({
|
scrollTop: 0
|
})
|
return
|
}
|
let year = new Date().getFullYear()
|
showLoading("创建中,请稍后...")
|
calendarCreate({
|
type: this.form.type,
|
isDefault: this.form.isDefault ? "1": "",
|
name
|
}).then((res) => {
|
hideLoading()
|
showToast("新建日历成功", "success")
|
uni.$emit('calendarListChange')
|
uni.navigateBack()
|
}).catch((rej) => {
|
hideLoading()
|
console.log("calendar-add calendarCreate 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
|
}
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
@import "../../common/css/button.scss";
|
|
.page-calendar-add {
|
display: flex;
|
width: 750rpx;
|
height: 100vh;
|
flex-direction: column;
|
|
.justify-center {
|
justify-content: center;
|
}
|
|
.items-center {
|
align-items: center
|
}
|
|
|
|
.uni-panel-content {
|
display: flex;
|
flex: 1;
|
width: 750rpx;
|
}
|
|
.calendar-form {
|
display: flex;
|
width: 98%;
|
flex: 1;
|
padding: 4px 1% 8px;
|
overflow: auto;
|
flex-direction: column;
|
}
|
|
.uni-panel-h {
|
display: flex;
|
flex-direction: row !important;
|
align-items: center !important;
|
padding: 12px 10px 12px 12px;
|
font-size: 14px;
|
}
|
|
.uni-panel-body {
|
display: flex;
|
flex-direction: column;
|
margin: 8px 12px;
|
padding: 4px 4px;
|
border-radius: 8px;
|
}
|
|
.uni-panel-calendar-name {
|
display: flex;
|
margin: 0px 4px;
|
width: 60px;
|
}
|
|
.uni-panel-calendar-value {
|
flex: 1;
|
display: flex;
|
margin: 0px 4px;
|
}
|
|
.uni-panel-text {
|
flex: 1;
|
color: #000000;
|
font-weight: normal;
|
padding: 0 5px;
|
line-height: 28px;
|
}
|
|
.uni-picker-input {
|
height: 50rpx;
|
padding: 0px 4px;
|
line-height: 50rpx;
|
font-size: 30rpx;
|
background: #FFF;
|
text-align: right;
|
color: #007aff;
|
flex: 1;
|
}
|
|
.button-clz {
|
display: flex;
|
justify-content: center;
|
width: 100%;
|
font-size: 17px !important;
|
margin-top: 8px;
|
margin-bottom: 8px;
|
border-radius: 0px;
|
}
|
|
.uni-panel-button {
|
flex: 1;
|
border-radius: 12px;
|
margin: 5px 12px 16px;
|
background-color: #00aaff;
|
color: #fff;
|
}
|
|
.uni-panel-bottom {
|
display: flex;
|
justify-content: flex-end;
|
align-items: flex-end;
|
min-height: 20px;
|
padding: 8px 12px;
|
font-size: 14px;
|
}
|
}
|
</style>
|