ExamBatchDialog.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <el-dialog
  3. class="exam-batch-dialog"
  4. :visible.sync="dialogVisible"
  5. width="600px"
  6. title="请选择考试批次"
  7. :close-on-press-escape="false"
  8. :close-on-click-modal="false"
  9. append-to-body
  10. >
  11. <el-radio-group size="medium" v-model="examBatchId">
  12. <el-radio v-for="item in examBatchs" :key="item.id" :label="item.id">{{
  13. item.label
  14. }}</el-radio>
  15. </el-radio-group>
  16. <div slot="footer" class="dialog-footer">
  17. <el-button @click="cancel" plain>取消</el-button>
  18. <el-button type="primary" @click="confirm">确认</el-button>
  19. </div>
  20. </el-dialog>
  21. </template>
  22. <script>
  23. import { examMonitorBatchList } from "@/api/invigilation";
  24. import { dateFormatForAPI } from "@/utils/utils";
  25. export default {
  26. name: "exam-batch-dialog",
  27. props: {
  28. initExamid: String,
  29. },
  30. data() {
  31. return {
  32. dialogVisible: false,
  33. examBatchId: null,
  34. examBatchs: [],
  35. userId: this.$store.state.user.id,
  36. };
  37. },
  38. mounted() {
  39. this.getExamList();
  40. },
  41. methods: {
  42. async getExamList() {
  43. const res = await examMonitorBatchList({
  44. userId: this.userId,
  45. pageNumber: 1,
  46. pageSize: 100,
  47. });
  48. this.examBatchs = res.data.data.records.map((item) => {
  49. return {
  50. ...item,
  51. label: `${item.name}【${dateFormatForAPI(
  52. item.startTime
  53. )} - ${dateFormatForAPI(item.endTime)}】`,
  54. };
  55. });
  56. let selectedExam = null;
  57. if (this.initExamid) {
  58. selectedExam = this.examBatchs.find(
  59. (item) => item.id === this.initExamid
  60. );
  61. } else {
  62. selectedExam = this.examBatchs[0];
  63. }
  64. this.examBatchId = selectedExam && selectedExam.id;
  65. this.$emit("confirm", selectedExam);
  66. },
  67. cancel() {
  68. this.dialogVisible = false;
  69. },
  70. open() {
  71. this.dialogVisible = true;
  72. },
  73. confirm() {
  74. if (!this.examBatchId) {
  75. this.$message.error("请选择考试批次!");
  76. return;
  77. }
  78. const exam = this.examBatchs.find((item) => item.id === this.examBatchId);
  79. this.$emit("confirm", exam);
  80. this.cancel();
  81. },
  82. },
  83. };
  84. </script>