updateSubject.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { NButton, NSpace, useMessage, NForm, NFormItem } from 'naive-ui';
  2. import { defineComponent, onMounted, reactive, ref } from 'vue';
  3. import styles from '../index.module.less';
  4. import CSelect from '/src/components/CSelect';
  5. import { getConfiguredSubjects, resetClass } from '../api';
  6. import { useCatchStore } from '/src/store/modules/catchData';
  7. export default defineComponent({
  8. props: {
  9. activeRow: {
  10. type: Object,
  11. default: () => ({ id: '' })
  12. },
  13. subjectList: {
  14. type: Array,
  15. default: () => []
  16. }
  17. },
  18. name: 'resetStudent',
  19. emits: ['close', 'getList', 'confirm'],
  20. setup(props, { emit }) {
  21. const catchStore = useCatchStore();
  22. const data = reactive({
  23. uploading: false
  24. });
  25. const message = useMessage();
  26. const subjectList = ref([] as any);
  27. const foemsRef = ref();
  28. const createClassForm = reactive({
  29. currentGradeNum: null,
  30. currentClass: null,
  31. gradeYear: null,
  32. subjectId: null,
  33. id: null
  34. });
  35. const getConfigSubject = async () => {
  36. try {
  37. const { data } = await getConfiguredSubjects({
  38. gradeYear: createClassForm.gradeYear,
  39. currentGradeNum: createClassForm.currentGradeNum,
  40. currentClass: createClassForm.currentClass
  41. });
  42. const temp = data || [];
  43. subjectList.value = temp.map((item: any) => {
  44. return {
  45. label: item.name,
  46. value: item.id
  47. };
  48. });
  49. } catch {
  50. //
  51. }
  52. };
  53. onMounted(async () => {
  54. // 获取教材分类列表
  55. // await catchStore.getSubjects();
  56. // subjectList.value = [
  57. // { id: null, name: '选择声部' },
  58. // ...catchStore.getSubjectList
  59. console.log(props.activeRow, ' props.activeRow');
  60. // ];
  61. createClassForm.gradeYear = props.activeRow.gradeYear;
  62. createClassForm.currentGradeNum = props.activeRow.currentGradeNum;
  63. createClassForm.currentClass = props.activeRow.currentClass;
  64. createClassForm.subjectId = props.activeRow.subjectId;
  65. createClassForm.id = props.activeRow.id;
  66. getConfigSubject();
  67. });
  68. const submitForms = () => {
  69. foemsRef.value.validate(async (error: any) => {
  70. if (error) {
  71. return;
  72. }
  73. data.uploading = true;
  74. try {
  75. await resetClass({ ...createClassForm });
  76. message.success('修改成功');
  77. emit('close');
  78. emit('confirm', {
  79. lastUseCoursewareId: props.activeRow.lessonCoursewareId,
  80. unit: props.activeRow.lessonCoursewareKnowledgeDetailId,
  81. subjectId: createClassForm.subjectId,
  82. name: props.activeRow.name, // 班级名称
  83. classGroupId: props.activeRow.id // 班级编号
  84. });
  85. emit('getList');
  86. } catch (e) {
  87. console.log(e);
  88. }
  89. data.uploading = false;
  90. });
  91. };
  92. return () => (
  93. <div class={[styles.addClass]}>
  94. <NForm label-placement="left" model={createClassForm} ref={foemsRef}>
  95. <NFormItem
  96. path="subjectId"
  97. rule={[
  98. {
  99. required: true,
  100. message: '请选择声部'
  101. }
  102. ]}>
  103. <CSelect
  104. {...({
  105. style: { width: '400px' },
  106. options: subjectList.value,
  107. placeholder: '选择声部',
  108. clearable: true
  109. } as any)}
  110. v-model:value={createClassForm.subjectId}></CSelect>
  111. </NFormItem>
  112. </NForm>
  113. <NSpace class={styles.btnGroup} justify="center">
  114. <NButton round onClick={() => emit('close')}>
  115. 取消
  116. </NButton>
  117. <NButton
  118. round
  119. loading={data.uploading}
  120. onClick={() => submitForms()}
  121. type="primary">
  122. 确定
  123. </NButton>
  124. </NSpace>
  125. </div>
  126. );
  127. }
  128. });