KindCategory.vue 5.1 KB

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