2020-12-17 13:19:12 +08:00
|
|
|
<template>
|
|
|
|
<el-dialog
|
2020-12-22 10:48:11 +08:00
|
|
|
:title="title"
|
2020-12-17 13:19:12 +08:00
|
|
|
:visible.sync="dialogVisible"
|
|
|
|
width="30%"
|
|
|
|
:before-close="handleClose"
|
|
|
|
>
|
|
|
|
<el-form ref="form" :model="form" :rules="rules" label-width="120px">
|
|
|
|
<el-form-item label="留言板名称:" prop="title">
|
|
|
|
<el-input v-model="form.title" style="width: 200px;" />
|
|
|
|
</el-form-item>
|
|
|
|
<el-form-item label="归属项目:" prop="project">
|
2020-12-22 10:48:11 +08:00
|
|
|
<el-select v-model="form.project" :disabled="update" placeholder="请选择">
|
2020-12-17 13:19:12 +08:00
|
|
|
<el-option
|
|
|
|
v-for="item in projectOptionList"
|
|
|
|
:key="item.value"
|
|
|
|
:label="item.label"
|
|
|
|
:value="item.value"
|
|
|
|
/>
|
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
|
|
|
</el-form>
|
|
|
|
<span slot="footer" class="dialog-footer">
|
|
|
|
<el-button @click="handleClose">取 消</el-button>
|
2020-12-22 10:48:11 +08:00
|
|
|
<el-button v-if="!update" type="primary" @click="commit">确 定</el-button>
|
|
|
|
<el-button v-if="update" type="primary" @click="updateCommit">修 改</el-button>
|
2020-12-17 13:19:12 +08:00
|
|
|
</span>
|
|
|
|
</el-dialog>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-12-22 10:48:11 +08:00
|
|
|
import { createPost, updatePost } from '@/api/learn';
|
2020-12-17 13:19:12 +08:00
|
|
|
export default {
|
|
|
|
name: 'Create',
|
|
|
|
props:{
|
|
|
|
projectOptionList:{
|
|
|
|
type: Array,
|
|
|
|
default() {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
dialogVisible: false,
|
2020-12-22 10:48:11 +08:00
|
|
|
postId: '',
|
2020-12-17 13:19:12 +08:00
|
|
|
form:{
|
|
|
|
title: '',
|
|
|
|
project: ''
|
|
|
|
},
|
2020-12-22 10:48:11 +08:00
|
|
|
title: '',
|
|
|
|
update: false,
|
2020-12-17 13:19:12 +08:00
|
|
|
rules: {
|
|
|
|
title: [
|
|
|
|
{ required: true, message: '请填写留言板名称', trigger: 'blur' }
|
|
|
|
],
|
|
|
|
project: [
|
|
|
|
{ required: true, message: '请选择归属项目', trigger: 'change' }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleClose() {
|
2020-12-22 10:48:11 +08:00
|
|
|
this.form = { title: '', project: '' };
|
2020-12-17 13:19:12 +08:00
|
|
|
this.$refs.form.resetFields();
|
|
|
|
this.dialogVisible = false;
|
|
|
|
},
|
2020-12-22 10:48:11 +08:00
|
|
|
doShow(data) {
|
2020-12-17 13:19:12 +08:00
|
|
|
this.dialogVisible = true;
|
2020-12-22 10:48:11 +08:00
|
|
|
this.postId = '';
|
|
|
|
this.update = false;
|
|
|
|
this.title = '创建留言板';
|
|
|
|
if (data) {
|
|
|
|
this.update = true;
|
|
|
|
this.title = '修改留言板';
|
|
|
|
this.form.title = data.title;
|
|
|
|
this.form.project = data.project;
|
|
|
|
this.postId = data.id;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updateCommit() {
|
|
|
|
this.$refs['form'].validate((valid) => {
|
|
|
|
if (valid) {
|
|
|
|
updatePost(this.postId, this.form).then(resp => {
|
|
|
|
this.$emit('reloadTable');
|
|
|
|
this.handleClose();
|
|
|
|
}).catch(() => {
|
|
|
|
this.$message.error('修改留言板失败!');
|
|
|
|
this.handleClose();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2020-12-17 13:19:12 +08:00
|
|
|
},
|
|
|
|
commit() {
|
|
|
|
this.$refs['form'].validate((valid) => {
|
|
|
|
if (valid) {
|
|
|
|
createPost(this.form).then(resp => {
|
|
|
|
this.$emit('reloadTable');
|
|
|
|
this.handleClose();
|
2020-12-18 09:17:18 +08:00
|
|
|
}).catch((error) => {
|
|
|
|
if (error.code == '10012') {
|
|
|
|
this.$message.error('本项目下的留言板已存在,请勿重复创建!');
|
|
|
|
} else {
|
|
|
|
this.$message.error('创建留言板失败!');
|
|
|
|
}
|
2020-12-17 13:19:12 +08:00
|
|
|
this.handleClose();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
</style>
|