search-group-resources.tsx 3.5 KB

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