category.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <div class="category">
  3. <div type="primary" class="title">
  4. <div class="flex lg">
  5. <i class="el-icon-s-fold"></i>
  6. <div class="m-l-8">人才图谱分类</div>
  7. </div>
  8. </div>
  9. <div class="category-con bg-white" v-show="category.length && showCate">
  10. <ul class="category-one">
  11. <li v-for="(item, index) in cateList" :key="index" :class="{ active: index === selectIndex }"
  12. @click="changeActive(index)">
  13. <div class="flex row-between">
  14. <span class="line-1">{{ item.title }}</span>
  15. <i v-if="item.children.length"
  16. :class="index === selectIndex ? 'el-icon-arrow-down' : 'el-icon-arrow-right'"></i>
  17. </div>
  18. <ul class="category-two" v-show="index === selectIndex">
  19. <li v-for="(itemTwo, indexTwo) in cateTwoList" :key="indexTwo"
  20. @click.stop="changeTwoActive(indexTwo)" :class="{ active: indexTwo === selectTowIndex }">
  21. <div class="flex row-center">
  22. <span class="line-1">{{ itemTwo.title }}</span>
  23. </div>
  24. </li>
  25. </ul>
  26. </li>
  27. <div class="category-float bg-white" v-show="showCateFloat && cateTwoList.length">
  28. <div class="float-con">
  29. <div class="m-t-16" v-for="(item, index) in cateTwoList" :key="index">
  30. <div class="category-two weight-500 m-b-15">
  31. <nuxt-link :to="`/category?id=${item.id}`">{{
  32. item.title
  33. }}</nuxt-link>
  34. </div>
  35. <div class="category-three flex flex-wrap">
  36. <div class="item" v-for="(titem, idx) in item.children" :key="idx">
  37. <nuxt-link :to="`/category?id=${titem.id}`" class="flex">
  38. <!-- <el-image-->
  39. <!-- style="width: 48px; height: 48px"-->
  40. <!-- :src="titem.image"-->
  41. <!-- fit="contain"-->
  42. <!-- ></el-image>-->
  43. <span class="m-l-8">{{
  44. titem.title
  45. }}</span>
  46. </nuxt-link>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </ul>
  53. </div>
  54. </div>
  55. </template>
  56. <script>
  57. import {
  58. mapState
  59. } from 'vuex'
  60. export default {
  61. data() {
  62. return {
  63. cateList: [],
  64. selectIndex: 0, //一级分类索引
  65. selectTowIndex: 0, //二级分类索引
  66. cateTwoList: [], //二级分类列表
  67. cateThreeList: [], //三级分类列表
  68. cateTwoId: 0,
  69. showCate: true,
  70. showCateFloat: false,
  71. //产业链配置
  72. currentTab: 0,
  73. }
  74. },
  75. created() {},
  76. mounted() {},
  77. updated() {},
  78. methods: {
  79. changeActive(index) {
  80. this.selectIndex = index
  81. this.selectTowIndex = 0 //二级分类索引重置0
  82. this.cateTwoList = this.cateList[this.selectIndex].children
  83. this.cateThreeSet()
  84. },
  85. changeTwoActive(index) {
  86. this.selectTowIndex = index
  87. this.cateThreeSet()
  88. console.log(this.selectTowIndex)
  89. this.$forceUpdate()
  90. },
  91. //产业链
  92. cateThreeSet() {
  93. this.cateTwoId = this.cateTwoList[this.selectTowIndex].id
  94. let children = this.cateTwoList[this.selectTowIndex].children.slice()
  95. if (children[0].title != '全部') {
  96. children.unshift({
  97. type: 1,
  98. pid: this.cateTwoId,
  99. title: '全部'
  100. })
  101. }
  102. this.currentTab = 0;
  103. this.cateThreeList = children.filter((item, index) => item.type == 1)
  104. if (this.cateThreeList.length > 0) {
  105. this.$emit('chain', this.cateThreeList)
  106. } else {
  107. // this.cateTwoId = 0;
  108. }
  109. },
  110. },
  111. watch: {
  112. $route: {
  113. immediate: true,
  114. handler: function(val) {
  115. this.showCate = val.path == '/' ? true : false
  116. },
  117. },
  118. category: {
  119. handler: function(val) {
  120. this.cateList = val.slice()
  121. if (this.cateList.length > 0) {
  122. this.cateTwoList = this.cateList[this.selectIndex].children
  123. this.cateThreeSet()
  124. }
  125. },
  126. immediate: true,
  127. deep: false,
  128. }
  129. },
  130. computed: {
  131. ...mapState(['category']),
  132. },
  133. }
  134. </script>
  135. <style lang="scss" scoped>
  136. .category {
  137. position: relative;
  138. .title {
  139. padding: 12px 20px;
  140. flex: none;
  141. width: 160px;
  142. box-sizing: border-box;
  143. border-radius: 0;
  144. background: $--color-primary;
  145. color: white;
  146. }
  147. .category-con {
  148. position: absolute;
  149. width: 100%;
  150. z-index: 999;
  151. height: 440px;
  152. padding: 10px 0;
  153. box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
  154. cursor: pointer;
  155. .category-one {
  156. height: 100%;
  157. overflow-y: auto;
  158. &::-webkit-scrollbar {
  159. display: none;
  160. /*隐藏滚动条*/
  161. }
  162. &>li {
  163. border-bottom: $--border-base;
  164. &>a {
  165. height: 42px;
  166. padding: 0 20px;
  167. }
  168. &>div {
  169. height: 42px;
  170. padding: 0 20px;
  171. }
  172. &.active {
  173. // background-color: #ffeeef;
  174. &>div {
  175. color: $--color-primary;
  176. font-weight: bold;
  177. }
  178. }
  179. }
  180. .category-float {
  181. box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
  182. position: absolute;
  183. left: 160px;
  184. top: 0;
  185. width: 880px;
  186. height: 440px;
  187. padding: 0 24px;
  188. overflow-y: auto;
  189. &::-webkit-scrollbar {
  190. display: none;
  191. /*隐藏滚动条*/
  192. }
  193. a:hover {
  194. color: #ff2c3c;
  195. }
  196. .float-con {
  197. .category-three {
  198. border-bottom: 1px dashed $--border-color-base;
  199. .item {
  200. width: 20%;
  201. margin-bottom: 20px;
  202. padding-right: 10px;
  203. }
  204. }
  205. }
  206. }
  207. }
  208. .category-two {
  209. height: 100%;
  210. overflow-y: auto;
  211. &::-webkit-scrollbar {
  212. display: none;
  213. /*隐藏滚动条*/
  214. }
  215. &>li {
  216. &>a {
  217. height: 42px;
  218. padding: 0 20px;
  219. }
  220. &>div {
  221. height: 42px;
  222. padding: 0 20px;
  223. }
  224. &.active {
  225. // background-color: #ffeeef;
  226. div {
  227. color: $--color-primary;
  228. font-weight: bold;
  229. }
  230. }
  231. }
  232. .category-float {
  233. box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
  234. position: absolute;
  235. left: 160px;
  236. top: 0;
  237. width: 880px;
  238. height: 440px;
  239. padding: 0 24px;
  240. overflow-y: auto;
  241. &::-webkit-scrollbar {
  242. display: none;
  243. /*隐藏滚动条*/
  244. }
  245. a:hover {
  246. color: #ff2c3c;
  247. }
  248. .float-con {
  249. .category-three {
  250. border-bottom: 1px dashed $--border-color-base;
  251. .item {
  252. width: 20%;
  253. margin-bottom: 20px;
  254. padding-right: 10px;
  255. }
  256. }
  257. }
  258. }
  259. }
  260. }
  261. }
  262. </style>