CategoryNav.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template lang="pug">
  2. .category-nav.container.is-content
  3. .columns
  4. .column.label 解决方案
  5. .column.tags
  6. a.tag(
  7. v-for="item in fullyClasses"
  8. :class="topCatId === item.id ? ['is-primary', 'is-light'] : []"
  9. :href="item.id !== '_' ? `/c/${item.id}` : '#'"
  10. @click.stop.prevent="changeClass(item)"
  11. ) {{item.name}}
  12. .subnav(changeCategory
  13. v-for="item in fullyClasses"
  14. v-if="item.categories && item.categories.length"
  15. v-show="topCatId === item.id"
  16. )
  17. a.tag.is-sub(
  18. v-for="cat in item.categories"
  19. :class="catId === cat.cat_id ? ['is-primary', 'is-light'] : []"
  20. :href="cat.cat_id !== '_' ? `/c/${cat.cat_id}` : '#'"
  21. @click.stop.prevent="changeCategory(item, cat)"
  22. ) {{cat.alias || cat.name}}
  23. .columns
  24. .column.label 服务方式
  25. .column.tags
  26. #st-mark
  27. .tag(
  28. v-for="item in fullyServiceTypes"
  29. :class="serviceType === item.hash_id ? ['is-primary', 'is-light'] : []"
  30. @click="changeServiceType(item)"
  31. ) {{item.alias || item.name}}
  32. </template>
  33. <script lang="ts">
  34. import Vue from 'vue'
  35. export default Vue.extend({
  36. name: 'CategoryNav',
  37. props: {
  38. classes: {
  39. type: Array,
  40. default: () => [] as any[]
  41. },
  42. serviceTypes: {
  43. type: Array,
  44. default: () => [] as any[]
  45. },
  46. topCatId: {
  47. type: String,
  48. default: '_'
  49. },
  50. catId: {
  51. type: String,
  52. default: '_'
  53. },
  54. serviceType: {
  55. type: String,
  56. default: '_'
  57. }
  58. },
  59. data() {
  60. return {
  61. }
  62. },
  63. computed: {
  64. fullyClasses(): any[] {
  65. return [{
  66. id: '_',
  67. name: '全部'
  68. },
  69. ...this.classes.map((row) => {
  70. const { hash_id, name, categories } = row
  71. const categoriesCopy = categories && categories.length ? [...categories] : []
  72. if (categoriesCopy.length) {
  73. categoriesCopy.unshift({
  74. cat_id: '_',
  75. name: '全部'
  76. })
  77. }
  78. return {
  79. id: hash_id,
  80. name,
  81. categories: categoriesCopy
  82. }
  83. })]
  84. },
  85. fullyServiceTypes(): any[] {
  86. return [{
  87. hash_id: '_',
  88. name: '全部'
  89. },
  90. ...this.serviceTypes
  91. ]
  92. }
  93. },
  94. methods: {
  95. changeClass(item) {
  96. this.$emit('update:topCatId', item.id)
  97. this.$emit('update:catId', '_')
  98. },
  99. changeCategory(topCat, cat) {
  100. this.$emit('update:topCatId', topCat.id)
  101. this.$emit('update:catId', cat.cat_id)
  102. },
  103. changeServiceType(item) {
  104. this.$emit('update:serviceType', item.hash_id)
  105. }
  106. }
  107. })
  108. </script>
  109. <style lang="scss">
  110. .kaifain-view .category-nav {
  111. padding: 2rem 0;
  112. .column {
  113. &.label {
  114. font-size: 0.8125rem;
  115. font-weight: 500;
  116. flex: none;
  117. margin: 4px 0 0;
  118. user-select: none;
  119. }
  120. }
  121. .tags {
  122. &:last-child {
  123. margin-bottom: -1rem;
  124. }
  125. > .tag {
  126. margin-right: 0.75rem;
  127. }
  128. }
  129. .tag {
  130. font-size: 0.782rem;
  131. min-width: 64px;
  132. text-decoration: none !important;
  133. cursor: pointer;
  134. user-select: none;
  135. &:not(.is-primary):hover {
  136. background: #efeff0;
  137. }
  138. &.is-sub {
  139. background: #f9f9fa;
  140. }
  141. }
  142. .subnav {
  143. background: #f9f9fa;
  144. border-radius: 8px;
  145. padding: 0.5rem 0.75rem 1px;
  146. margin: 0.125rem 0 0.5rem;
  147. }
  148. }
  149. .kaifain-view {
  150. @media screen and (max-width: 767px) {
  151. .category-nav {
  152. padding: 0.75rem 0 1.5rem;
  153. .column.label {
  154. padding: 0.25rem 0.75rem 0.125rem;
  155. }
  156. }
  157. }
  158. }
  159. </style>