123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <template>
- <BasicModal
- @ok="handleSubmit"
- :destroyOnClose="true"
- :maskClosable="false"
- v-bind="$attrs"
- @register="registerModal"
- :title="getTitle"
- :width="1002"
- >
- <BasicForm @register="registerForm">
- <template #studentIds>
- <div class="flex" style="flex-wrap: wrap">
- <div v-for="(item, index) in modelRef" :key="index">
- <div style="margin: 4px" v-if="index < 6"> {{ item.name }}</div>
- </div>
- <div style="margin: 4px" v-if="modelRef.length > 6"> ... 等{{ modelRef.length }}个 </div>
- </div>
- </template>
- </BasicForm>
- </BasicModal>
- </template>
- <script setup lang="ts">
- import { ref, computed, unref } from 'vue';
- import { useMessage } from '/@/hooks/web/useMessage';
- import { BasicModal, useModalInner } from '/@/components/Modal';
- import { BasicForm, useForm } from '/@/components/Form/index';
- import { form4Schema } from '../data.config';
- import {
- getBandingTaskClassList,
- postBandingTaskClassChangeClass,
- } from '/@/services/apis/BandingTaskClassController';
- const isUpdate = ref(true);
- const modelRef = ref<Recordable[]>([]);
- const emit = defineEmits(['success', 'register']);
- const { createMessage } = useMessage();
- const [registerForm, { validate, resetFields, updateSchema }] = useForm({
- labelWidth: 100,
- schemas: form4Schema,
- showActionButtonGroup: false,
- });
- const [registerModal, { closeModal, setModalProps }] = useModalInner(async (data) => {
- resetFields();
- setModalProps({ confirmLoading: false });
- isUpdate.value = !!data?.isUpdate;
- modelRef.value = [...data.baseData];
- const taskClassList = await getBandingTaskClassList({
- bandingTaskId: data.bandingTaskId,
- });
- const classList = taskClassList.map((item) => {
- return {
- label: item.name,
- value: item.id,
- };
- });
- updateSchema([
- {
- field: 'bandingTaskClassId',
- componentProps: {
- options: classList,
- },
- },
- ]);
- });
- const getTitle = computed(() => (!unref(isUpdate) ? '调整班级' : '调整班级'));
- const handleSubmit = async () => {
- try {
- const values = await validate();
- setModalProps({ confirmLoading: true });
- const newStudentIds: string[] = [];
- modelRef.value.forEach((item) => {
- newStudentIds.push(item.id);
- });
- const postParams = {
- newStudentIds: newStudentIds,
- };
- Object.assign(postParams, values);
- await postBandingTaskClassChangeClass(postParams as API.ChangeClassDto);
- createMessage.success('操作成功');
- closeModal();
- emit('success');
- } finally {
- setModalProps({ confirmLoading: false });
- }
- };
- </script>
- <style scoped lang="less"></style>
|