examQusetionCreateGapFilling.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <div class="app-container">
  3. <div class="common-card exam-question-create-body">
  4. <a-spin :spinning="loading">
  5. <a-form
  6. :form="aquestionAddForm"
  7. @submit="handleSubmitForm"
  8. style="width: 515px;"
  9. :loading="loading"
  10. >
  11. <a-form-item
  12. label="试题内容"
  13. :label-col="labelCol"
  14. :wrapper-col="wrapperCol"
  15. >
  16. <a-textarea
  17. placeholder="试题内容"
  18. :auto-size="{ minRows: 3, maxRows: 5 }"
  19. :maxLength="500"
  20. v-decorator="[
  21. 'content',
  22. {
  23. rules: [{ required: true, message: '请输入试题内容!' }],
  24. },
  25. ]"
  26. />
  27. </a-form-item>
  28. <div class="question-option">
  29. <span class="question-option-title">正确答案:</span>
  30. <span class="question-option-add" @click="questionOptionAddFun"
  31. >新增填空</span
  32. >
  33. </div>
  34. <div
  35. class="question-option-list-row"
  36. v-for="(item, index) in optionsList"
  37. :key="index"
  38. >
  39. <span
  40. v-if="optionsList.length > 1"
  41. class="question-option-list-row-delete"
  42. @click="questionOptionDeleteFun(index)"
  43. >删除</span
  44. >
  45. <a-form-item
  46. label=" "
  47. :label-col="labelCol"
  48. :wrapper-col="wrapperCol"
  49. >
  50. <a-input
  51. placeholder="填空需与试题一一对应"
  52. :maxLength="100"
  53. v-decorator="[
  54. `answers-${index}`,
  55. {
  56. rules: [{ required: true, message: '请输入填空答案!' }],
  57. },
  58. ]"
  59. />
  60. </a-form-item>
  61. </div>
  62. <div class="create-select-div">
  63. <span>试题类型:</span>
  64. <div class="create-select-row">
  65. <div class="create-select-item">
  66. <span>父类</span>
  67. <a-select
  68. v-model="typeConditionParentValue"
  69. @change="selectTypeConditionParent"
  70. >
  71. <a-select-option
  72. v-for="(item, index) in typeConditionParentList"
  73. :key="index"
  74. :value="item.id"
  75. >
  76. {{ item.name }}
  77. </a-select-option>
  78. </a-select>
  79. </div>
  80. <div class="create-select-item">
  81. <span>子类</span>
  82. <a-select v-model="typeConditionChildrenValue">
  83. <a-select-option
  84. v-for="(item, index) in typeConditionChildrenList"
  85. :key="index"
  86. :value="item.id"
  87. >
  88. {{ item.name }}
  89. </a-select-option>
  90. </a-select>
  91. </div>
  92. </div>
  93. </div>
  94. <a-form-item
  95. label="工种类别"
  96. :label-col="labelCol"
  97. :wrapper-col="wrapperCol"
  98. >
  99. <a-select
  100. v-decorator="[
  101. 'engineeringWorkChooseValue',
  102. {
  103. rules: [
  104. {
  105. required: false,
  106. },
  107. ],
  108. initialValue: engineeringWorkChooseValue,
  109. },
  110. ]"
  111. >
  112. <a-select-option
  113. v-for="(item, index) in engineeringWorkList"
  114. :key="index"
  115. :value="item.id"
  116. >
  117. {{ item.name }}
  118. </a-select-option>
  119. </a-select>
  120. </a-form-item>
  121. <a-form-item>
  122. <a-button
  123. class="qusetionSubmitBtn"
  124. type="primary"
  125. html-type="submit"
  126. >提交</a-button
  127. >
  128. </a-form-item>
  129. </a-form>
  130. </a-spin>
  131. </div>
  132. <div class="company-info">
  133. <span>
  134. copyright © 浮游科技有限公司出品
  135. </span>
  136. </div>
  137. </div>
  138. </template>
  139. <script>
  140. import { formateUrlParams, formatePathParams } from '@/filters';
  141. import { mapGetters } from 'vuex';
  142. export default {
  143. name: 'examQusetionCreateGapFilling',
  144. props: {},
  145. components: {},
  146. data() {
  147. return {
  148. loading: false, // 是否显示加载动画
  149. labelCol: { span: 6 }, // 表单行中label的占位
  150. wrapperCol: { span: 18 }, // 表单行中内容的占位
  151. aquestionAddForm: this.$form.createForm(this, {
  152. name: 'examQusetionAddDuoXuan',
  153. }),
  154. questionType: 'TianKong', // 试题类型:填空题
  155. optionsList: [{ value: '' }], // 选项列表
  156. typeConditionParentList: [], // 试题类型-父类列表
  157. typeConditionParentValue: '', // 父类所选值
  158. typeConditionChildrenList: [], // 试题类型-子类列表
  159. typeConditionChildrenValue: '', // 子类所选值
  160. engineeringWorkList: [], // 工种数据列表
  161. engineeringWorkChooseValue: '', // 所选工种
  162. finalAnswerIndexs: undefined, // 正确答案下标
  163. };
  164. },
  165. created() {
  166. this.initDataFun(); // 初始化数据
  167. },
  168. mounted() {},
  169. beforeDestroy() {},
  170. watch: {},
  171. computed: {
  172. ...mapGetters([
  173. 'GET_ENGINEERING_WORK_LIST',
  174. 'GET_EXAM_QUESTION_TYPE_CONDITION_PARENT',
  175. ]),
  176. },
  177. methods: {
  178. // 初始化数据
  179. initDataFun() {
  180. // 试题类型
  181. this.typeConditionParentList = [
  182. ...this.GET_EXAM_QUESTION_TYPE_CONDITION_PARENT,
  183. ];
  184. this.typeConditionParentValue = this.typeConditionParentList[0].id;
  185. // 工种类别
  186. this.engineeringWorkList = [
  187. { name: '不限', id: '' },
  188. ...this.GET_ENGINEERING_WORK_LIST,
  189. ];
  190. this.getTableChildrenListFun(); // 查询:试题类型列表-子类
  191. },
  192. // 查询:试题类型列表-子类
  193. getTableChildrenListFun() {
  194. this.loading = true;
  195. let params = {
  196. categoryId: this.typeConditionParentValue,
  197. };
  198. this.$_http
  199. .get(
  200. formatePathParams(
  201. this.$_API.INTERFACE_GET_EXAMS_QUESTION_TYPE_CONDITION_CHILDRENS,
  202. params
  203. )
  204. )
  205. .then((res) => {
  206. this.typeConditionChildrenList = res.data;
  207. this.typeConditionChildrenValue = this.typeConditionChildrenList[0].id;
  208. this.loading = false;
  209. })
  210. .catch(() => {
  211. this.loading = false;
  212. });
  213. },
  214. // 操作:新增选项
  215. questionOptionAddFun() {
  216. this.optionsList.push({ value: '' });
  217. },
  218. // 操作:删除选项
  219. questionOptionDeleteFun(index) {
  220. this.optionsList.splice(index, 1);
  221. },
  222. // 操作:选择了父类
  223. selectTypeConditionParent() {
  224. this.getTableChildrenListFun(); // 查询:试题类型列表-子类
  225. },
  226. // 操作:表单提交
  227. handleSubmitForm(e) {
  228. e.preventDefault();
  229. this.aquestionAddForm.validateFields((err, values) => {
  230. if (!err) {
  231. // let engineerTypeInfo = this.formatEngineeringWorkChooseValue(
  232. // values.engineeringWorkChooseValue
  233. // ); // 获取工种信息
  234. // 需要拼接到请求地址后面的参数
  235. let urlParams = {
  236. categoryid: this.typeConditionChildrenValue, // 试题类型ID
  237. engineertypeid: values.engineeringWorkChooseValue, // 工种ID
  238. };
  239. // 接口Body参数
  240. let params = {
  241. content: values.content, // 内容
  242. finalAnswer: this.formatQuestionAnswersArr(values), // 正确答案
  243. // engineerTypes: [engineerTypeInfo], // 工种信息集合
  244. type: this.questionType, // 试题类型ID
  245. answers: [], // 选项
  246. };
  247. this.httpQuestFun(urlParams, params);
  248. }
  249. });
  250. },
  251. // 获取工种信息
  252. formatEngineeringWorkChooseValue(id) {
  253. let seleteItem = {};
  254. for (let i = 0; i < this.engineeringWorkList.length; i++) {
  255. let item = this.engineeringWorkList[i];
  256. if (item.id === id) {
  257. seleteItem = item;
  258. break;
  259. }
  260. }
  261. return seleteItem;
  262. },
  263. // 把答案放入一个数组中
  264. formatQuestionAnswersArr(values) {
  265. let arr = [];
  266. for (let key in values) {
  267. if (key.includes('answers-')) {
  268. arr.push(values[key]);
  269. }
  270. }
  271. return arr;
  272. },
  273. // 表单提交请求
  274. httpQuestFun(urlParams, params) {
  275. this.loading = true;
  276. this.$_http
  277. .post(
  278. formateUrlParams(
  279. this.$_API.INTERFACE_POST_EXAMS_QUESTION_ADD,
  280. urlParams
  281. ),
  282. params
  283. )
  284. .then(() => {
  285. this.loading = false;
  286. this.$message.success('添加填空题成功');
  287. })
  288. .catch(() => {
  289. this.loading = false;
  290. });
  291. },
  292. },
  293. };
  294. </script>
  295. <style lang="less"></style>
  296. <style lang="less" scoped>
  297. @import '~@/styles/common/variable.less';
  298. </style>