SelectGenreDialog.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <Dialog v-model="dialogVisible">
  3. <template #header>
  4. <div class="row items-center">
  5. <div style="font-size: 130%">
  6. Выбрать жанры
  7. </div>
  8. </div>
  9. </template>
  10. <div class="col column" style="height: 500px; min-width: 400px">
  11. <div class="row items-center top-panel bg-grey-3">
  12. <q-input ref="search" v-model="search" class="col" outlined dense bg-color="white" placeholder="Найти" clearable />
  13. </div>
  14. <div class="col fit tree">
  15. <div v-show="nodes.length" class="checkbox-tick-all">
  16. <q-checkbox v-model="tickAll" size="36px" label="Выбрать все" @update:model-value="makeTickAll" />
  17. </div>
  18. <q-tree
  19. v-model:ticked="ticked"
  20. v-model:expanded="expanded"
  21. class="q-my-xs"
  22. :nodes="nodes"
  23. node-key="key"
  24. tick-strategy="leaf"
  25. selected-color="black"
  26. :filter="search"
  27. no-nodes-label="Жанров нет"
  28. no-results-label="Ничего не найдено"
  29. >
  30. </q-tree>
  31. </div>
  32. </div>
  33. <template #footer>
  34. <q-btn class="q-px-md q-ml-sm" color="primary" dense no-caps @click="okClick">
  35. OK
  36. </q-btn>
  37. </template>
  38. </Dialog>
  39. </template>
  40. <script>
  41. //-----------------------------------------------------------------------------
  42. import vueComponent from '../../vueComponent.js';
  43. import Dialog from '../../share/Dialog.vue';
  44. const componentOptions = {
  45. components: {
  46. Dialog
  47. },
  48. watch: {
  49. modelValue(newValue) {
  50. this.dialogVisible = newValue;
  51. if (newValue)
  52. this.init();//no await
  53. },
  54. dialogVisible(newValue) {
  55. this.$emit('update:modelValue', newValue);
  56. },
  57. genre() {
  58. this.updateTicked();
  59. },
  60. ticked() {
  61. this.checkAllTicked();
  62. this.updateGenre();
  63. },
  64. }
  65. };
  66. class GenreSelectDialog {
  67. _options = componentOptions;
  68. _props = {
  69. modelValue: Boolean,
  70. genre: {type: String, value: ''},
  71. genreTree: Array,
  72. };
  73. dialogVisible = false;
  74. search = '';
  75. ticked = [];
  76. expanded = [];
  77. tickAll = false;
  78. allKeys = [];
  79. created() {
  80. }
  81. async init() {
  82. }
  83. get nodes() {
  84. const result = [];
  85. this.allKeys = [];
  86. for (const section of this.genreTree) {
  87. const rkey = `r-${section.name}`;
  88. const sec = {label: section.name, key: rkey, children: []};
  89. for (const g of section.value) {
  90. sec.children.push({label: g.name, key: g.value});
  91. this.allKeys.push(g.value);
  92. }
  93. result.push(sec);
  94. }
  95. return result;
  96. }
  97. makeTickAll() {
  98. if (this.tickAll) {
  99. const newTicked = [];
  100. for (const key of this.allKeys) {
  101. newTicked.push(key);
  102. }
  103. this.ticked = newTicked;
  104. } else {
  105. this.ticked = [];
  106. }
  107. }
  108. checkAllTicked() {
  109. const ticked = new Set(this.ticked);
  110. let newTickAll = !!(this.nodes.length);
  111. for (const key of this.allKeys) {
  112. if (!ticked.has(key)) {
  113. newTickAll = false;
  114. break;
  115. }
  116. }
  117. this.tickAll = newTickAll;
  118. }
  119. updateTicked() {
  120. this.ticked = this.genre.split(',').filter(s => s);
  121. }
  122. updateGenre() {
  123. this.$emit('update:genre', this.ticked.join(','));
  124. }
  125. okClick() {
  126. this.dialogVisible = false;
  127. }
  128. }
  129. export default vueComponent(GenreSelectDialog);
  130. //-----------------------------------------------------------------------------
  131. </script>
  132. <style scoped>
  133. .top-panel {
  134. height: 50px;
  135. border-bottom: 1px solid gray;
  136. padding: 0 10px 0 12px;
  137. }
  138. .tree {
  139. padding: 0px 10px 10px 10px;
  140. overflow: auto;
  141. }
  142. .checkbox-tick-all {
  143. border-bottom: 1px solid #bbbbbb;
  144. margin-bottom: 7px;
  145. padding: 5px 5px 2px 16px;
  146. }
  147. </style>