examQusetionCreateMultiple.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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="loginForm"
  7. @submit="handleLoginFun"
  8. style="width: 500px;"
  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="20"
  20. v-decorator="[
  21. 'content',
  22. {
  23. rules: [{ required: true, message: 'Please input content!' }],
  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 > 2"
  41. class="question-option-list-row-delete"
  42. @click="questionOptionDeleteFun(index)"
  43. >删除</span
  44. >
  45. <a-form-item
  46. :label="index | formatQuestionIndex"
  47. :label-col="labelCol"
  48. :wrapper-col="wrapperCol"
  49. >
  50. <a-input
  51. placeholder="选项内容"
  52. :maxLength="200"
  53. v-decorator="[
  54. `answers-${index}`,
  55. {
  56. rules: [
  57. { required: true, message: 'Please input content!' },
  58. ],
  59. },
  60. ]"
  61. />
  62. </a-form-item>
  63. </div>
  64. <a-form-item
  65. label="正确答案"
  66. :label-col="labelCol"
  67. :wrapper-col="wrapperCol"
  68. >
  69. <!-- <a-input
  70. placeholder="答案格式为大写字母"
  71. :maxLength="200"
  72. v-decorator="[
  73. 'finalAnswer',
  74. {
  75. rules: [{ required: true, message: 'Please input content!' }],
  76. },
  77. ]"
  78. /> -->
  79. <a-select
  80. mode="multiple"
  81. v-decorator="[
  82. 'finalAnswerIndexs',
  83. {
  84. rules: [{ required: true, message: 'Please input content!' }],
  85. },
  86. ]"
  87. >
  88. <a-select-option
  89. v-for="(item, index) in optionsList"
  90. :key="index"
  91. :value="index"
  92. >
  93. {{ index | formatQuestionIndex }}
  94. </a-select-option>
  95. </a-select>
  96. </a-form-item>
  97. <a-form-item
  98. label="必学日期"
  99. :label-col="labelCol"
  100. :wrapper-col="wrapperCol"
  101. >
  102. <a-date-picker
  103. @change="onDateChange"
  104. placeholder="请选择日期"
  105. v-decorator="[
  106. 'studyDate',
  107. {
  108. rules: [{ required: true, message: 'Please selete date!' }],
  109. },
  110. ]"
  111. />
  112. </a-form-item>
  113. <a-form-item
  114. label="工种类别"
  115. :label-col="labelCol"
  116. :wrapper-col="wrapperCol"
  117. >
  118. <a-select
  119. v-decorator="[
  120. 'engineeringWorkChooseValue',
  121. {
  122. rules: [
  123. {
  124. required: false,
  125. message: 'Please selete engineering work!',
  126. },
  127. ],
  128. initialValue: engineeringWorkChooseValue,
  129. },
  130. ]"
  131. >
  132. <a-select-option
  133. :value="item.code"
  134. v-for="(item, index) in engineeringWorkList"
  135. :key="index"
  136. >
  137. {{ item.name }}
  138. </a-select-option>
  139. </a-select>
  140. </a-form-item>
  141. <a-form-item>
  142. <a-button
  143. class="qusetionSubmitBtn"
  144. type="primary"
  145. html-type="submit"
  146. >提交</a-button
  147. >
  148. </a-form-item>
  149. </a-form>
  150. </a-spin>
  151. </div>
  152. </div>
  153. </template>
  154. <script>
  155. import { ENGINEERING_WORK_LIST } from '@/common/Constant';
  156. import { formatQuestionIndex } from '@/filters';
  157. export default {
  158. name: 'examQusetionCreateMultiple',
  159. props: {},
  160. components: {},
  161. data() {
  162. return {
  163. loading: false, // 是否显示加载动画
  164. labelCol: { span: 6 }, // 表单行中label的占位
  165. wrapperCol: { span: 18 }, // 表单行中内容的占位
  166. loginForm: this.$form.createForm(this, {
  167. name: 'examQusetionAddDuoXuan',
  168. }),
  169. questionType: 'DuoXuan', // 题目类型:多选题
  170. optionsList: [{ value: '' }, { value: '' }], // 选项列表
  171. engineeringWorkList: [], // 工种数据列表
  172. engineeringWorkChooseValue: '', // 所选工种
  173. studyDate: '', // 开考时间
  174. };
  175. },
  176. created() {
  177. this.initDataFun(); // 初始化数据
  178. },
  179. mounted() {},
  180. beforeDestroy() {},
  181. watch: {},
  182. computed: {},
  183. methods: {
  184. // 初始化数据
  185. initDataFun() {
  186. // 工种类别
  187. this.engineeringWorkList = [
  188. { name: '不限工种', code: '' },
  189. ...ENGINEERING_WORK_LIST,
  190. ];
  191. this.engineeringWorkChooseValue = this.engineeringWorkList[0].code;
  192. },
  193. // 操作:新增选项
  194. questionOptionAddFun() {
  195. this.optionsList.push({ value: '' });
  196. },
  197. // 操作:删除选项
  198. questionOptionDeleteFun(index) {
  199. this.optionsList.splice(index, 1);
  200. },
  201. // 操作:选择答案
  202. handleChange(values) {
  203. console.log(values);
  204. },
  205. // 操作:选择日期
  206. onDateChange(date, dateString) {
  207. if (date) {
  208. this.studyDate = dateString;
  209. } else {
  210. this.studyDate = '';
  211. }
  212. },
  213. // 操作:表单提交
  214. handleLoginFun(e) {
  215. e.preventDefault();
  216. this.loginForm.validateFields((err, values) => {
  217. if (!err) {
  218. let params = {
  219. type: this.questionType,
  220. content: values.content,
  221. engineeringWorkChooseValue: values.engineeringWorkChooseValue,
  222. studyDate: this.studyDate,
  223. finalAnswer: this.formatQuestionFinalAnswerArr(
  224. values.finalAnswerIndexs
  225. ),
  226. answers: this.formatQuestionAnswersArr(values),
  227. };
  228. this.httpQuestFun(params);
  229. }
  230. });
  231. },
  232. // 把答案下标转换为大写英文字母放入一个数组中
  233. formatQuestionFinalAnswerArr(indexs) {
  234. let arr = '';
  235. indexs.forEach((item) => {
  236. arr += formatQuestionIndex(item);
  237. });
  238. return [arr];
  239. },
  240. // 把选项放入一个数组中
  241. formatQuestionAnswersArr(values) {
  242. let arr = [];
  243. for (let key in values) {
  244. if (key.includes('answers-')) {
  245. arr.push(values[key]);
  246. }
  247. }
  248. return arr;
  249. },
  250. // 表单提交请求
  251. httpQuestFun(params) {
  252. this.loading = true;
  253. console.log(params);
  254. setTimeout(() => {
  255. this.loading = false;
  256. }, 2000);
  257. // this.$_http
  258. // .post(this.$_API.INTERFACE_POST_EXAMS_QUESTION_ADD, params)
  259. // .then((res) => {
  260. // console.log(res);
  261. // })
  262. // .catch((err) => {
  263. // console.log(err);
  264. // })
  265. // .finally(() => {
  266. // this.loading = false;
  267. // });
  268. },
  269. },
  270. };
  271. </script>
  272. <style lang="less"></style>
  273. <style lang="less" scoped>
  274. @import '~@/styles/common/variable.less';
  275. </style>