rt-sim-training-client/src/views/competitionManage/bankList/question-create-page.vue

110 lines
2.6 KiB
Vue
Raw Normal View History

2020-05-26 15:59:11 +08:00
<template>
<div class="page">
<div class="page__container">
<el-card class="page__container-body">
<question-form ref="info" :option="formModel" :remove="true" @modify="doModify" />
</el-card>
<div class="page__container-footer">
<el-button type="primary" :is-create="true" @click="create"> </el-button>
<el-button @click="back"> </el-button>
</div>
</div>
<dialog-modify-rich ref="rich" />
</div>
</template>
<script>
import QuestionForm from './question-form.vue';
import DialogModifyRich from './dialog-modify-rich';
import { createQuestion } from '@/api/questionBank.js';
import * as authUtils from '@/utils/auth.js';
export default {
components: {
QuestionForm,
DialogModifyRich
},
data() {
return {
active: 0,
formModel: {
id: '',
topic: '',
type: 'select',
answer: 0,
optionList: []
}
};
},
computed: {
deviceId() {
return this.$route.params.deviceId;
},
path() {
return this.$route.path;
}
},
created() {
const value = authUtils.getSessionStorage(this.path);
if (value) {
const model = JSON.parse(value);
this.formModel.type = model.type;
}
},
methods: {
doBack() {
this.$router.go(-1);
},
doModify(node) {
this.$refs.rich.doShow(node);
},
create() {
this.$refs.info.validate().then(valid => {
if (valid) {
createQuestion(this.formModel).then(resp => {
authUtils.setSessionStorage(this.path, JSON.stringify({
type: this.formModel.type
}));
this.doBack();
}).catch(error => {
this.$message.error(`创建试题失败: ${error.message}`);
});
}
}).catch(error => { this.$message.warning(error.message); });
},
back() {
this.$router.go(-1);
}
}
};
</script>
<style lang="scss" scoped>
.page {
width: 100%;
&__container {
width: 55%;
margin: auto;
&-header {
margin-bottom: 10px;
.step-group {
margin: 10px 0;
.box {
display: flex;
justify-content: flex-end;
}
}
}
&-body {
padding: 40px;
}
&-footer {
margin-top: 20px;
display: flex;
justify-content: center;
}
}
}
</style>