updateSubject.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. subjectId: null,
  32. id: null
  33. });
  34. const getConfigSubject = async () => {
  35. try {
  36. const { data } = await getConfiguredSubjects({
  37. currentGradeNum: createClassForm.currentGradeNum,
  38. currentClass: createClassForm.currentClass
  39. });
  40. const temp = data || [];
  41. subjectList.value = temp.map((item: any) => {
  42. return {
  43. label: item.name,
  44. value: item.id
  45. };
  46. });
  47. } catch {
  48. //
  49. }
  50. };
  51. onMounted(async () => {
  52. // 获取教材分类列表
  53. // await catchStore.getSubjects();
  54. // subjectList.value = [
  55. // { id: null, name: '选择声部' },
  56. // ...catchStore.getSubjectList
  57. // ];
  58. createClassForm.currentGradeNum = props.activeRow.currentGradeNum;
  59. createClassForm.currentClass = props.activeRow.currentClass;
  60. createClassForm.subjectId = props.activeRow.subjectId;
  61. createClassForm.id = props.activeRow.id;
  62. getConfigSubject();
  63. });
  64. const submitForms = () => {
  65. foemsRef.value.validate(async (error: any) => {
  66. if (error) {
  67. return;
  68. }
  69. data.uploading = true;
  70. try {
  71. await resetClass({ ...createClassForm });
  72. message.success('修改成功');
  73. emit('close');
  74. emit('confirm', {
  75. lastUseCoursewareId: props.activeRow.lessonCoursewareId,
  76. unit: props.activeRow.lessonCoursewareKnowledgeDetailId,
  77. subjectId: createClassForm.subjectId,
  78. name: props.activeRow.name, // 班级名称
  79. classGroupId: props.activeRow.id // 班级编号
  80. });
  81. emit('getList');
  82. } catch (e) {
  83. console.log(e);
  84. }
  85. data.uploading = false;
  86. });
  87. };
  88. return () => (
  89. <div class={[styles.addClass]}>
  90. <NForm label-placement="left" model={createClassForm} ref={foemsRef}>
  91. <NFormItem
  92. path="subjectId"
  93. rule={[
  94. {
  95. required: true,
  96. message: '请选择声部'
  97. }
  98. ]}>
  99. <CSelect
  100. {...({
  101. style: { width: '400px' },
  102. options: subjectList.value,
  103. placeholder: '选择声部',
  104. clearable: true
  105. } as any)}
  106. v-model:value={createClassForm.subjectId}></CSelect>
  107. </NFormItem>
  108. </NForm>
  109. <NSpace class={styles.btnGroup} justify="center">
  110. <NButton round onClick={() => emit('close')}>
  111. 取消
  112. </NButton>
  113. <NButton
  114. round
  115. loading={data.uploading}
  116. onClick={() => submitForms()}
  117. type="primary">
  118. 确定
  119. </NButton>
  120. </NSpace>
  121. </div>
  122. );
  123. }
  124. });