Browse Source

feat:修改分班

DESKTOP-USV654P\pc 8 months ago
parent
commit
9d0ba8ba3d

+ 216 - 0
src/views/educational/division/components/DsionStep2_1.vue

@@ -0,0 +1,216 @@
+<template>
+  <div class="dsion-step2">
+    <BasicTable @register="registerTable" :searchInfo="searchInfo">
+      <template #toolbar>
+        <a-button type="primary" @click="handelImport">导入</a-button>
+        <a-button type="primary" @click="handelAdd">添加</a-button>
+      </template>
+
+      <template #majorSetId="{ record, column }">
+        <Select
+          v-model:value="record[column.dataIndex]"
+          :options="majorSetOptions"
+          style="margin: -5px 0; width: 100%"
+        />
+      </template>
+      <template #name="{ record, column }">
+        <a-input
+          v-model:value="record[column.dataIndex]"
+          placeholder="班级名称"
+          style="margin: -5px 0; width: 100%"
+        />
+      </template>
+      <template #number="{ record, column }">
+        <a-input-number
+          v-model:value="record[column.dataIndex]"
+          placeholder="班级人数"
+          style="margin: -5px 0; width: 100%"
+        />
+      </template>
+      <template #teacherId="{ record, column }">
+        <Select
+          v-model:value="record[column.dataIndex]"
+          :options="teacherOptions"
+          style="margin: -5px 0; width: 100%"
+        />
+      </template>
+      <template #classroomId="{ record, column }">
+        <Select
+          v-model:value="record[column.dataIndex]"
+          :options="classroomOptions"
+          style="margin: -5px 0; width: 100%"
+        />
+      </template>
+      <template #isOrderClass="{ record, column }">
+        <Checkbox v-model:checked="record[column.dataIndex]" />
+      </template>
+      <template #sortCode="{ record, column }">
+        <a-input-number
+          v-model:value="record[column.dataIndex]"
+          placeholder="排序"
+          style="margin: -5px 0; width: 100%"
+        />
+      </template>
+      <template #action="{ record }">
+        <TableAction
+          :actions="[
+            {
+              label: '保存',
+              onClick: handleSave.bind(null, record),
+            },
+            {
+              label: '删除',
+              color: 'error',
+              onClick: handleDelete.bind(null, record),
+            },
+          ]"
+        />
+      </template>
+    </BasicTable>
+
+    <FormImport @register="registerImportModal" @success="handleSuccess" />
+  </div>
+</template>
+
+<script setup lang="ts">
+  import { reactive, ref, watch, onMounted } from 'vue';
+  import {
+    BasicTable,
+    useTable,
+    TableAction,
+    EditRecordRow,
+    ActionItem,
+  } from '/@/components/Table';
+  import { table2Columns } from '../data.config';
+  import { useMessage } from '/@/hooks/web/useMessage';
+  import { buildUUID } from '/@/utils/uuid';
+  import FormImport from './import.vue';
+  import { useModal } from '/@/components/Modal';
+  import {
+    deleteBandingBandingTaskClass,
+    getBandingTaskClassList,
+    postBandingBandingTaskClass,
+    putBandingBandingTaskClass,
+  } from '/@/services/apis/BandingTaskClassController';
+  import { cloneDeep } from 'lodash-es';
+  import ApiSelect from '/@/components/Form/src/components/ApiSelect.vue';
+  import { getMajorSetOption } from '/@/api/userMagic';
+  import { requestMagicApi } from '/@/api/magicApi';
+  import { Checkbox, Select } from 'ant-design-vue';
+
+  const [registerImportModal, { openModal: openImportModal }] = useModal();
+
+  const [registerTable, { reload, insertTableDataRecord, deleteTableDataRecord, getDataSource }] =
+    useTable({
+      api: getBandingTaskClassList,
+      title: '班级列表',
+      rowKey: 'id',
+      columns: table2Columns,
+      useSearchForm: false,
+      showTableSetting: true,
+      bordered: true,
+      immediate: false,
+      canResize: true,
+      pagination: false,
+      actionColumn: {
+        width: 120,
+        title: '操作',
+        dataIndex: 'action',
+        slots: { customRender: 'action' },
+        fixed: 'right',
+      },
+      afterFetch: (data) => {
+        return data.map((item) => {
+          item.isOrderClass = item.isOrderClass === 1;
+          return item;
+        });
+      },
+    });
+
+  const searchInfo = reactive<Recordable>({});
+
+  const props = defineProps({
+    taskId: { type: String, default: '' },
+  });
+
+  watch(
+    () => props.taskId,
+    async (newVal) => {
+      if (newVal) {
+        searchInfo.bandingTaskId = newVal;
+      }
+    },
+  );
+
+  const { createMessage } = useMessage();
+
+  const handelAdd = () => {
+    insertTableDataRecord({ id: buildUUID(), _newRow: true, isOrderClass: false });
+  };
+
+  const handleDelete = async (record: EditRecordRow) => {
+    if (record._newRow) {
+      deleteTableDataRecord(record.id);
+    } else {
+      await deleteBandingBandingTaskClass([record.id]);
+      reload();
+    }
+  };
+
+  const handleSave = async (record: EditRecordRow) => {
+    const valid = true; // await record.onValid?.();
+    if (valid) {
+      const data = {
+        ...record,
+      };
+      data['isOrderClass'] = data['isOrderClass'] ? 1 : 0;
+      if (record._newRow) {
+        await postBandingBandingTaskClass({
+          ...data,
+          bandingTaskId: props.taskId,
+        } as API.AddBandingTaskClassDto);
+      } else {
+        const _dataSource = getDataSource();
+        const editData = _dataSource.filter((row) => row.id === record.id)[0];
+        Object.assign(editData, data);
+        await putBandingBandingTaskClass(editData as API.UpdateBandingTaskClassDto);
+      }
+      reload();
+    } else {
+      createMessage.error({ content: '请填写正确的数据', key: 'saving' });
+    }
+  };
+
+  const handelImport = () => {
+    openImportModal(true, { baseData: { taskId: props.taskId } });
+  };
+
+  const handleSuccess = () => {
+    reload();
+  };
+
+  const validateStep = () => {
+    return true;
+  };
+  const reloadStep = () => {
+    reload();
+  };
+
+  const majorSetOptions = ref([]);
+  const teacherOptions = ref([]);
+  const classroomOptions = ref([]);
+
+  onMounted(async () => {
+    majorSetOptions.value = await getMajorSetOption();
+    teacherOptions.value = await requestMagicApi({ url: 'baseData/user/list?type=1' });
+    classroomOptions.value = await requestMagicApi({ url: 'baseData/classroom/option' });
+  });
+
+  defineExpose({ validateStep, reloadStep });
+</script>
+
+<style lang="less" scoped>
+  .dsion-step2 {
+    margin: 16px 0;
+  }
+</style>

+ 1 - 1
src/views/educational/division/index.vue

@@ -46,7 +46,7 @@
   import { Steps } from 'ant-design-vue';
   import { reactive, onMounted, ref } from 'vue';
   import DsionStep1 from './components/DsionStep1.vue';
-  import DsionStep2 from './components/DsionStep2.vue';
+  import DsionStep2 from './components/DsionStep2_1.vue';
   import DsionStep3 from './components/DsionStep3.vue';
   import DsionStep4 from './components/DsionStep4.vue';
   import DsionStep5 from './components/DsionStep5.vue';