KindCategory.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <div class="kind-category" @mouseleave="hideChildrenLayout()">
  3. <ul class="kind-main list-unstyled">
  4. <li v-for="kind in kindsToShow" class="kind-main-item" :class="{active: kind.id==activeKindId}"
  5. @mouseenter="showChildrenLayout(kind)">
  6. <nuxt-link :to="`/product/kind/${kind.id}`">
  7. <span>{{ kind.nameCn }}</span>
  8. <i class="iconfont icon-arrow-right icon-sm pull-right"></i>
  9. </nuxt-link>
  10. </li>
  11. <li class="kind-main-item item-more">
  12. <nuxt-link to="/product/kind">
  13. <span>查看更多器件分类</span>
  14. </nuxt-link>
  15. </li>
  16. </ul>
  17. <!-- 子类目 -->
  18. <transition name="fade" mode="out-in">
  19. <div v-if="activeKindId" class="kind-children">
  20. <div v-for="(kind, index) in kindsToShow" :key="index"
  21. v-if="kind.id==activeKindId" class="kind-children-layout">
  22. <empty-box v-if="!kind.fetching && kind.children && !kind.children.length"></empty-box>
  23. <loading-box v-else-if="kind.fetching" color="rgba(80, 120, 203, 0.9)"></loading-box>
  24. <div class="kind-children-item-wrap" v-else>
  25. <dl class="kind-children-item dl-horizontal" v-for="c in kind.children">
  26. <dt>
  27. <nuxt-link :to="`/product/kind/${c.id}`">
  28. <span>{{ c.nameCn }}</span><i class="pull-right iconfont icon-arrow-right icon-sm"></i>
  29. </nuxt-link>
  30. </dt>
  31. <dd>
  32. <ul class="list-unstyled list-inline">
  33. <li v-for="h in c.children">
  34. <nuxt-link :to="`/product/kind/${h.id}`">
  35. <span>{{ h.nameCn }}</span>
  36. </nuxt-link>
  37. </li>
  38. </ul>
  39. </dd>
  40. </dl>
  41. </div>
  42. </div>
  43. </div>
  44. </transition>
  45. </div>
  46. </template>
  47. <script>
  48. export default {
  49. name: 'kind-category',
  50. data () {
  51. return {
  52. activeKindId: 0
  53. }
  54. },
  55. methods: {
  56. showChildrenLayout (kind) {
  57. if (!kind.leaf) {
  58. this.activeKindId = kind.id
  59. if (!kind.children) {
  60. this.$emit('loadchild', kind.id)
  61. }
  62. }
  63. },
  64. hideChildrenLayout () {
  65. this.activeKindId = null
  66. }
  67. },
  68. computed: {
  69. kinds () {
  70. return this.$store.state.product.kind.kinds
  71. },
  72. kindsToShow () {
  73. // 只显示前13个根类目
  74. return this.kinds.data.slice(0, 13)
  75. }
  76. }
  77. }
  78. </script>
  79. <style lang="scss" scoped>
  80. @import '~assets/scss/variables';
  81. .kind-category {
  82. position: absolute;
  83. width: 200px;
  84. height: 477px;
  85. .kind-main {
  86. margin: 0;
  87. padding: 0;
  88. z-index: 10;
  89. .kind-main-item {
  90. height: 34.1px;
  91. line-height: 34.1px;
  92. padding: 0 20px;
  93. background: rgba(80, 120, 203, 0.9);
  94. display: block;
  95. > a {
  96. color: #fff;
  97. > .iconfont {
  98. opacity: 0;
  99. }
  100. }
  101. &.item-more {
  102. background-color: #4c66bb;
  103. font-weight: bold;
  104. font-size: 12px;
  105. }
  106. &.active,&:hover {
  107. background-color: #a0b2eb;
  108. > a {
  109. font-weight: bold;
  110. > .iconfont {
  111. opacity: 1;
  112. }
  113. }
  114. }
  115. }
  116. }
  117. .kind-children {
  118. position: absolute;
  119. top: 0;
  120. left: 200px;
  121. z-index: 9;
  122. box-shadow: 1px 0 3px #666;
  123. .kind-children-layout {
  124. background-color: #fff;
  125. width: 990px;
  126. height: 477px;
  127. font-size: 12px;
  128. overflow-y: auto;
  129. .kind-children-item-wrap {
  130. height: 100%;
  131. width: 100%;
  132. .kind-children-item {
  133. margin-bottom: $md-pad;
  134. dt {
  135. span {
  136. width: 90%;
  137. display: inline-block;
  138. font-weight: bold;
  139. overflow: hidden;
  140. clear: left;
  141. text-align: right;
  142. text-overflow: ellipsis;
  143. white-space: nowrap;
  144. }
  145. }
  146. dd {
  147. ul {
  148. margin: 0;
  149. padding: 0;
  150. li {
  151. border-left: $border;
  152. margin-bottom: $pad;
  153. span {
  154. margin: 0 $sm-pad;
  155. }
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
  162. }
  163. }
  164. </style>