form.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <xn-form-container
  3. :title="formData.id ? '编辑t_exam_paper' : '增加t_exam_paper'"
  4. :width="700"
  5. :visible="visible"
  6. :destroy-on-close="true"
  7. @close="onClose"
  8. >
  9. <a-form ref="formRef" :model="formData" :rules="formRules" layout="vertical">
  10. <a-form-item label="年级:" name="level">
  11. <a-select
  12. v-model:value="formData.level"
  13. :options="gradeLevelOptions"
  14. style="width: 100%"
  15. placeholder="请选择年级"
  16. >
  17. </a-select>
  18. </a-form-item>
  19. <a-form-item label="学科:" name="subjectId">
  20. <a-select
  21. v-model:value="formData.subjectId"
  22. :options="susbjectOptions"
  23. style="width: 100%"
  24. placeholder="请选择学科"
  25. >
  26. </a-select>
  27. </a-form-item>
  28. <a-form-item label="试卷类型:" name="paperType">
  29. <a-select
  30. v-model:value="formData.paperType"
  31. :options="paperTypeOptions"
  32. style="width: 100%"
  33. placeholder="请选择试卷类型"
  34. >
  35. </a-select>
  36. </a-form-item>
  37. <a-form-item label="试卷名称:" name="name">
  38. <a-input v-model:value="formData.name" placeholder="请输入试卷名称" allow-clear />
  39. </a-form-item>
  40. <a-form-item :key="index" :label="'标题'+(index+1)+':'" required v-for="(titleItem,index) in titleItems">
  41. <a-input v-model="titleItem.name" style="width: 65%"/>
  42. <a-button style="margin-left: 20px" @click="addQuestion(titleItem)">添加题目</a-button>
  43. <a-button style="margin-left: 20px;background-color: red;" @click="titleItems.splice(index,1)" type="primary">删除</a-button>
  44. <a-card class="exampaper-item-box" v-if="titleItem.questionItems.length!==0">
  45. <a-form-item :key="questionIndex" :label="'题目'+(questionIndex+1)+':'"
  46. v-for="(questionItem,questionIndex) in titleItem.questionItems" style="margin-bottom: 15px">
  47. <a-row>
  48. <a-col :span="23">
  49. <QuestionShow :qType="questionItem.questionType" :question="questionItem"/>
  50. </a-col>
  51. <a-col :span="1">
  52. <a-button @click="titleItem.value.questionItems.splice(questionIndex,1)">删除</a-button>
  53. </a-col>
  54. </a-row>
  55. </a-form-item>
  56. </a-card>
  57. </a-form-item>
  58. <a-form-item label="建议时长:" name="suggestTime">
  59. <a-input-number id="inputNumber" width="100%" v-model:value="formData.suggestTime" :min="1" :max="180" placeholder="分钟" allow-clear/>
  60. </a-form-item>
  61. </a-form>
  62. <template #footer>
  63. <a-button style="margin-right: 8px" @click="addTitle">添加标题</a-button>
  64. <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
  65. <a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
  66. </template>
  67. </xn-form-container>
  68. </template>
  69. <script setup name="tExamPaperForm">
  70. import { cloneDeep } from 'lodash-es'
  71. import { required } from '@/utils/formRules'
  72. import tExamPaperApi from '@/api/paper/examPaperApi'
  73. import tool from "@/utils/tool";
  74. // 抽屉状态
  75. const visible = ref(false)
  76. const emit = defineEmits({ successful: null })
  77. const formRef = ref()
  78. // 表单数据
  79. const formData = ref({})
  80. const submitLoading = ref(false)
  81. // 打开抽屉
  82. const onOpen = (record) => {
  83. visible.value = true
  84. if (record) {
  85. let recordData = cloneDeep(record)
  86. formData.value = Object.assign({}, recordData)
  87. }
  88. }
  89. // 关闭抽屉
  90. const onClose = () => {
  91. formRef.value.resetFields()
  92. formData.value = {}
  93. visible.value = false
  94. }
  95. // 默认要校验的
  96. const formRules = {
  97. }
  98. // 验证并提交数据
  99. const onSubmit = () => {
  100. formRef.value.validate().then(() => {
  101. submitLoading.value = true
  102. const formDataParam = cloneDeep(formData.value)
  103. tExamPaperApi
  104. .tExamPaperSubmitForm(formDataParam, formDataParam.id)
  105. .then(() => {
  106. onClose()
  107. emit('successful')
  108. })
  109. .finally(() => {
  110. submitLoading.value = false
  111. })
  112. })
  113. }
  114. const gradeLevelOptions = tool.dictList('SEMESTER')
  115. const susbjectOptions = tool.dictList('SUBJECT')
  116. const paperTypeOptions = tool.dictList('PAPER_TYPE')
  117. const titleItems = ref([])
  118. const currentTitleItem = ref(null)
  119. const addTitle = () => {
  120. titleItems.value.push({
  121. name: '',
  122. questionItems: []
  123. })
  124. }
  125. const addQuestion = (titleItem) =>{
  126. currentTitleItem.value = titleItem
  127. this.questionPage.showDialog = true
  128. this.search()
  129. }
  130. // 抛出函数
  131. defineExpose({
  132. onOpen
  133. })
  134. </script>
  135. <style>
  136. .exampaper-item-box {
  137. .q-title {
  138. margin: 0px 5px 0px 5px;
  139. }
  140. .q-item-content {
  141. }
  142. }
  143. </style>