|
@@ -1,68 +1,76 @@
|
|
|
<template>
|
|
|
<div id="lookdetail">
|
|
|
- <detail-frame :title="mainTitle" returns="./index">
|
|
|
- <data-form :fields="fields" :rules="rules" @save="handleSave" :isNew="isNew">
|
|
|
- <template #options="{item}">
|
|
|
- <template v-if="item.model === 'state'">
|
|
|
- <el-option label="弃用" value="0"></el-option>
|
|
|
- <el-option label="正常" value="1"></el-option>
|
|
|
- </template>
|
|
|
- </template>
|
|
|
- <template #custom="{ item, form, fieldChange }">
|
|
|
- <el-button type="text" @click="dialogFormVisible = true">选择题类型</el-button>
|
|
|
- <el-dialog title="选择题类型" :visible.sync="dialogFormVisible">
|
|
|
- <el-form :model="form">
|
|
|
- <template>
|
|
|
- <el-tabs v-model="activeName" @tab-click="handleClick">
|
|
|
- <el-tab-pane label="单选" name="first">
|
|
|
- <el-button type="text" @click="dialogFormVisible1 = true">增加</el-button>
|
|
|
-
|
|
|
- <el-dialog title="增加页面" :visible.sync="dialogFormVisible1">
|
|
|
- <el-form :model="form" label-width="80px">
|
|
|
- <el-form-item label="序号" :label-width="formLabelWidth">
|
|
|
- <el-input v-model="form.zuoyeid" autocomplete="off" placeholder="请输入序号" prop="zuoyeid"></el-input>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="名称" :label-width="formLabelWidth">
|
|
|
- <el-input v-model="form.zuoyename" autocomplete="off" placeholder="请输入名称" prop="zuoyename"></el-input>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="答案" :label-width="formLabelWidth">
|
|
|
- <el-input v-model="form.answer" autocomplete="off" placeholder="请输入答案" prop="answer"></el-input>
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
- <div slot="footer" class="dialog-footer">
|
|
|
- <el-button @click="dialogFormVisible1 = false">取 消</el-button>
|
|
|
- <el-button type="primary" @click="dialogFormVisible1 = false">确 定</el-button>
|
|
|
- </div>
|
|
|
- </el-dialog>
|
|
|
- <data-table :fields="fieldss" :data="index" :opera="opera" @edit="toEdit"></data-table>
|
|
|
- </el-tab-pane>
|
|
|
- <el-tab-pane label="多选" name="first"></el-tab-pane>
|
|
|
- <el-tab-pane label="问答" name="third">
|
|
|
- <el-form ref="form" :model="form" label-width="80px">
|
|
|
- <el-form-item label="问答">
|
|
|
- <el-input v-model="form.duoxuan" placeholder="请输入问答题"></el-input>
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
- </el-tab-pane>
|
|
|
- </el-tabs>
|
|
|
- </template>
|
|
|
- </el-form>
|
|
|
- <div slot="footer" class="dialog-footer">
|
|
|
- <el-button @click="dialogFormVisible = false">取 消</el-button>
|
|
|
- <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
|
|
|
- </div>
|
|
|
- </el-dialog>
|
|
|
- </template>
|
|
|
- </data-form>
|
|
|
+ <detail-frame :title="mainTitle" returns="/itembank/index">
|
|
|
+ <el-form ref="infoForm" :model="info" :rules="rules" label-width="120px" size="small" @submit.native.prevent style="background:#fff;padding:20px">
|
|
|
+ <el-form-item label="类型" :required="true" prop="type">
|
|
|
+ <el-radio-group v-model="info.type">
|
|
|
+ <el-radio v-for="(item, index) in radios" :key="index" :label="item.code">{{ item.name }}</el-radio>
|
|
|
+ </el-radio-group>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="题目" :required="true" prop="topic">
|
|
|
+ <el-input v-model="info.topic"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="状态" :required="true" prop="status">
|
|
|
+ <el-radio-group v-model="info.status">
|
|
|
+ <el-radio label="0">禁用</el-radio>
|
|
|
+ <el-radio label="1">使用</el-radio>
|
|
|
+ </el-radio-group>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="选项" prop="option" v-if="info.type === '0' || info.type === '1'">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="24" style="text-align:right;padding-bottom:10px">
|
|
|
+ <el-button type="primary" size="mini" @click="drawer = true">添加选项</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24">
|
|
|
+ <el-table :data="info.option" border stripe size="mini">
|
|
|
+ <el-table-column align="center" label="序号" prop="number"></el-table-column>
|
|
|
+ <el-table-column align="center" label="内容" prop="option_name"></el-table-column>
|
|
|
+ <el-table-column align="center" label="操作">
|
|
|
+ <template v-slot="{ row, $index }">
|
|
|
+ <el-tooltip effect="dark" content="编辑" placement="bottom">
|
|
|
+ <el-button type="text" size="mini" icon="el-icon-edit" @click="toOedit(row, $index)"></el-button>
|
|
|
+ </el-tooltip>
|
|
|
+ <el-tooltip effect="dark" content="删除" placement="bottom">
|
|
|
+ <el-button type="text" size="mini" icon="el-icon-delete" @click="toOdelete(row, $index)"></el-button>
|
|
|
+ </el-tooltip>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="答案" prop="answer" v-if="info.type === '0' || info.type === '1'">
|
|
|
+ <el-input v-model="info.answer"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-row type="flex" justify="center">
|
|
|
+ <el-col :span="6">
|
|
|
+ <el-button type="primary" @click="handleSave">保 存</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="6">
|
|
|
+ <el-button @click="$refs.infoForm.resetFields()">重 置</el-button>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
</detail-frame>
|
|
|
+ <el-drawer :visible.sync="drawer" @close="toOclose" direction="rtl" :with-header="false">
|
|
|
+ <el-tabs style="padding:10px;">
|
|
|
+ <el-tab-pane label="选项">
|
|
|
+ <data-form :styles="{ padding: 0 }" :data="optionForm" :fields="oFields" :rules="oRules" @save="handleOsave" :isNew="oIsNew"></data-form>
|
|
|
+ </el-tab-pane>
|
|
|
+ </el-tabs>
|
|
|
+ </el-drawer>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import dataTable from '@frame/components/data-table';
|
|
|
import detailFrame from '@frame/layout/admin/detail-frame';
|
|
|
import dataForm from '@frame/components/form';
|
|
|
import upload from '@frame/components/upload';
|
|
|
+import _ from 'lodash';
|
|
|
+import { createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions } = createNamespacedHelpers('question');
|
|
|
export default {
|
|
|
metaInfo: { title: '题库详情页' },
|
|
|
name: 'lookdetail',
|
|
@@ -70,59 +78,50 @@ export default {
|
|
|
components: {
|
|
|
detailFrame,
|
|
|
dataForm,
|
|
|
- dataTable,
|
|
|
},
|
|
|
data: () => ({
|
|
|
+ oIsNew: true,
|
|
|
+ drawer: false,
|
|
|
+ loading: true,
|
|
|
opera: [
|
|
|
{
|
|
|
label: '编辑',
|
|
|
icon: 'el-icon-edit',
|
|
|
method: 'edit',
|
|
|
},
|
|
|
+ {
|
|
|
+ label: '删除',
|
|
|
+ icon: 'el-icon-delete',
|
|
|
+ method: 'delete',
|
|
|
+ },
|
|
|
],
|
|
|
-
|
|
|
- activeName: '',
|
|
|
- dialogTableVisible: false,
|
|
|
- dialogTableVisible1: false,
|
|
|
- dialogFormVisible: false,
|
|
|
- dialogFormVisible1: false,
|
|
|
- form: {
|
|
|
- duoxuan: '',
|
|
|
- name: '',
|
|
|
- region: '',
|
|
|
- date1: '',
|
|
|
- date2: '',
|
|
|
- delivery: false,
|
|
|
- type: [],
|
|
|
- zuoyeid: '',
|
|
|
- zuoyename: '',
|
|
|
- answer: '',
|
|
|
- },
|
|
|
- formLabelWidth: '120px',
|
|
|
- fieldss: [
|
|
|
- { label: '序号', required: true, model: 'zuoyeid' },
|
|
|
- { label: '名称', required: true, model: 'zuoyename' },
|
|
|
- { label: '答案', required: true, model: 'answer' },
|
|
|
+ form: {},
|
|
|
+ optionForm: {},
|
|
|
+ info: { status: `1` },
|
|
|
+ radios: [
|
|
|
+ { code: '0', name: '单选' },
|
|
|
+ { code: '1', name: '多选' },
|
|
|
+ { code: '2', name: '简答' },
|
|
|
],
|
|
|
-
|
|
|
- index: [{ zuoyeid: '1' }],
|
|
|
- fields: [
|
|
|
- { label: '题名', required: true, model: 'title' },
|
|
|
- { label: '状态', required: true, model: 'state', type: `select` },
|
|
|
- { label: '题型', required: true, model: 'type', type: 'tixing', custom: true },
|
|
|
+ oFields: [
|
|
|
+ { label: '序号', required: true, model: 'number' },
|
|
|
+ { label: '内容', required: true, model: 'option_name' },
|
|
|
],
|
|
|
+ oRules: {
|
|
|
+ number: [{ required: true, message: '请输入序号' }],
|
|
|
+ option_name: [{ required: true, message: '请输入内容' }],
|
|
|
+ },
|
|
|
rules: {
|
|
|
- zuoyeid: [{ required: true, message: '请输入序号', trigger: 'blur' }],
|
|
|
- zuoyename: [{ required: true, message: '请输入名称', trigger: 'blur' }],
|
|
|
- answer: [{ required: true, message: '请输入答案', trigger: 'blur' }],
|
|
|
- name: [{ required: true, message: '请输入作业姓名' }],
|
|
|
- state: [{ required: true, message: '请选择状态' }],
|
|
|
- tixing: [{ required: true, message: '请选择题类型' }],
|
|
|
- title: [{ required: true, message: '请选择标题' }],
|
|
|
+ type: [{ required: true, message: '请选择类型', trigger: 'blur' }],
|
|
|
+ topic: [{ required: true, message: '请输入题目', trigger: 'blur' }],
|
|
|
+ status: [{ required: true, message: '请选择状态' }],
|
|
|
},
|
|
|
}),
|
|
|
created() {},
|
|
|
computed: {
|
|
|
+ id() {
|
|
|
+ return this.$route.query.id;
|
|
|
+ },
|
|
|
mainTitle() {
|
|
|
let meta = this.$route.meta;
|
|
|
let main = meta.title || '';
|
|
@@ -138,50 +137,82 @@ export default {
|
|
|
return this.$route.query.id ? false : true;
|
|
|
},
|
|
|
},
|
|
|
+ watch: {
|
|
|
+ isNew: {
|
|
|
+ immediate: true,
|
|
|
+ handler(val) {
|
|
|
+ if (val) this.loading = false;
|
|
|
+ else this.search();
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
methods: {
|
|
|
- search({ skip = 0, limit = 15, ...info } = {}) {
|
|
|
- console.log(`in search`);
|
|
|
+ ...mapActions(['fetch', 'create', 'update']),
|
|
|
+ async search({ skip = 0, limit = 10, ...info } = {}) {
|
|
|
+ const res = await this.fetch(this.id);
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ this.$set(this, `info`, res.data);
|
|
|
+ }
|
|
|
+ this.loading = false;
|
|
|
+ },
|
|
|
+ handleSave() {
|
|
|
+ this.$refs['infoForm'].validate(valid => {
|
|
|
+ if (valid) {
|
|
|
+ this.toSave();
|
|
|
+ } else {
|
|
|
+ console.warn('form validate error!!!');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ async toSave() {
|
|
|
+ let res;
|
|
|
+ let msg;
|
|
|
+ let newData = {};
|
|
|
+ let { type, option, answer, ...other } = this.info;
|
|
|
+ if (type === 0 || type === 1) newData = this.info;
|
|
|
+ else newData = { type, ...other };
|
|
|
+ if (this.isNew) {
|
|
|
+ res = await this.create(newData);
|
|
|
+ msg = `${this.keyWord}添加成功`;
|
|
|
+ } else {
|
|
|
+ res = await this.update(newData);
|
|
|
+ msg = `${this.keyWord}修改成功`;
|
|
|
+ }
|
|
|
+ if (this.$checkRes(res, msg)) this.$router.push({ path: '/itembank/index' });
|
|
|
},
|
|
|
toEdit({ data }) {
|
|
|
console.log(`in toEdit`);
|
|
|
console.log(data);
|
|
|
},
|
|
|
- handleClick(tab, event) {
|
|
|
- console.log(tab, event);
|
|
|
- },
|
|
|
|
|
|
- uploadSuccess() {},
|
|
|
- async handleSave({ isNew, data }) {
|
|
|
- console.log(isNew);
|
|
|
- console.log(data);
|
|
|
+ // 选项
|
|
|
+ toOclose() {
|
|
|
+ this.drawer = false;
|
|
|
+ this.oIsNew = true;
|
|
|
+ this.optionForm = {};
|
|
|
+ },
|
|
|
+ handleOsave({ isNew, data }) {
|
|
|
+ if (isNew) {
|
|
|
+ if (!_.isArray(this.info.option)) this.info.option = [];
|
|
|
+ this.info.option.push(data);
|
|
|
+ } else {
|
|
|
+ let { index, ...info } = data;
|
|
|
+ this.$set(this.info.option, index, info);
|
|
|
+ }
|
|
|
+ this.toOclose();
|
|
|
+ },
|
|
|
+ toOedit(row, index) {
|
|
|
+ let data = JSON.parse(JSON.stringify(row));
|
|
|
+ data.index = index;
|
|
|
+ this.optionForm = data;
|
|
|
+ this.drawer = true;
|
|
|
+ this.oIsNew = false;
|
|
|
+ },
|
|
|
+ toOdelete(row, index) {
|
|
|
+ this.info.option.splice(index, 1);
|
|
|
},
|
|
|
},
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
-<style lang="less" scoped>
|
|
|
-/deep/.el-tabs__nav-wrap::after {
|
|
|
- content: '';
|
|
|
- position: absolute;
|
|
|
- left: 0;
|
|
|
- bottom: 0;
|
|
|
- width: 100%;
|
|
|
- height: 2px;
|
|
|
- background-color: #ffffff;
|
|
|
- z-index: 1;
|
|
|
-}
|
|
|
-
|
|
|
-/deep/.el-tabs__active-bar {
|
|
|
- position: absolute;
|
|
|
- bottom: 0;
|
|
|
- left: 0;
|
|
|
- height: 2px;
|
|
|
- background-color: #ffffff;
|
|
|
-}
|
|
|
-/deep/.el-tabs__item.is-active {
|
|
|
- color: #303133;
|
|
|
-}
|
|
|
-/deep/.el-input__inner {
|
|
|
- margin: 0 0 20px 0;
|
|
|
-}
|
|
|
-</style>
|
|
|
+<style lang="less" scoped></style>
|