KindCategory.vue 5.1 KB

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