|
@@ -3,8 +3,8 @@
|
|
|
<div class="common-card exam-question-create-body">
|
|
|
<a-spin :spinning="loading">
|
|
|
<a-form
|
|
|
- :form="loginForm"
|
|
|
- @submit="handleLoginFun"
|
|
|
+ :form="aquestionAddForm"
|
|
|
+ @submit="handleSubmitForm"
|
|
|
style="width: 500px;"
|
|
|
:loading="loading"
|
|
|
>
|
|
@@ -16,11 +16,11 @@
|
|
|
<a-textarea
|
|
|
placeholder="题目内容"
|
|
|
:auto-size="{ minRows: 3, maxRows: 5 }"
|
|
|
- :maxLength="20"
|
|
|
+ :maxLength="1000"
|
|
|
v-decorator="[
|
|
|
'content',
|
|
|
{
|
|
|
- rules: [{ required: true, message: 'Please input content!' }],
|
|
|
+ rules: [{ required: true, message: '请输入题目内容!' }],
|
|
|
},
|
|
|
]"
|
|
|
/>
|
|
@@ -53,9 +53,7 @@
|
|
|
v-decorator="[
|
|
|
`answers-${index}`,
|
|
|
{
|
|
|
- rules: [
|
|
|
- { required: true, message: 'Please input content!' },
|
|
|
- ],
|
|
|
+ rules: [{ required: true, message: '请输入选项内容!' }],
|
|
|
},
|
|
|
]"
|
|
|
/>
|
|
@@ -67,28 +65,26 @@
|
|
|
:wrapper-col="wrapperCol"
|
|
|
>
|
|
|
<a-select
|
|
|
- placeholder="请选择值"
|
|
|
+ placeholder="请选择答案"
|
|
|
v-decorator="[
|
|
|
'finalAnswerIndexs',
|
|
|
{
|
|
|
- rules: [
|
|
|
- { required: true, message: 'Please selete finalAnswer!' },
|
|
|
- ],
|
|
|
- initialValue: engineeringWorkChooseValue,
|
|
|
+ rules: [{ required: true, message: '请选择答案!' }],
|
|
|
+ initialValue: finalAnswerIndexs,
|
|
|
},
|
|
|
]"
|
|
|
>
|
|
|
<a-select-option
|
|
|
- :value="index"
|
|
|
v-for="(item, index) in optionsList"
|
|
|
:key="index"
|
|
|
+ :value="index"
|
|
|
>
|
|
|
{{ index | formatQuestionIndex }}
|
|
|
</a-select-option>
|
|
|
</a-select>
|
|
|
</a-form-item>
|
|
|
- <a-form-item
|
|
|
- label="必学日期"
|
|
|
+ <!-- <a-form-item
|
|
|
+ label="必答日期"
|
|
|
:label-col="labelCol"
|
|
|
:wrapper-col="wrapperCol"
|
|
|
>
|
|
@@ -96,12 +92,39 @@
|
|
|
@change="onDateChange"
|
|
|
placeholder="请选择日期"
|
|
|
v-decorator="[
|
|
|
- 'studyDate',
|
|
|
+ 'answerDate',
|
|
|
{
|
|
|
- rules: [{ required: true, message: 'Please selete date!' }],
|
|
|
+ rules: [{ required: true, message: '请选择必答日期!' }],
|
|
|
},
|
|
|
]"
|
|
|
/>
|
|
|
+ </a-form-item> -->
|
|
|
+ <a-form-item
|
|
|
+ label="题目分类"
|
|
|
+ :label-col="labelCol"
|
|
|
+ :wrapper-col="wrapperCol"
|
|
|
+ >
|
|
|
+ <a-select
|
|
|
+ v-decorator="[
|
|
|
+ 'typeCondition',
|
|
|
+ {
|
|
|
+ rules: [
|
|
|
+ {
|
|
|
+ required: false,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ initialValue: typeCondition,
|
|
|
+ },
|
|
|
+ ]"
|
|
|
+ >
|
|
|
+ <a-select-option
|
|
|
+ v-for="(item, index) in typeConditionList"
|
|
|
+ :key="index"
|
|
|
+ :value="item.id"
|
|
|
+ >
|
|
|
+ {{ item.name }}
|
|
|
+ </a-select-option>
|
|
|
+ </a-select>
|
|
|
</a-form-item>
|
|
|
<a-form-item
|
|
|
label="工种类别"
|
|
@@ -115,7 +138,6 @@
|
|
|
rules: [
|
|
|
{
|
|
|
required: false,
|
|
|
- message: 'Please selete engineering work!',
|
|
|
},
|
|
|
],
|
|
|
initialValue: engineeringWorkChooseValue,
|
|
@@ -123,9 +145,9 @@
|
|
|
]"
|
|
|
>
|
|
|
<a-select-option
|
|
|
- :value="item.code"
|
|
|
v-for="(item, index) in engineeringWorkList"
|
|
|
:key="index"
|
|
|
+ :value="item.id"
|
|
|
>
|
|
|
{{ item.name }}
|
|
|
</a-select-option>
|
|
@@ -146,8 +168,8 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { ENGINEERING_WORK_LIST } from '@/common/Constant';
|
|
|
-import { formatQuestionIndex } from '@/filters';
|
|
|
+import { formatQuestionIndex, formateUrlParams } from '@/filters';
|
|
|
+import { mapGetters } from 'vuex';
|
|
|
export default {
|
|
|
name: 'examQusetionCreateSingle',
|
|
|
props: {},
|
|
@@ -157,14 +179,17 @@ export default {
|
|
|
loading: false, // 是否显示加载动画
|
|
|
labelCol: { span: 6 }, // 表单行中label的占位
|
|
|
wrapperCol: { span: 18 }, // 表单行中内容的占位
|
|
|
- loginForm: this.$form.createForm(this, {
|
|
|
+ aquestionAddForm: this.$form.createForm(this, {
|
|
|
name: 'examQusetionAddDanXuan',
|
|
|
}),
|
|
|
- questionType: 'DanXuan', // 题目类型:单选题
|
|
|
+ questionType: 'DanXuan', // 题目类目:单选题
|
|
|
optionsList: [{ value: '' }, { value: '' }], // 选项列表
|
|
|
+ typeConditionList: [], // 题目类别列表
|
|
|
+ typeCondition: '', // 所选题目类别
|
|
|
engineeringWorkList: [], // 工种数据列表
|
|
|
engineeringWorkChooseValue: '', // 所选工种
|
|
|
- studyDate: '', // 开考时间
|
|
|
+ // answerDate: '', // 必答时间
|
|
|
+ finalAnswerIndexs: undefined, // 正确答案下标
|
|
|
};
|
|
|
},
|
|
|
created() {
|
|
@@ -173,16 +198,25 @@ export default {
|
|
|
mounted() {},
|
|
|
beforeDestroy() {},
|
|
|
watch: {},
|
|
|
- computed: {},
|
|
|
+ computed: {
|
|
|
+ ...mapGetters([
|
|
|
+ 'GET_ENGINEERING_WORK_LIST',
|
|
|
+ 'GET_EXAM_QUESTION_TYPE_CONDITION',
|
|
|
+ ]),
|
|
|
+ },
|
|
|
methods: {
|
|
|
// 初始化数据
|
|
|
initDataFun() {
|
|
|
+ // 题目类别
|
|
|
+ this.typeConditionList = [
|
|
|
+ { name: '不限', id: '' },
|
|
|
+ ...this.GET_EXAM_QUESTION_TYPE_CONDITION,
|
|
|
+ ];
|
|
|
// 工种类别
|
|
|
this.engineeringWorkList = [
|
|
|
- { name: '不限工种', code: '' },
|
|
|
- ...ENGINEERING_WORK_LIST,
|
|
|
+ { name: '不限', id: '' },
|
|
|
+ ...this.GET_ENGINEERING_WORK_LIST,
|
|
|
];
|
|
|
- this.engineeringWorkChooseValue = this.engineeringWorkList[0].code;
|
|
|
},
|
|
|
// 操作:新增选项
|
|
|
questionOptionAddFun() {
|
|
@@ -192,36 +226,54 @@ export default {
|
|
|
questionOptionDeleteFun(index) {
|
|
|
this.optionsList.splice(index, 1);
|
|
|
},
|
|
|
- // 操作:选择日期
|
|
|
- onDateChange(date, dateString) {
|
|
|
- if (date) {
|
|
|
- this.studyDate = dateString;
|
|
|
- } else {
|
|
|
- this.studyDate = '';
|
|
|
- }
|
|
|
- },
|
|
|
+ // // 操作:选择日期
|
|
|
+ // onDateChange(date, dateString) {
|
|
|
+ // if (date) {
|
|
|
+ // this.answerDate = dateString;
|
|
|
+ // } else {
|
|
|
+ // this.answerDate = '';
|
|
|
+ // }
|
|
|
+ // },
|
|
|
// 操作:表单提交
|
|
|
- handleLoginFun(e) {
|
|
|
+ handleSubmitForm(e) {
|
|
|
e.preventDefault();
|
|
|
- this.loginForm.validateFields((err, values) => {
|
|
|
+ this.aquestionAddForm.validateFields((err, values) => {
|
|
|
if (!err) {
|
|
|
- let params = {
|
|
|
- // 貌似需要拼接到请求地址后面的参数
|
|
|
+ let engineerTypeInfo = this.formatEngineeringWorkChooseValue(
|
|
|
+ values.engineeringWorkChooseValue
|
|
|
+ ); // 获取工种信息
|
|
|
+ // 需要拼接到请求地址后面的参数
|
|
|
+ let urlParams = {
|
|
|
categoryid: this.questionType, // 题目类目ID
|
|
|
engineertypeid: values.engineeringWorkChooseValue, // 工种ID
|
|
|
-
|
|
|
- engineertypes: values.engineeringWorkChooseValue, // 工种ID
|
|
|
+ };
|
|
|
+ // 接口Body参数
|
|
|
+ let params = {
|
|
|
content: values.content, // 内容
|
|
|
- tages: [this.studyDate], // 日期
|
|
|
- finalanswer: this.formatQuestionFinalAnswerArr(
|
|
|
+ finalAnswer: this.formatQuestionFinalAnswerArr(
|
|
|
values.finalAnswerIndexs
|
|
|
), // 正确答案
|
|
|
+ engineerTypes: [engineerTypeInfo], // 工种信息集合
|
|
|
+ type: this.questionType, // 题目类别ID
|
|
|
+ // tages: [this.answerDate], // 日期
|
|
|
answers: this.formatQuestionAnswersArr(values), // 选项
|
|
|
};
|
|
|
- this.httpQuestFun(params);
|
|
|
+ this.httpQuestFun(urlParams, params);
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
+ // 获取工种信息
|
|
|
+ formatEngineeringWorkChooseValue(id) {
|
|
|
+ let seleteItem = {};
|
|
|
+ for (let i = 0; i < this.engineeringWorkList.length; i++) {
|
|
|
+ let item = this.engineeringWorkList[i];
|
|
|
+ if (item.id === id) {
|
|
|
+ seleteItem = item;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return seleteItem;
|
|
|
+ },
|
|
|
// 把答案下标转换为大写英文字母放入一个数组中
|
|
|
formatQuestionFinalAnswerArr(index) {
|
|
|
let arr = [formatQuestionIndex(index)];
|
|
@@ -238,19 +290,21 @@ export default {
|
|
|
return arr;
|
|
|
},
|
|
|
// 表单提交请求
|
|
|
- httpQuestFun(params) {
|
|
|
- console.log(params);
|
|
|
+ httpQuestFun(urlParams, params) {
|
|
|
this.loading = true;
|
|
|
this.$_http
|
|
|
- .post(this.$_API.INTERFACE_POST_EXAMS_QUESTION_ADD, params)
|
|
|
- .then((res) => {
|
|
|
- console.log(res);
|
|
|
+ .post(
|
|
|
+ formateUrlParams(
|
|
|
+ this.$_API.INTERFACE_POST_EXAMS_QUESTION_ADD,
|
|
|
+ urlParams
|
|
|
+ ),
|
|
|
+ params
|
|
|
+ )
|
|
|
+ .then(() => {
|
|
|
+ this.loading = false;
|
|
|
this.$message.success('添加单选题成功');
|
|
|
})
|
|
|
- .catch((err) => {
|
|
|
- console.log(err);
|
|
|
- })
|
|
|
- .finally(() => {
|
|
|
+ .catch(() => {
|
|
|
this.loading = false;
|
|
|
});
|
|
|
},
|