search-group-resources.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { defineComponent, onMounted, reactive } from 'vue';
  2. import styles from './index.module.less';
  3. import { NButton, NForm, NFormItem, NSpace } from 'naive-ui';
  4. import iconAdd from '../../images/icon-add.svg';
  5. import TheSearch from '/src/components/TheSearch';
  6. import { resourceTypeArray } from '/src/utils/searchArray';
  7. import { useCatchStore } from '/src/store/modules/catchData';
  8. export default defineComponent({
  9. name: 'search-group',
  10. emits: ['search', 'add'],
  11. setup(props, { emit }) {
  12. const catchStore = useCatchStore();
  13. const forms = reactive({
  14. type: 'MUSIC', //
  15. keyword: '',
  16. bookVersionId: null,
  17. subjectId: null
  18. });
  19. const onSearch = () => {
  20. emit('search', forms);
  21. };
  22. onMounted(async () => {
  23. // 获取教材分类列表
  24. await catchStore.getMusicSheetCategory();
  25. // 获取声部列表
  26. await catchStore.getSubjects();
  27. });
  28. return () => (
  29. <div class={styles.searchGroup}>
  30. <div class={styles.searchCatatory}>
  31. <NSpace size="small" class={styles.btnType}>
  32. {resourceTypeArray.map((item: any) => (
  33. <NButton
  34. type={forms.type === item.value ? 'primary' : 'default'}
  35. secondary={forms.type === item.value ? false : true}
  36. round
  37. size="small"
  38. focusable={false}
  39. onClick={() => {
  40. forms.type = item.value;
  41. onSearch();
  42. }}>
  43. {item.label}
  44. </NButton>
  45. ))}
  46. </NSpace>
  47. <NButton
  48. type="primary"
  49. class={styles.addTrain}
  50. focusable={false}
  51. strong
  52. onClick={() => emit('add')}>
  53. <img src={iconAdd} />
  54. 添加自定义教材
  55. </NButton>
  56. </div>
  57. <NForm labelAlign="left" labelPlacement="left">
  58. {forms.type === 'MUSIC' && (
  59. <NFormItem label="教材:">
  60. <NSpace class={styles.spaceSection}>
  61. {catchStore.getAllMusicCategories.map((music: any) => (
  62. <NButton
  63. secondary={forms.bookVersionId === music.id}
  64. quaternary={forms.bookVersionId !== music.id}
  65. strong
  66. focusable={false}
  67. type={
  68. forms.bookVersionId === music.id ? 'primary' : 'default'
  69. }
  70. onClick={() => {
  71. forms.bookVersionId = music.id;
  72. onSearch();
  73. }}>
  74. {music.name}
  75. </NButton>
  76. ))}
  77. </NSpace>
  78. </NFormItem>
  79. )}
  80. <NFormItem label="乐器:">
  81. <NSpace class={styles.spaceSection}>
  82. {catchStore.getSubjectAllList.map((subject: any) => (
  83. <NButton
  84. secondary={forms.subjectId === subject.id}
  85. quaternary={forms.subjectId !== subject.id}
  86. strong
  87. focusable={false}
  88. type={forms.subjectId === subject.id ? 'primary' : 'default'}
  89. onClick={() => {
  90. forms.subjectId = subject.id;
  91. onSearch();
  92. }}>
  93. {subject.name}
  94. </NButton>
  95. ))}
  96. </NSpace>
  97. </NFormItem>
  98. <TheSearch
  99. class={styles.inputSearch}
  100. round
  101. onSearch={(val: string) => {
  102. forms.keyword = val;
  103. onSearch();
  104. }}
  105. />
  106. </NForm>
  107. </div>
  108. );
  109. }
  110. });