StuImport.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div class="stu-import">
  3. <qm-low-form :fields="fields">
  4. <template #tip>
  5. <div class="tip">
  6. 导入参数设置为:考试年度 - {{ year }};考次 - {{ yearHalf }}
  7. </div>
  8. </template>
  9. </qm-low-form>
  10. <a-table :data-source="dataList" :columns="columns" size="middle" bordered>
  11. <template #bodyCell="{ column, record }">
  12. <template v-if="column.key === 'operation'">
  13. <qm-button type="link" @click="openImportDialog(record)"
  14. >导入</qm-button
  15. >
  16. <qm-button type="link" @click="clear(record)">清空</qm-button>
  17. </template>
  18. </template>
  19. </a-table>
  20. <SetImportParamsDialog
  21. v-model="showSetParamsDialog"
  22. v-if="showSetParamsDialog"
  23. ></SetImportParamsDialog>
  24. <StuImportFileDialog
  25. v-model="showStuImportFileDialog"
  26. v-if="showStuImportFileDialog"
  27. >
  28. </StuImportFileDialog>
  29. </div>
  30. </template>
  31. <script name="StuImport" lang="ts" setup>
  32. import { ref } from "vue";
  33. import SetImportParamsDialog from "./SetImportParamsDialog.vue";
  34. import { getStuList } from "@/ap/baseDataConfig";
  35. import { useUserStore } from "@/store";
  36. import { getStuImportSet, clearStuData } from "@/ap/baseDataConfig";
  37. import StuImportFileDialog from "./StuImportFileDialog.vue";
  38. import type { TableColumnsType } from "@qmth/ui";
  39. const userStore = useUserStore();
  40. const showSetParamsDialog = ref(false);
  41. const showStuImportFileDialog = ref(false);
  42. const year = ref();
  43. const yearHalf = ref();
  44. const loading = ref(false);
  45. const fullYear = (num: number) => {
  46. return String(num).length == 4 ? num : "20" + num;
  47. };
  48. const _getStuImportSet = () => {
  49. getStuImportSet({ examId: userStore.curExam?.id as number }).then(
  50. (res: any) => {
  51. year.value = res?.year ? fullYear(res.year) : "";
  52. yearHalf.value = res?.yearHalf;
  53. }
  54. );
  55. };
  56. _getStuImportSet();
  57. const fields = ref([
  58. {
  59. type: "button",
  60. text: "设置导入参数",
  61. attrs: {
  62. onClick: () => {
  63. showSetParamsDialog.value = true;
  64. },
  65. },
  66. },
  67. {
  68. cell: "tip",
  69. },
  70. ]);
  71. const columns: TableColumnsType = [
  72. {
  73. title: "序号",
  74. dataIndex: "index",
  75. key: "index",
  76. width: 100,
  77. customRender: ({ index }) => `${index + 1}`,
  78. },
  79. {
  80. title: "科目代码",
  81. dataIndex: "subjectCode",
  82. },
  83. {
  84. title: "科目名称",
  85. dataIndex: "subjectName",
  86. },
  87. {
  88. title: "已导入考生数",
  89. dataIndex: "studentCount",
  90. },
  91. {
  92. title: "操作",
  93. key: "operation",
  94. width: 300,
  95. },
  96. ];
  97. const dataList = ref([]);
  98. const search = () => {
  99. loading.value = true;
  100. getStuList({ examId: userStore.curExam?.id as number })
  101. .then((res: any) => {
  102. dataList.value = res || [];
  103. })
  104. .finally(() => {
  105. loading.value = false;
  106. });
  107. };
  108. search();
  109. const clear = (row: any) => {
  110. window.$confirm({
  111. title: () => "系统通知",
  112. content: () => "请确认是否立即删除?",
  113. onOk() {
  114. clearStuData({
  115. examId: userStore.curExam?.id as number,
  116. subjectCode: row.subjectCode,
  117. }).then(() => {
  118. window.$message.success("操作成功");
  119. search();
  120. });
  121. },
  122. });
  123. };
  124. const curRow = ref(null);
  125. const openImportDialog = (row: any) => {
  126. curRow.value = row;
  127. showStuImportFileDialog.value = true;
  128. };
  129. </script>
  130. <style lang="less" scoped>
  131. .stu-import {
  132. padding: 0 20px 20px 20px;
  133. .tip {
  134. height: 32px;
  135. line-height: 32px;
  136. border-radius: 6px;
  137. background: #e8f3ff;
  138. margin-left: 8px;
  139. padding: 0 12px;
  140. color: #165dff;
  141. }
  142. }
  143. </style>