index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <script setup lang="ts">
  2. import { PageWrapper } from '/@/components/Page';
  3. import { useTable, BasicTable, TableAction } from '/@/components/Table';
  4. import { searchFormSchema, tableColumns } from './data.config';
  5. import { reactive, computed } from 'vue';
  6. import { Recordable } from 'vite-plugin-mock';
  7. import { useMessage } from '/@/hooks/web/useMessage';
  8. import {
  9. getStudentReportRecordPlanPage,
  10. postStudentReportRecordAllSign,
  11. postStudentReportRecordExportQuery,
  12. postStudentReportRecordUpdateStduyStatus,
  13. postStudentReportRecordSign,
  14. } from '/@/services/apis/StudentReportRecordController';
  15. import { downloadByData } from '/@/utils/file/download';
  16. import { formatToDate } from '/@/utils/dateUtil';
  17. import PlanTree from './planTree.vue';
  18. import { Switch } from 'ant-design-vue';
  19. import { useLoading } from '/@/components/Loading';
  20. import { usePermission } from '/@/hooks/web/usePermission';
  21. const searchInfo = reactive<Recordable>({});
  22. const { createConfirm, createMessage } = useMessage();
  23. const { hasPermission } = usePermission();
  24. const [openFullLoading, closeFullLoading] = useLoading({
  25. tip: '处理中...',
  26. });
  27. const [registerTable, { reload, getSelectRowKeys, getForm, clearSelectedRowKeys }] = useTable({
  28. api: getStudentReportRecordPlanPage,
  29. title: '报到计划表',
  30. rowKey: 'id',
  31. columns: tableColumns,
  32. formConfig: {
  33. labelWidth: 120,
  34. schemas: searchFormSchema,
  35. },
  36. useSearchForm: true,
  37. showTableSetting: true,
  38. bordered: true,
  39. immediate: false,
  40. canResize: true,
  41. actionColumn: {
  42. width: 120,
  43. title: '操作',
  44. dataIndex: 'action',
  45. slots: { customRender: 'action' },
  46. fixed: 'right',
  47. },
  48. rowSelection: {
  49. type: 'checkbox',
  50. getCheckboxProps: (record: Recordable) => ({
  51. disabled: record.isReport === 1,
  52. }),
  53. },
  54. });
  55. const hasSelected = computed(() => getSelectRowKeys().length > 0);
  56. const handleChangeReport = async () => {
  57. try {
  58. openFullLoading();
  59. const keys: Recordable[] = [];
  60. getSelectRowKeys().forEach((item) => {
  61. keys.push({ id: item });
  62. });
  63. if (keys.length > 0) {
  64. await postStudentReportRecordAllSign(keys);
  65. clearSelectedRowKeys();
  66. await reload();
  67. }
  68. } finally {
  69. closeFullLoading();
  70. }
  71. };
  72. const handleChangeStduyStatus = (record: any) => {
  73. createConfirm({
  74. iconType: 'warning',
  75. title: '温馨提醒',
  76. content: '确认切换当前学生就读方式?',
  77. onOk: async () => {
  78. try {
  79. await postStudentReportRecordUpdateStduyStatus({ id: record.id });
  80. createMessage.success('切换成功');
  81. await reload();
  82. } catch (e) {
  83. createMessage.error('切换失败');
  84. }
  85. },
  86. okText: '确认',
  87. cancelText: '取消',
  88. });
  89. };
  90. const handleExport = async () => {
  91. if (!searchInfo.studentReportPlanId) {
  92. createMessage.warning('请先选择计划再导出');
  93. return;
  94. }
  95. const postData = getForm().getFieldsValue();
  96. downloadByData(
  97. (await postStudentReportRecordExportQuery({ ...postData, ...searchInfo })).data,
  98. `学生报到信息${formatToDate(new Date())}.xlsx`,
  99. );
  100. };
  101. function handleSelect(id) {
  102. searchInfo.studentReportPlanId = id;
  103. reload();
  104. }
  105. const handleReport = async (record) => {
  106. await postStudentReportRecordSign({ id: record.id });
  107. createMessage.success('已成功修改状态');
  108. clearSelectedRowKeys();
  109. reload();
  110. };
  111. </script>
  112. <template>
  113. <PageWrapper dense contentFullHeight fixedHeight contentClass="flex">
  114. <PlanTree class="w-1/3 xl:w-1/4" @select="handleSelect" />
  115. <BasicTable @register="registerTable" class="w-2/3 xl:w-3/4" :searchInfo="searchInfo">
  116. <template #toolbar>
  117. <a-button
  118. type="primary"
  119. @click="handleChangeReport"
  120. :disabled="!hasSelected"
  121. v-auth="'schoolOpens:report'"
  122. >
  123. 变更为已报到
  124. </a-button>
  125. <a-button type="primary" @click="handleExport">导出</a-button>
  126. </template>
  127. <template #action="{ record }">
  128. <TableAction
  129. :actions="[
  130. {
  131. label: '切换就读方式',
  132. onClick: handleChangeStduyStatus.bind(null, record),
  133. },
  134. ]"
  135. />
  136. </template>
  137. <template #isReport="{ record }">
  138. <Switch :checked="record.isReport === 1" @change="handleReport(record)" />
  139. </template>
  140. </BasicTable>
  141. </PageWrapper>
  142. </template>
  143. <style scoped lang="less"></style>