You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

226 lines
7.8 KiB

2 years ago
  1. <template>
  2. <v-card outlined class="rounded-xl px-3">
  3. <v-card-title> {{ $t("Categories") }} </v-card-title>
  4. <v-card-subtitle class="mt-0">
  5. <v-card outlined class="d-flex flex-row justify-space-between align-center px-3" style="border-radius: 12px"
  6. height="36" width="100%" :ripple="false" @click="dialog = true">
  7. <div style="color: #9c9c9c">{{ $t(searchBarTitle) }}</div>
  8. <v-img height="25" max-width="25" contain :src="require('~/assets/svg/search.svg')"></v-img>
  9. </v-card>
  10. </v-card-subtitle>
  11. <v-card-text class="ml-n4 mt-n3">
  12. <v-list>
  13. <v-list-group :value="categoryExpend[i]" v-for="(category, i) in categories.slice(0, 8)" :key="'category-' + i"
  14. :ref="'category-' + i" no-action class="my-n3">
  15. <template v-slot:activator>
  16. <v-list-item-title>{{ category.category }}</v-list-item-title>
  17. </template>
  18. <template v-slot:prependIcon>
  19. <v-checkbox dense hide-details v-model="categoryChecked" :value="category.id" @click.stop="
  20. () => {
  21. clickCategory(category.id);
  22. }
  23. "></v-checkbox>
  24. </template>
  25. <v-list-item v-for="(subcategory, j) in category.subcategories" :key="'category-' + i + 'subcategory-' + j">
  26. <v-list-item-icon>
  27. <v-checkbox dense hide-details v-model="subcategoryChecked" :value="subcategory.id" @click.stop="">
  28. </v-checkbox>
  29. </v-list-item-icon>
  30. <v-list-item-title v-text="subcategory.subcategory"></v-list-item-title>
  31. </v-list-item>
  32. </v-list-group>
  33. </v-list>
  34. </v-card-text>
  35. <v-card-text>
  36. <v-btn outlined class="rounded-xl remove-upper tw-border-primary-2 tw-text-primary-1 mt-n10"
  37. style="padding: 10px auto" width="100%" @click="dialog = true">
  38. {{ $t("See more") }}
  39. </v-btn>
  40. </v-card-text>
  41. <v-dialog @click:outside="text = ''" v-model="dialog" width="644" height="618" class="rounded-xl">
  42. <v-card class="rounded-xl pa-4" width="100%" height="100%">
  43. <v-card-title>
  44. <v-row no-gutters class="d-flex justify-space-between">
  45. <div class="ml-n3">{{ $t("Select Exhibition Categories") }}</div>
  46. <v-img :src="require('~/assets/svg/X.svg')" max-width="24" max-height="24" contain @click="dialog = false">
  47. </v-img>
  48. </v-row>
  49. </v-card-title>
  50. <v-card-subtitle class="mt-5">
  51. <v-text-field outlined dense v-model="text" class="rounded-xl" :label="$t('Find Exhibition categories ...')">
  52. <template v-slot:append>
  53. <v-img height="25" width="25" class="mt-n1" contain :src="require('~/assets/svg/search.svg')"></v-img>
  54. </template>
  55. </v-text-field>
  56. </v-card-subtitle>
  57. <v-card-text>
  58. <v-expansion-panels v-model="categoryDialogExpend" :key="updateExpand" class="elevation-0" flat multiple>
  59. <template v-for="(category, i) in categories">
  60. <v-expansion-panel :key="'category-' + i"
  61. v-if="categoryChild[i] > 0 || text === ''" flat class="mt-0">
  62. <v-expansion-panel-header class="py-0">
  63. <div class="checkbox-wrap d-flex align-center">
  64. <v-checkbox class="mt-0 pt-0" dense hide-details v-model="categoryChecked" :value="category.id"
  65. @click.stop="
  66. () => {
  67. clickCategory(category.id);
  68. }
  69. "></v-checkbox>
  70. </div>
  71. <span class="ms-5">{{ category.category }}</span>
  72. </v-expansion-panel-header>
  73. <v-expansion-panel-content class="pb-0">
  74. <template>
  75. <v-spacer :key="'category-' + i + 'subcategory-' + j"
  76. class="d-flex align-center panel-content-wrap" v-if="
  77. subcategory.subcategory
  78. .toLowerCase()
  79. .includes(text.toLowerCase()) || text == ''
  80. ">
  81. <div class="checkbox-wrap ms-9 me-5">
  82. <v-checkbox dense hide-details class="mt-0 pt-0" v-model="subcategoryChecked"
  83. :value="subcategory.id" @click.stop=""></v-checkbox>
  84. </div>
  85. <div class="mt-1">
  86. {{ subcategory.subcategory }}
  87. </div>
  88. </v-spacer>
  89. </template>
  90. </v-expansion-panel-content>
  91. </v-expansion-panel>
  92. </template>
  93. </v-expansion-panels>
  94. </v-card-text>
  95. </v-card>
  96. </v-dialog>
  97. </v-card>
  98. </template>
  99. <script>
  100. export default {
  101. props: ["categories", "searchBarWidth", "searchBarTitle"],
  102. data() {
  103. return {
  104. categoryExpend: Array(100).fill(false),
  105. categoryDialogExpend: [],
  106. categoryChecked: [],
  107. subcategoryChecked: [],
  108. category2subcategory: {},
  109. categoryChild: [],
  110. dialog: false,
  111. updateExpand: false,
  112. text: "",
  113. };
  114. },
  115. created() {
  116. for (let i = 0; i < this.categories.length; i++) {
  117. this.category2subcategory[this.categories[i].id] = [];
  118. if (this.categories[i].subcategories != null) {
  119. this.categoryChild[i] = this.categories[i].subcategories.length;
  120. for (let j = 0; j < this.categories[i].subcategories.length; j++) {
  121. this.category2subcategory[this.categories[i].id].push(
  122. this.categories[i].subcategories[j].id
  123. );
  124. }
  125. }
  126. }
  127. },
  128. watch: {
  129. categoryChecked() {
  130. this.$emit("selectCategory", this.categoryChecked);
  131. },
  132. subcategoryChecked() {
  133. this.$emit("selectSubcategory", this.subcategoryChecked);
  134. },
  135. text() {
  136. this.categoryDialogExpend = [];
  137. let findCount = 0;
  138. for (let i = 0; i < this.$props.categories.length; i++) {
  139. let num = 0;
  140. for (
  141. let j = 0;
  142. j < this.$props.categories[i].subcategories.length;
  143. j++
  144. ) {
  145. if (
  146. this.$props.categories[i].subcategories[j].subcategory
  147. .toLowerCase()
  148. .includes(this.text.toLowerCase()) &&
  149. this.text !== ""
  150. ) {
  151. num++;
  152. }
  153. }
  154. this.categoryChild[i] = num;
  155. if (this.categoryChild[i] > 0) {
  156. findCount++;
  157. }
  158. }
  159. this.updateExpand = !this.updateExpand;
  160. this.categoryDialogExpend = [...Array(findCount).keys()];
  161. this.$forceUpdate();
  162. },
  163. },
  164. methods: {
  165. clickCategory(clickCategoryId) {
  166. if (this.categoryChecked.includes(clickCategoryId)) {
  167. // add
  168. let subCategoryList = this.category2subcategory[clickCategoryId];
  169. for (let i = 0; i < subCategoryList.length; i++) {
  170. let subCategoryId = subCategoryList[i];
  171. if (!this.subcategoryChecked.includes(subCategoryId))
  172. this.subcategoryChecked.push(subCategoryId);
  173. }
  174. } else {
  175. // delete
  176. let subCategoryList = this.category2subcategory[clickCategoryId];
  177. for (let i = 0; i < subCategoryList.length; i++) {
  178. let subCategoryId = subCategoryList[i];
  179. let idx = this.subcategoryChecked.indexOf(subCategoryId);
  180. if (idx > -1) this.subcategoryChecked.splice(idx, 1);
  181. }
  182. }
  183. },
  184. },
  185. };
  186. </script>
  187. <style scoped lang="scss">
  188. :deep() {
  189. .v-text-field__details {
  190. display: none !important;
  191. }
  192. .v-input__append-inner {
  193. margin-top: 12px !important;
  194. }
  195. .v-input--selection-controls__input {
  196. i {
  197. color: #f5cda8 !important;
  198. }
  199. }
  200. .v-label {
  201. color: #232323 !important;
  202. margin-left: 20px;
  203. }
  204. }
  205. .checkbox-wrap {
  206. max-width: 18px;
  207. height: 18px;
  208. }
  209. .panel-content-wrap {
  210. height: 40px;
  211. }
  212. .v-expansion-panel--active>.v-expansion-panel-header {
  213. min-height: 40px;
  214. }
  215. </style>