rt-sim-training-client/src/views/messageBoard/create.vue

120 lines
3.6 KiB
Vue
Raw Normal View History

<template>
<el-dialog
2020-12-22 10:48:11 +08:00
:title="title"
: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="请选择">
<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>
</span>
</el-dialog>
</template>
<script>
2020-12-22 10:48:11 +08:00
import { createPost, updatePost } from '@/api/learn';
export default {
name: 'Create',
props:{
projectOptionList:{
type: Array,
default() {
return [];
}
}
},
data() {
return {
dialogVisible: false,
2020-12-22 10:48:11 +08:00
postId: '',
form:{
title: '',
project: ''
},
2020-12-22 10:48:11 +08:00
title: '',
update: false,
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: '' };
this.$refs.form.resetFields();
this.dialogVisible = false;
},
2020-12-22 10:48:11 +08:00
doShow(data) {
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();
});
}
});
},
commit() {
this.$refs['form'].validate((valid) => {
if (valid) {
createPost(this.form).then(resp => {
this.$emit('reloadTable');
this.handleClose();
}).catch((error) => {
if (error.code == '10012') {
this.$message.error('本项目下的留言板已存在,请勿重复创建!');
} else {
this.$message.error('创建留言板失败!');
}
this.handleClose();
});
}
});
}
}
};
</script>
<style scoped>
</style>