KindCategory.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. // kinds: {}
  54. }
  55. },
  56. methods: {
  57. showChildrenLayout (kind) {
  58. if (!kind.leaf) {
  59. this.activeKindId = kind.id
  60. if (!kind.children) {
  61. this.$emit('loadchild', kind.id)
  62. }
  63. }
  64. },
  65. hideChildrenLayout () {
  66. this.activeKindId = null
  67. }
  68. },
  69. // mounted () {
  70. // this.$http.get(`/api/product/kind/0/children_all`)
  71. // .then(response => {
  72. // this.kinds = response
  73. // })
  74. // },
  75. computed: {
  76. kinds () {
  77. return this.$store.state.product.kind.kinds
  78. },
  79. kindsToShow () {
  80. // 只显示前13个根类目
  81. if (this.kinds.data) {
  82. return this.kinds.data.slice(0, 13)
  83. }
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. @import '~assets/scss/variables';
  90. .kind-children .kind-children-layout{
  91. padding: 15px 0 0 0;
  92. }
  93. .kind-category {
  94. position: absolute;
  95. width: 200px;
  96. height: 477px;
  97. .kind-main {
  98. margin: 0;
  99. padding: 0;
  100. z-index: 10;
  101. .kind-main-item {
  102. height: 34.1px;
  103. line-height: 34.1px;
  104. padding: 0 10px 0 20px;
  105. background: rgba(80, 120, 203, 0.9);
  106. display: block;
  107. > a {
  108. color: #fff;
  109. > .iconfont {
  110. opacity: 0;
  111. }
  112. }
  113. &.item-more {
  114. background-color: #4c66bb;
  115. font-weight: bold;
  116. font-size: 12px;
  117. }
  118. &.active,&:hover {
  119. background-color: #a0b2eb;
  120. > a {
  121. font-weight: bold;
  122. > .iconfont {
  123. opacity: 1;
  124. }
  125. }
  126. }
  127. }
  128. }
  129. .kind-children {
  130. position: absolute;
  131. top: 0;
  132. left: 200px;
  133. z-index: 9;
  134. box-shadow: 1px 0 3px #666;
  135. .kind-children-layout {
  136. background-color: #fff;
  137. width: 990px;
  138. height: 477px;
  139. font-size: 12px;
  140. overflow-y: auto;
  141. a {
  142. color: #000;
  143. }
  144. a:hover {
  145. color: #ff0006;
  146. }
  147. .kind-children-item-wrap {
  148. height: 100%;
  149. width: 100%;
  150. .kind-children-item {
  151. margin-bottom: $md-pad;
  152. dt {
  153. span {
  154. width: 90%;
  155. display: inline-block;
  156. font-weight: bold;
  157. overflow: hidden;
  158. clear: left;
  159. text-align: right;
  160. text-overflow: ellipsis;
  161. white-space: nowrap;
  162. }
  163. i{
  164. font-size: 12px;
  165. }
  166. }
  167. dd {
  168. ul {
  169. margin: 0;
  170. padding: 0;
  171. li {
  172. border-left: $border;
  173. margin-bottom: $pad;
  174. span {
  175. margin: 0 $sm-pad;
  176. }
  177. }
  178. }
  179. }
  180. }
  181. }
  182. }
  183. }
  184. }
  185. </style>