فهرست منبع

对接新建题目的接口

yellowtaotao 4 سال پیش
والد
کامیت
0f3eee15ae

+ 40 - 10
src/filters/index.js

@@ -136,11 +136,11 @@ export function dateChange() {
 }
 
 /**
- * 路径参数替换
+ * 请求地址拼接指定参数:/url/{id}
  * @pathParams {Object} 路径参数
  * @return 新path
  */
-export function pathParams(path, pathParams) {
+export function formatePathParams(path, pathParams) {
   if (path.includes('{') && pathParams) {
     let keys = Object.keys(pathParams);
     keys.forEach((it) => {
@@ -150,12 +150,43 @@ export function pathParams(path, pathParams) {
   return path;
 }
 
+/**
+ * 请求地址拼接路径的参数: /url?id=xx&name=yy
+ * @pathParams {Object} 路径参数
+ * @return 新path
+ */
+export function formateUrlParams(path, urlParams) {
+  let paramsNum = 0
+  for (let key in urlParams) {
+    // // 如果urlParams不为空,并且是第一个不为空的参数时,直接进行拼接,不用加&
+    // if (path === 'aaa/bbb?' && urlParams[key]) {
+    //   path = path + key + '=' + urlParams[key];
+    //   // 如果该项的obj不为空(等于0也可以),但不是第一个不为空的参数时,加&进行拼接
+    // } else if (
+    //   (path !== 'aaa/bbb?' && urlParams[key]) ||
+    //   (path !== 'aaa/bbb?' && urlParams[key] === 0)
+    // ) {
+    //   path = path + '&' + key + '=' + urlParams[key];
+    // }
+    paramsNum++
+    if (paramsNum === 1) {
+      path = path + '?' + key + '=' + urlParams[key]
+    } else if (paramsNum > 1) {
+      path = path + '&' + key + '=' + urlParams[key]
+    }
+  }
+  return path
+}
+
 /**
  * 过滤选项的编号
  * @index {Number} 下标
  * @return 字母
  */
-export function formatQuestionIndex(index) {
+export function formatQuestionIndex(index) {      
+  if (index === undefined || index === null) {
+    return ''
+  }
   return String.fromCharCode(index + 65);
 }
 
@@ -207,21 +238,20 @@ export function formateHoursMinutesSeconds(hours, minutes, seconds) {
  * @seconds 秒
  * @returns millisecond
  */
- export function formateSeconds(hours, minutes, seconds) {
-   let millisecond  = 0
+export function formateSeconds(hours, minutes, seconds) {
+  let millisecond = 0;
   if (hours && !isNaN(hours)) {
-    millisecond  = millisecond  + hours * (1000 * 60 * 60)
+    millisecond = millisecond + hours * (1000 * 60 * 60);
   }
   if (minutes && !isNaN(minutes)) {
-    millisecond  = millisecond  + minutes * (1000 * 60)
+    millisecond = millisecond + minutes * (1000 * 60);
   }
   if (seconds && !isNaN(seconds)) {
-    millisecond  = millisecond  + seconds * (1000)
+    millisecond = millisecond + seconds * 1000;
   }
-  return millisecond ;
+  return millisecond;
 }
 
-
 /**
  * 过滤:考试类型
  * @code:编码

+ 2 - 2
src/views/engineeringWorkManagement/engineeringWorkList.vue

@@ -45,7 +45,7 @@
 </template>
 
 <script>
-import { pathParams } from '@/filters';
+import { formatePathParams } from '@/filters';
 export default {
   name: 'engineeringWorkList',
   props: {},
@@ -129,7 +129,7 @@ export default {
           };
           that.$_http
             .delete(
-              pathParams(
+              formatePathParams(
                 that.$_API.INTERFACE_DELETE_ENGINEERINGWORK_DELETE,
                 params
               )

+ 2 - 3
src/views/examQuestionManagement/examQuestionList.vue

@@ -121,7 +121,7 @@
 <script>
 import { EXAM_QUESTION_TYPE } from '@/common/Constant';
 import { mapGetters } from 'vuex';
-import { pathParams } from '@/filters';
+import { formatePathParams } from '@/filters';
 export default {
   name: 'examQuestionList',
   props: {},
@@ -159,7 +159,6 @@ export default {
     },
   },
   computed: {
-    // 是否选择了数据
     ...mapGetters([
       'screenHeight',
       'GET_ENGINEERING_WORK_LIST',
@@ -315,7 +314,7 @@ export default {
           };
           that.$_http
             .delete(
-              pathParams(
+              formatePathParams(
                 that.$_API.INTERFACE_DELETE_EXAMS_QUESTION_DELETE,
                 params
               )

+ 2 - 2
src/views/examQuestionManagement/examQuestionType.vue

@@ -45,7 +45,7 @@
 </template>
 
 <script>
-import { pathParams } from '@/filters';
+import { formatePathParams } from '@/filters';
 export default {
   name: 'examQuestionType',
   props: {},
@@ -123,7 +123,7 @@ export default {
       };
       this.$_http
         .delete(
-          pathParams(
+          formatePathParams(
             this.$_API.INTERFACE_POST_EXAMS_QUESTION_TYPE_DELETE,
             params
           )

+ 88 - 56
src/views/examQuestionManagement/examQusetionCreateGapFilling.vue

@@ -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,29 +53,38 @@
                 v-decorator="[
                   `answers-${index}`,
                   {
-                    rules: [
-                      { required: true, message: 'Please input content!' },
-                    ],
+                    rules: [{ required: true, message: '请输入填空答案!' }],
                   },
                 ]"
               />
             </a-form-item>
           </div>
           <a-form-item
-            label="必学日期"
+            label="题目分类"
             :label-col="labelCol"
             :wrapper-col="wrapperCol"
           >
-            <a-date-picker
-              @change="onDateChange"
-              placeholder="请选择日期"
+            <a-select
               v-decorator="[
-                'studyDate',
+                'typeCondition',
                 {
-                  rules: [{ required: true, message: 'Please selete date!' }],
+                  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="工种类别"
@@ -89,7 +98,6 @@
                   rules: [
                     {
                       required: false,
-                      message: 'Please selete engineering work!',
                     },
                   ],
                   initialValue: engineeringWorkChooseValue,
@@ -97,9 +105,9 @@
               ]"
             >
               <a-select-option
-                :value="item.code"
                 v-for="(item, index) in engineeringWorkList"
                 :key="index"
+                :value="item.id"
               >
                 {{ item.name }}
               </a-select-option>
@@ -120,7 +128,8 @@
 </template>
 
 <script>
-import { ENGINEERING_WORK_LIST } from '@/common/Constant';
+import { formateUrlParams } from '@/filters';
+import { mapGetters } from 'vuex';
 export default {
   name: 'examQusetionCreateGapFilling',
   props: {},
@@ -130,14 +139,16 @@ export default {
       loading: false, // 是否显示加载动画
       labelCol: { span: 6 }, // 表单行中label的占位
       wrapperCol: { span: 18 }, // 表单行中内容的占位
-      loginForm: this.$form.createForm(this, {
+      aquestionAddForm: this.$form.createForm(this, {
         name: 'examQusetionAddDuoXuan',
       }),
       questionType: 'TianKong', // 题目类型:填空题
       optionsList: [{ value: '' }], // 选项列表
+      typeConditionList: [], // 题目类别列表
+      typeCondition: '', // 所选题目类别
       engineeringWorkList: [], // 工种数据列表
       engineeringWorkChooseValue: '', // 所选工种
-      studyDate: '', // 开考时间
+      finalAnswerIndexs: undefined, // 正确答案下标
     };
   },
   created() {
@@ -146,16 +157,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() {
@@ -165,32 +185,44 @@ export default {
     questionOptionDeleteFun(index) {
       this.optionsList.splice(index, 1);
     },
-    // 操作:选择日期
-    onDateChange(date, dateString) {
-      if (date) {
-        this.studyDate = dateString;
-      } else {
-        this.studyDate = '';
-      }
-    },
     // 操作:表单提交
-    handleLoginFun(e) {
+    handleSubmitForm(e) {
       e.preventDefault();
-      this.loginForm.validateFields((err, values) => {
+      this.aquestionAddForm.validateFields((err, values) => {
         if (!err) {
           console.log(values);
+          let engineerTypeInfo = this.formatEngineeringWorkChooseValue(
+            values.engineeringWorkChooseValue
+          ); // 获取工种信息
+          // 需要拼接到请求地址后面的参数
+          let urlParams = {
+            categoryid: this.questionType, // 题目类目ID
+            engineertypeid: values.engineeringWorkChooseValue, // 工种ID
+          };
+          // 接口Body参数
           let params = {
-            type: this.questionType,
-            content: values.content,
-            engineeringWorkChooseValue: values.engineeringWorkChooseValue,
-            studyDate: this.studyDate,
-            finalAnswer: this.formatQuestionAnswersArr(values),
-            answers: [],
+            content: values.content, // 内容
+            finalAnswer: this.formatQuestionAnswersArr(values), // 正确答案
+            engineerTypes: [engineerTypeInfo], // 工种信息集合
+            type: this.questionType, // 题目类别ID
+            answers: [], // 选项
           };
-          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;
+    },
     // 把答案放入一个数组中
     formatQuestionAnswersArr(values) {
       let arr = [];
@@ -202,23 +234,23 @@ export default {
       return arr;
     },
     // 表单提交请求
-    httpQuestFun(params) {
+    httpQuestFun(urlParams, params) {
       this.loading = true;
-      console.log(params);
-      setTimeout(() => {
-        this.loading = false;
-      }, 2000);
-      // this.$_http
-      //   .post(this.$_API.INTERFACE_POST_EXAMS_QUESTION_ADD, params)
-      //   .then((res) => {
-      //     console.log(res);
-      //   })
-      //   .catch((err) => {
-      //     console.log(err);
-      //   })
-      //   .finally(() => {
-      //     this.loading = false;
-      //   });
+      this.$_http
+        .post(
+          formateUrlParams(
+            this.$_API.INTERFACE_POST_EXAMS_QUESTION_ADD,
+            urlParams
+          ),
+          params
+        )
+        .then(() => {
+          this.loading = false;
+          this.$message.success('添加填空题成功');
+        })
+        .catch(() => {
+          this.loading = false;
+        });
     },
   },
 };

+ 91 - 72
src/views/examQuestionManagement/examQusetionCreateMultiple.vue

@@ -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: '请输入选项内容!' }],
                   },
                 ]"
               />
@@ -66,22 +64,13 @@
             :label-col="labelCol"
             :wrapper-col="wrapperCol"
           >
-            <!-- <a-input
-              placeholder="答案格式为大写字母"
-              :maxLength="200"
-              v-decorator="[
-                'finalAnswer',
-                {
-                  rules: [{ required: true, message: 'Please input content!' }],
-                },
-              ]"
-            /> -->
             <a-select
               mode="multiple"
               v-decorator="[
                 'finalAnswerIndexs',
                 {
-                  rules: [{ required: true, message: 'Please input content!' }],
+                  rules: [{ required: true, message: '请选择答案!' }],
+                  initialValue: finalAnswerIndexs,
                 },
               ]"
             >
@@ -95,20 +84,31 @@
             </a-select>
           </a-form-item>
           <a-form-item
-            label="必学日期"
+            label="题目分类"
             :label-col="labelCol"
             :wrapper-col="wrapperCol"
           >
-            <a-date-picker
-              @change="onDateChange"
-              placeholder="请选择日期"
+            <a-select
               v-decorator="[
-                'studyDate',
+                'typeCondition',
                 {
-                  rules: [{ required: true, message: 'Please selete date!' }],
+                  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="工种类别"
@@ -122,7 +122,6 @@
                   rules: [
                     {
                       required: false,
-                      message: 'Please selete engineering work!',
                     },
                   ],
                   initialValue: engineeringWorkChooseValue,
@@ -130,9 +129,9 @@
               ]"
             >
               <a-select-option
-                :value="item.code"
                 v-for="(item, index) in engineeringWorkList"
                 :key="index"
+                :value="item.id"
               >
                 {{ item.name }}
               </a-select-option>
@@ -153,8 +152,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: 'examQusetionCreateMultiple',
   props: {},
@@ -164,14 +163,16 @@ export default {
       loading: false, // 是否显示加载动画
       labelCol: { span: 6 }, // 表单行中label的占位
       wrapperCol: { span: 18 }, // 表单行中内容的占位
-      loginForm: this.$form.createForm(this, {
+      aquestionAddForm: this.$form.createForm(this, {
         name: 'examQusetionAddDuoXuan',
       }),
       questionType: 'DuoXuan', // 题目类型:多选题
       optionsList: [{ value: '' }, { value: '' }], // 选项列表
+      typeConditionList: [], // 题目类别列表
+      typeCondition: '', // 所选题目类别
       engineeringWorkList: [], // 工种数据列表
       engineeringWorkChooseValue: '', // 所选工种
-      studyDate: '', // 开考时间
+      finalAnswerIndexs: undefined, // 正确答案下标
     };
   },
   created() {
@@ -180,16 +181,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() {
@@ -199,37 +209,46 @@ export default {
     questionOptionDeleteFun(index) {
       this.optionsList.splice(index, 1);
     },
-    // 操作:选择答案
-    handleChange(values) {
-      console.log(values);
-    },
-    // 操作:选择日期
-    onDateChange(date, dateString) {
-      if (date) {
-        this.studyDate = dateString;
-      } else {
-        this.studyDate = '';
-      }
-    },
     // 操作:表单提交
-    handleLoginFun(e) {
+    handleSubmitForm(e) {
       e.preventDefault();
-      this.loginForm.validateFields((err, values) => {
+      this.aquestionAddForm.validateFields((err, values) => {
         if (!err) {
+          console.log(values);
+          let engineerTypeInfo = this.formatEngineeringWorkChooseValue(
+            values.engineeringWorkChooseValue
+          ); // 获取工种信息
+          // 需要拼接到请求地址后面的参数
+          let urlParams = {
+            categoryid: this.questionType, // 题目类目ID
+            engineertypeid: values.engineeringWorkChooseValue, // 工种ID
+          };
+          // 接口Body参数
           let params = {
-            type: this.questionType,
-            content: values.content,
-            engineeringWorkChooseValue: values.engineeringWorkChooseValue,
-            studyDate: this.studyDate,
+            content: values.content, // 内容
             finalAnswer: this.formatQuestionFinalAnswerArr(
               values.finalAnswerIndexs
-            ),
-            answers: this.formatQuestionAnswersArr(values),
+            ), // 正确答案
+            engineerTypes: [engineerTypeInfo], // 工种信息集合
+            type: this.questionType, // 题目类别ID
+            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(indexs) {
       let arr = '';
@@ -249,23 +268,23 @@ export default {
       return arr;
     },
     // 表单提交请求
-    httpQuestFun(params) {
+    httpQuestFun(urlParams, params) {
       this.loading = true;
-      console.log(params);
-      setTimeout(() => {
-        this.loading = false;
-      }, 2000);
-      // this.$_http
-      //   .post(this.$_API.INTERFACE_POST_EXAMS_QUESTION_ADD, params)
-      //   .then((res) => {
-      //     console.log(res);
-      //   })
-      //   .catch((err) => {
-      //     console.log(err);
-      //   })
-      //   .finally(() => {
-      //     this.loading = false;
-      //   });
+      this.$_http
+        .post(
+          formateUrlParams(
+            this.$_API.INTERFACE_POST_EXAMS_QUESTION_ADD,
+            urlParams
+          ),
+          params
+        )
+        .then(() => {
+          this.loading = false;
+          this.$message.success('添加多选题成功');
+        })
+        .catch(() => {
+          this.loading = false;
+        });
     },
   },
 };

+ 108 - 54
src/views/examQuestionManagement/examQusetionCreateSingle.vue

@@ -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;
         });
     },

+ 92 - 72
src/views/examQuestionManagement/examQusetionCreateTrueOrFalse.vue

@@ -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: '请输入题目内容!' }],
                 },
               ]"
             />
@@ -33,12 +33,6 @@
             v-for="(item, index) in optionsList"
             :key="index"
           >
-            <span
-              v-if="optionsList.length > 2"
-              class="question-option-list-row-delete"
-              @click="questionOptionDeleteFun(index)"
-              >删除</span
-            >
             <a-form-item
               :label="index | formatQuestionIndex"
               :label-col="labelCol"
@@ -51,9 +45,7 @@
                 v-decorator="[
                   `answers-${index}`,
                   {
-                    rules: [
-                      { required: true, message: 'Please input content!' },
-                    ],
+                    rules: [{ required: true, message: '请输入选项内容!' }],
                     initialValue: item.value,
                   },
                 ]"
@@ -70,37 +62,46 @@
               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="必学日期"
+            label="题目分类"
             :label-col="labelCol"
             :wrapper-col="wrapperCol"
           >
-            <a-date-picker
-              @change="onDateChange"
-              placeholder="请选择日期"
+            <a-select
               v-decorator="[
-                'studyDate',
+                'typeCondition',
                 {
-                  rules: [{ required: true, message: 'Please selete date!' }],
+                  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="工种类别"
@@ -114,7 +115,6 @@
                   rules: [
                     {
                       required: false,
-                      message: 'Please selete engineering work!',
                     },
                   ],
                   initialValue: engineeringWorkChooseValue,
@@ -122,9 +122,9 @@
               ]"
             >
               <a-select-option
-                :value="item.code"
                 v-for="(item, index) in engineeringWorkList"
                 :key="index"
+                :value="item.id"
               >
                 {{ item.name }}
               </a-select-option>
@@ -145,8 +145,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: 'examQusetionCreateTrueOrFalse',
   props: {},
@@ -156,14 +156,16 @@ export default {
       loading: false, // 是否显示加载动画
       labelCol: { span: 6 }, // 表单行中label的占位
       wrapperCol: { span: 18 }, // 表单行中内容的占位
-      loginForm: this.$form.createForm(this, {
+      aquestionAddForm: this.$form.createForm(this, {
         name: 'examQusetionAddPanDuan',
       }),
       questionType: 'PanDuan', // 题目类型:判断题
       optionsList: [{ value: '正确' }, { value: '错误' }], // 选项列表
+      typeConditionList: [], // 题目类别列表
+      typeCondition: '', // 所选题目类别
       engineeringWorkList: [], // 工种数据列表
       engineeringWorkChooseValue: '', // 所选工种
-      studyDate: '', // 开考时间
+      finalAnswerIndexs: undefined, // 正确答案下标
     };
   },
   created() {
@@ -172,48 +174,66 @@ 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;
-    },
-    // 操作:删除选项
-    questionOptionDeleteFun(index) {
-      this.optionsList.splice(index, 1);
-    },
-    // 操作:选择日期
-    onDateChange(date, dateString) {
-      if (date) {
-        this.studyDate = dateString;
-      } else {
-        this.studyDate = '';
-      }
     },
     // 操作:表单提交
-    handleLoginFun(e) {
+    handleSubmitForm(e) {
       e.preventDefault();
-      this.loginForm.validateFields((err, values) => {
+      this.aquestionAddForm.validateFields((err, values) => {
         if (!err) {
+          console.log(values);
+          let engineerTypeInfo = this.formatEngineeringWorkChooseValue(
+            values.engineeringWorkChooseValue
+          ); // 获取工种信息
+          // 需要拼接到请求地址后面的参数
+          let urlParams = {
+            categoryid: this.questionType, // 题目类目ID
+            engineertypeid: values.engineeringWorkChooseValue, // 工种ID
+          };
+          // 接口Body参数
           let params = {
-            type: this.questionType,
-            content: values.content,
-            engineeringWorkChooseValue: values.engineeringWorkChooseValue,
-            studyDate: this.studyDate,
+            content: values.content, // 内容
             finalAnswer: this.formatQuestionFinalAnswerArr(
               values.finalAnswerIndexs
-            ),
-            answers: this.formatQuestionAnswersArr(values),
+            ), // 正确答案
+            engineerTypes: [engineerTypeInfo], // 工种信息集合
+            type: this.questionType, // 题目类别ID
+            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)];
@@ -230,23 +250,23 @@ export default {
       return arr;
     },
     // 表单提交请求
-    httpQuestFun(params) {
+    httpQuestFun(urlParams, params) {
       this.loading = true;
-      console.log(params);
-      setTimeout(() => {
-        this.loading = false;
-      }, 2000);
-      // this.$_http
-      //   .post(this.$_API.INTERFACE_POST_EXAMS_QUESTION_ADD, params)
-      //   .then((res) => {
-      //     console.log(res);
-      //   })
-      //   .catch((err) => {
-      //     console.log(err);
-      //   })
-      //   .finally(() => {
-      //     this.loading = false;
-      //   });
+      this.$_http
+        .post(
+          formateUrlParams(
+            this.$_API.INTERFACE_POST_EXAMS_QUESTION_ADD,
+            urlParams
+          ),
+          params
+        )
+        .then(() => {
+          this.loading = false;
+          this.$message.success('添加判断题成功');
+        })
+        .catch(() => {
+          this.loading = false;
+        });
     },
   },
 };