KindCategory.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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" @mouseenter="hideChildrenLayout()">
  12. <nuxt-link to="/product/kind/home">
  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-children .kind-children-layout{
  82. padding: 15px 0 0 0;
  83. }
  84. .kind-category {
  85. position: absolute;
  86. width: 200px;
  87. height: 477px;
  88. .kind-main {
  89. margin: 0;
  90. padding: 0;
  91. z-index: 10;
  92. .kind-main-item {
  93. height: 34.1px;
  94. line-height: 34.1px;
  95. padding: 0 10px 0 20px;
  96. background: rgba(80, 120, 203, 0.9);
  97. display: block;
  98. > a {
  99. color: #fff;
  100. > .iconfont {
  101. opacity: 0;
  102. }
  103. }
  104. &.item-more {
  105. background-color: #4c66bb;
  106. font-weight: bold;
  107. font-size: 12px;
  108. }
  109. &.active,&:hover {
  110. background-color: #a0b2eb;
  111. > a {
  112. font-weight: bold;
  113. > .iconfont {
  114. opacity: 1;
  115. }
  116. }
  117. }
  118. }
  119. }
  120. .kind-children {
  121. position: absolute;
  122. top: 0;
  123. left: 200px;
  124. z-index: 9;
  125. box-shadow: 1px 0 3px #666;
  126. .kind-children-layout {
  127. background-color: #fff;
  128. width: 990px;
  129. height: 477px;
  130. font-size: 12px;
  131. overflow-y: auto;
  132. .kind-children-item-wrap {
  133. height: 100%;
  134. width: 100%;
  135. .kind-children-item {
  136. margin-bottom: $md-pad;
  137. dt {
  138. span {
  139. width: 90%;
  140. display: inline-block;
  141. font-weight: bold;
  142. overflow: hidden;
  143. clear: left;
  144. text-align: right;
  145. text-overflow: ellipsis;
  146. white-space: nowrap;
  147. }
  148. }
  149. dd {
  150. ul {
  151. margin: 0;
  152. padding: 0;
  153. li {
  154. border-left: $border;
  155. margin-bottom: $pad;
  156. span {
  157. margin: 0 $sm-pad;
  158. }
  159. }
  160. }
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. </style>