examQusetionCreateSingle.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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-form-item>
  80. <a-form-item
  81. label="必学日期:"
  82. :label-col="labelCol"
  83. :wrapper-col="wrapperCol"
  84. >
  85. <a-date-picker
  86. @change="onDateChange"
  87. placeholder="请选择日期"
  88. v-decorator="[
  89. 'studyDate',
  90. {
  91. rules: [{ required: true, message: 'Please selete date!' }],
  92. },
  93. ]"
  94. />
  95. </a-form-item>
  96. <a-form-item
  97. label="工种类别:"
  98. :label-col="labelCol"
  99. :wrapper-col="wrapperCol"
  100. >
  101. <a-select
  102. v-decorator="[
  103. 'engineeringWorkChooseValue',
  104. {
  105. rules: [{ required: false, message: 'Please selete date!' }],
  106. initialValue: engineeringWorkChooseValue,
  107. },
  108. ]"
  109. >
  110. <a-select-option
  111. :value="item.value"
  112. v-for="(item, index) in engineeringWorkList"
  113. :key="index"
  114. >
  115. {{ item.title }}
  116. </a-select-option>
  117. </a-select>
  118. </a-form-item>
  119. <a-form-item>
  120. <a-button
  121. class="qusetionSubmitBtn"
  122. type="primary"
  123. html-type="submit"
  124. >提交</a-button
  125. >
  126. </a-form-item>
  127. </a-form>
  128. </a-spin>
  129. </div>
  130. </div>
  131. </template>
  132. <script>
  133. import { ENGINEERING_WORK_LIST } from '@/common/Constant';
  134. export default {
  135. name: 'examQusetionCreateSingle',
  136. props: {},
  137. components: {},
  138. data() {
  139. return {
  140. loading: false, // 是否显示加载动画
  141. labelCol: { span: 6 }, // 表单行中label的占位
  142. wrapperCol: { span: 18 }, // 表单行中内容的占位
  143. loginForm: this.$form.createForm(this, {
  144. name: 'examQusetionAddDanXuan',
  145. }),
  146. questionType: 'DanXuan', // 题目类型:单选题
  147. optionsList: [{ value: '' }, { value: '' }], // 选项列表
  148. engineeringWorkList: [], // 工种数据列表
  149. engineeringWorkChooseValue: '', // 所选工种
  150. studyDate: '', // 开考时间
  151. };
  152. },
  153. created() {
  154. this.initDataFun(); // 初始化数据
  155. },
  156. mounted() {},
  157. beforeDestroy() {},
  158. watch: {},
  159. computed: {},
  160. methods: {
  161. // 初始化数据
  162. initDataFun() {
  163. // 工种类别
  164. this.engineeringWorkList = [
  165. { title: '不限工种', value: '' },
  166. ...ENGINEERING_WORK_LIST,
  167. ];
  168. this.engineeringWorkChooseValue = this.engineeringWorkList[0].value;
  169. },
  170. // 操作:新增选项
  171. questionOptionAddFun() {
  172. this.optionsList.push({ value: '' });
  173. },
  174. // 操作:删除选项
  175. questionOptionDeleteFun(index) {
  176. this.optionsList.splice(index, 1);
  177. },
  178. // 操作:选择日期
  179. onDateChange(date, dateString) {
  180. if (date) {
  181. this.studyDate = dateString;
  182. } else {
  183. this.studyDate = '';
  184. }
  185. },
  186. // 操作:表单提交
  187. handleLoginFun(e) {
  188. e.preventDefault();
  189. this.loginForm.validateFields((err, values) => {
  190. if (!err) {
  191. let params = {
  192. ...values,
  193. };
  194. params.studyDate = this.studyDate;
  195. this.httpQuestFun(params);
  196. }
  197. });
  198. },
  199. // 表单提交请求
  200. httpQuestFun(params) {
  201. this.loading = true;
  202. console.log(params);
  203. setTimeout(() => {
  204. this.loading = false;
  205. }, 2000);
  206. // this.$_http
  207. // .post(this.$_API.INTERFACE_POST_EXAMS_QUESTION_ADD, params)
  208. // .then((res) => {
  209. // console.log(res);
  210. // })
  211. // .catch((err) => {
  212. // console.log(err);
  213. // })
  214. // .finally(() => {
  215. // this.loading = false;
  216. // });
  217. },
  218. },
  219. };
  220. </script>
  221. <style lang="less"></style>
  222. <style lang="less" scoped>
  223. @import '~@/styles/common/variable.less';
  224. </style>