index.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { defineComponent, onMounted, ref } from 'vue';
  2. import styles from './index.module.less';
  3. import { NButton, NSpace, useMessage } from 'naive-ui';
  4. import { useCatchStore } from '/src/store/modules/catchData';
  5. import iconSelect from '../../images/icon-select.png';
  6. import { usePrepareStore } from '/src/store/modules/prepareLessons';
  7. export default defineComponent({
  8. name: 'subject-sync',
  9. props: {
  10. subjectId: {
  11. type: [String, Number],
  12. default: ''
  13. }
  14. },
  15. emits: ['close', 'confirm'],
  16. setup(props, { emit }) {
  17. const catchStore = useCatchStore();
  18. const prepareStore = usePrepareStore();
  19. const message = useMessage();
  20. const selectSubjectIds = ref([] as any);
  21. const subjectList = ref([] as any);
  22. const onSubmit = () => {
  23. if (selectSubjectIds.value.length <= 0) {
  24. message.error('至少选择一个声部进行同步');
  25. return;
  26. }
  27. emit('confirm', selectSubjectIds.value);
  28. };
  29. onMounted(async () => {
  30. // 获取教材分类列表
  31. await catchStore.getSubjects();
  32. const baseAllSubjectList = catchStore.getSubjectList;
  33. const teachingSubjectList = prepareStore.getSubjectList; // 教材自带声部;
  34. const tempSubjectList: any = [];
  35. baseAllSubjectList.forEach((subject: any) => {
  36. const index = teachingSubjectList.findIndex(
  37. (t: any) => t.id == subject.id
  38. );
  39. if (index != -1) {
  40. tempSubjectList.push(subject);
  41. }
  42. });
  43. subjectList.value = tempSubjectList;
  44. if (props.subjectId) {
  45. selectSubjectIds.value = [Number(props.subjectId)];
  46. }
  47. });
  48. return () => (
  49. <div class={styles.subjectSync}>
  50. <div class={styles.tips}>
  51. 请选择当前课件可使用的乐器
  52. <span>(勾选后则对应乐器下的课件内容将被当前课件内容全部替换)</span>
  53. </div>
  54. <div class={styles.subjectList}>
  55. {subjectList.value.map((subject: any) => (
  56. <div
  57. class={[
  58. styles.subjectItem,
  59. selectSubjectIds.value.includes(subject.id)
  60. ? styles.subjectSelect
  61. : ''
  62. ]}
  63. onClick={() => {
  64. if (selectSubjectIds.value.includes(subject.id)) {
  65. const index = selectSubjectIds.value.indexOf(subject.id);
  66. selectSubjectIds.value.splice(index, 1);
  67. } else {
  68. selectSubjectIds.value.push(subject.id);
  69. }
  70. }}>
  71. <div class={styles.imgSection}>
  72. <img src={subject.img} />
  73. {selectSubjectIds.value.includes(subject.id) && (
  74. <img src={iconSelect} class={styles.iconSelect} />
  75. )}
  76. </div>
  77. <p class={styles.subjectName}>{subject.name}</p>
  78. </div>
  79. ))}
  80. </div>
  81. <NSpace class={styles.btnGroupModal} justify="center">
  82. <NButton round onClick={() => emit('close')}>
  83. 取消
  84. </NButton>
  85. <NButton round type="primary" onClick={onSubmit}>
  86. 确定
  87. </NButton>
  88. </NSpace>
  89. </div>
  90. );
  91. }
  92. });