<template>
|
<div class="container2">
|
<div class="title" v-if="!editId">
|
新建日历记事
|
<span class="back" @click="back" v-if="showBack"> <i class="iconfont icon-fanhui"></i> 返回 </span>
|
</div>
|
<div class="title" v-else>
|
<span>修改日历记事</span>
|
<span class="back" @click="back" v-if="showBack"> <i class="iconfont icon-fanhui"></i> 返回 </span>
|
</div>
|
|
<div class="wrap">
|
<el-row>
|
<el-col :lg="16" :md="20" :sm="24" :xs="24">
|
<el-form :model="calendarHoliday" status-icon ref="form" label-width="auto" @submit.prevent :rules="rules">
|
<el-form-item label="标题" prop="title">
|
<el-input placeholder="请输入标题" v-model="calendarHoliday.title"></el-input>
|
</el-form-item>
|
|
<el-form-item label="日历时间" prop="date_range">
|
<el-date-picker
|
v-model="calendarHoliday.date_range"
|
type="daterange"
|
range-separator="到"
|
start-placeholder="开始时间"
|
end-placeholder="结束时间"
|
format="YYYY-MM-DD"
|
value-format="YYYY-MM-DD"
|
/>
|
</el-form-item>
|
<el-form-item label="类型" prop="type">
|
<el-select v-model="calendarHoliday.type" placeholder="类型" clearable filterable>
|
<el-option v-for="item in calendarTypeList" :key="item.value" :label="item.label" :value="item.value" />
|
</el-select>
|
</el-form-item>
|
|
<el-form-item class="submit">
|
<el-button type="primary" @click="submitForm">保 存</el-button>
|
<el-button @click="resetForm">重 置</el-button>
|
</el-form-item>
|
</el-form>
|
</el-col>
|
</el-row>
|
</div>
|
</div>
|
</template>
|
|
<script>
|
import { reactive, ref, onMounted, computed } from 'vue'
|
import { ElMessage } from 'element-plus'
|
import Calendar from '@/model/calendar'
|
import CalendarHoliday from '@/model/calendarHoliday'
|
import SysDictItemModel from '@/model/sysDictItem'
|
import dayjs from 'dayjs'
|
|
export default {
|
components: {},
|
props: {
|
editId: {
|
type: String,
|
default: null,
|
},
|
showBack: {
|
type: Boolean,
|
default: true,
|
},
|
pointDate: {
|
type: String,
|
default: null,
|
},
|
},
|
setup(props, context) {
|
const form = ref(null)
|
const loading = ref(false)
|
const business_content = ref(null)
|
const calendarTypeList = ref([])
|
|
const calendarHoliday = reactive({
|
id: '',
|
title: '',
|
date_range: [],
|
start_date: '',
|
type: '',
|
end_date: '',
|
})
|
|
const listAssign = (a, b) => Object.keys(a).forEach(key => {
|
a[key] = b[key] || a[key]
|
})
|
|
/**
|
* 表单规则验证
|
*/
|
const { rules } = getRules()
|
|
onMounted(() => {
|
if (props.editId) {
|
getCalendarHoliday()
|
}
|
if (props.pointDate) {
|
const tmp_date_range = []
|
tmp_date_range.push(props.pointDate)
|
tmp_date_range.push(props.pointDate)
|
calendarHoliday.date_range = tmp_date_range
|
}
|
|
loadDictDitems()
|
})
|
|
// 根据字典类型查询字典
|
const loadDictDitems = async () => {
|
calendarTypeList.value = await SysDictItemModel.getSysDictItemListByType('calendar_type')
|
}
|
|
const getCalendarHoliday = async () => {
|
loading.value = true
|
const res = await CalendarHoliday.getCalendarHoliday(props.editId)
|
|
listAssign(calendarHoliday, res)
|
calendarHoliday.value = res
|
|
const tmp_date_range = []
|
tmp_date_range.push(res.start_date)
|
tmp_date_range.push(res.end_date)
|
|
calendarHoliday.value.date_range = tmp_date_range
|
calendarHoliday.date_range = tmp_date_range
|
|
calendarHoliday.type = `${res.type}`
|
|
loading.value = false
|
}
|
|
// 重置表单
|
const resetForm = () => {
|
form.value.resetFields()
|
}
|
|
const submitForm = async formName => {
|
form.value.validate(async valid => {
|
if (valid) {
|
let res = {}
|
calendarHoliday.start_date = calendarHoliday.date_range[0]
|
calendarHoliday.end_date = calendarHoliday.date_range[1]
|
if (props.editId) {
|
res = await CalendarHoliday.editCalendarHoliday(props.editId, calendarHoliday)
|
context.emit('editClose')
|
} else {
|
res = await CalendarHoliday.createCalendarHoliday(calendarHoliday)
|
resetForm(formName)
|
if (props.editId) {
|
context.emit('editClose')
|
}
|
}
|
if (res.code < window.MAX_SUCCESS_CODE) {
|
ElMessage.success(`${res.message}`)
|
}
|
} else {
|
console.error('error submit!!')
|
ElMessage.error('请将信息填写完整')
|
}
|
})
|
}
|
|
const back = () => {
|
context.emit('editClose')
|
}
|
|
const handleContentChange = val => {
|
calendarHoliday.business_content = val
|
}
|
|
return {
|
back,
|
calendarHoliday,
|
form,
|
rules,
|
resetForm,
|
submitForm,
|
|
business_content,
|
handleContentChange,
|
calendarTypeList,
|
}
|
},
|
}
|
|
/**
|
* 表单验证规则
|
*/
|
function getRules() {
|
/**
|
* 验证回调函数
|
*/
|
const checkInfo = (rule, value, callback) => {
|
if (!value) {
|
callback(new Error('信息不能为空'))
|
}
|
callback()
|
}
|
const rules = {
|
title: [{ message: '标题不能为空', trigger: 'blur', required: true }],
|
date_range: [{ message: '日历时间不能为空', trigger: 'blur', required: true }],
|
type: [{ message: '日历类型不能为空', trigger: 'blur', required: true }],
|
}
|
return { rules }
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
.container2 {
|
.title {
|
width: 100%;
|
height: 59px;
|
line-height: 59px;
|
color: $parent-title-color;
|
font-size: 16px;
|
font-weight: 500;
|
text-indent: 40px;
|
border-bottom: 1px solid #dae1ec;
|
|
.back {
|
float: right;
|
margin-right: 40px;
|
cursor: pointer;
|
}
|
}
|
|
.wrap {
|
padding: 20px;
|
width: 100%;
|
}
|
|
.submit {
|
float: left;
|
}
|
}
|
</style>
|