adjust.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <BasicModal
  3. @ok="handleSubmit"
  4. :destroyOnClose="true"
  5. :maskClosable="false"
  6. v-bind="$attrs"
  7. @register="registerModal"
  8. :title="getTitle"
  9. :width="1002"
  10. >
  11. <BasicForm @register="registerForm">
  12. <template #studentIds>
  13. <div class="flex" style="flex-wrap: wrap">
  14. <div v-for="(item, index) in modelRef" :key="index">
  15. <div style="margin: 4px" v-if="index < 6"> {{ item.name }}</div>
  16. </div>
  17. <div style="margin: 4px" v-if="modelRef.length > 6"> ... 等{{ modelRef.length }}个 </div>
  18. </div>
  19. </template>
  20. </BasicForm>
  21. </BasicModal>
  22. </template>
  23. <script setup lang="ts">
  24. import { ref, computed, unref } from 'vue';
  25. import { useMessage } from '/@/hooks/web/useMessage';
  26. import { BasicModal, useModalInner } from '/@/components/Modal';
  27. import { BasicForm, useForm } from '/@/components/Form/index';
  28. import { form4Schema } from '../data.config';
  29. import {
  30. getBandingTaskClassList,
  31. postBandingTaskClassChangeClass,
  32. } from '/@/services/apis/BandingTaskClassController';
  33. const isUpdate = ref(true);
  34. const modelRef = ref<Recordable[]>([]);
  35. const emit = defineEmits(['success', 'register']);
  36. const { createMessage } = useMessage();
  37. const [registerForm, { validate, resetFields, updateSchema }] = useForm({
  38. labelWidth: 100,
  39. schemas: form4Schema,
  40. showActionButtonGroup: false,
  41. });
  42. const [registerModal, { closeModal, setModalProps }] = useModalInner(async (data) => {
  43. resetFields();
  44. setModalProps({ confirmLoading: false });
  45. isUpdate.value = !!data?.isUpdate;
  46. modelRef.value = [...data.baseData];
  47. const taskClassList = await getBandingTaskClassList({
  48. bandingTaskId: data.bandingTaskId,
  49. });
  50. const classList = taskClassList.map((item) => {
  51. return {
  52. label: item.name,
  53. value: item.id,
  54. };
  55. });
  56. updateSchema([
  57. {
  58. field: 'bandingTaskClassId',
  59. componentProps: {
  60. options: classList,
  61. },
  62. },
  63. ]);
  64. });
  65. const getTitle = computed(() => (!unref(isUpdate) ? '调整班级' : '调整班级'));
  66. const handleSubmit = async () => {
  67. try {
  68. const values = await validate();
  69. setModalProps({ confirmLoading: true });
  70. const newStudentIds: string[] = [];
  71. modelRef.value.forEach((item) => {
  72. newStudentIds.push(item.id);
  73. });
  74. const postParams = {
  75. newStudentIds: newStudentIds,
  76. };
  77. Object.assign(postParams, values);
  78. await postBandingTaskClassChangeClass(postParams as API.ChangeClassDto);
  79. createMessage.success('操作成功');
  80. closeModal();
  81. emit('success');
  82. } finally {
  83. setModalProps({ confirmLoading: false });
  84. }
  85. };
  86. </script>
  87. <style scoped lang="less"></style>