NsHeader.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <template>
  2. <div class="header">
  3. <ns-header-top />
  4. <ns-header-mid />
  5. <div class="nav">
  6. <div class="shop-list-content"
  7. :class="forceExpand || isShopHover || (isIndex && is_show) ? 'shop-list-active' : 'shadow'">
  8. <div class="shop-list" v-if="categoryConfig.category ==1" @mouseover="shopHover" @mouseleave="shopLeave">
  9. <div class="list-item" v-for="(item, index) in goodsCategoryTree" :key="index"
  10. @mouseover="selectedCategory = item.category_id" @mouseleave="selectedCategory = -1">
  11. <router-link :to="{ path: '/goods/list', query: { category_id: item.category_id, level: item.level } }"
  12. target="_blank">
  13. <div>
  14. <img class="category-img" v-if="categoryConfig.img == 1 && item.image" :src="$util.img(item.image)" />
  15. <p class="category-name">{{item.category_name }}</p>
  16. </div>
  17. <i class="el-icon-arrow-right" aria-hidden="true"></i>
  18. </router-link>
  19. </div>
  20. </div>
  21. <!-- 分类类型2 -->
  22. <div class="shop-list"
  23. :class="forceExpand || isShopHover || (isIndex && is_show) ? 'shop-list-active' : 'shadow'"
  24. v-else-if="categoryConfig.category ==2" @mouseover="shopHover" @mouseleave="shopLeave">
  25. <div class="list-item" v-for="(item, index) in goodsCategoryTree" :key="index"
  26. @mouseover="selectedCategory = item.category_id" @mouseleave="selectedCategory = -1">
  27. <router-link :to="{ path: '/goods/list', query: { category_id: item.category_id, level: item.level } }"
  28. target="_blank">
  29. <div>
  30. <img class="category-img" v-if="categoryConfig.img == 1 && item.image" :src="$util.img(item.image)" />
  31. <p class="category-name">{{ item.category_name }}</p>
  32. </div>
  33. <i class="el-icon-arrow-right" aria-hidden="true"></i>
  34. </router-link>
  35. <div class="cate-part" v-if="item.child_list" :class="{ show: selectedCategory == item.category_id }">
  36. <div class="cate-part-col1">
  37. <div class="cate-detail">
  38. <div class="cate-detail-item">
  39. <div class="cate-detail-con">
  40. <router-link v-for="(second_item, second_index) in item.child_list" :key="second_index"
  41. target="_blank"
  42. :to="{ path: '/goods/list', query: { category_id: second_item.category_id, level: second_item.level } }">
  43. <img class="cate-detail-img" v-if="categoryConfig.img == 1"
  44. :src="$util.img(second_item.image)" />
  45. <p class="category-name">{{second_item.category_name }}</p>
  46. </router-link>
  47. </div>
  48. </div>
  49. </div>
  50. </div>
  51. </div>
  52. </div>
  53. </div>
  54. <!-- 分类类型3 -->
  55. <div class="shop-list" :class="forceExpand || isShopHover || isIndex ? 'shop-list-active' : 'shadow'"
  56. v-else-if="categoryConfig.category ==3" @mouseover="shopHover" @mouseleave="shopLeave">
  57. <div class="list-item" v-for="(item, index) in goodsCategoryTree" :key="index"
  58. @mouseover="selectedCategory = item.category_id" @mouseleave="selectedCategory = -1">
  59. <router-link :to="{ path: '/goods/list', query: { category_id: item.category_id, level: item.level } }"
  60. target="_blank">
  61. <div class="list-item-left">
  62. <img class="category-img" v-if="categoryConfig.img == 1 && item.image" :src="$util.img(item.image)" />
  63. <p class="category-name">{{item.category_name }}</p>
  64. </div>
  65. <!-- <i class="el-icon-arrow-right" aria-hidden="true" v-if="item.child_list"></i> -->
  66. </router-link>
  67. <div class="item-itm " :class="{'item-itm-img':categoryConfig.img == 1}">
  68. <router-link v-for="(second_item, second_index) in item.child_list" :key="second_index"
  69. :to="{ path: '/goods/list', query: { category_id: second_item.category_id, level: second_item.level } }"
  70. target="_blank" v-show="second_index < 3" style="display:inline-block;">
  71. {{ second_item.short_name?second_item.short_name : second_item.category_name }}
  72. </router-link>
  73. </div>
  74. <div class="cate-part" v-if="item.child_list" :class="{ show: selectedCategory == item.category_id }">
  75. <div class="cate-part-col1">
  76. <div class="cate-detail">
  77. <dl class="cate-detail-item" v-for="(second_item, second_index) in item.child_list"
  78. :key="second_index">
  79. <dt class="cate-detail-tit">
  80. <router-link target="_blank"
  81. :to="{ path: '/goods/list', query: { category_id: second_item.category_id, level: second_item.level } }">
  82. {{ second_item.category_name }}
  83. </router-link>
  84. </dt>
  85. <dd class="cate-detail-con" v-if="second_item.child_list">
  86. <router-link v-for="(third_item, third_index) in second_item.child_list" :key="third_index"
  87. target="_blank"
  88. :to="{ path: '/goods/list', query: { category_id: third_item.category_id, level: third_item.level } }">
  89. <img class="cate-detail-img" v-if="categoryConfig.img == 1"
  90. :src="$util.img(third_item.image)" />
  91. <p class="category-name">{{third_item.category_name }}</p>
  92. </router-link>
  93. </dd>
  94. </dl>
  95. </div>
  96. </div>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. </div>
  102. </div>
  103. </template>
  104. <script>
  105. import NsHeaderTop from './NsHeaderTop';
  106. import NsHeaderMid from './NsHeaderMid';
  107. import {
  108. tree,
  109. categoryConfig
  110. } from '@/api/goods/goodscategory';
  111. import {
  112. mapGetters
  113. } from "vuex"
  114. export default {
  115. props: {
  116. forceExpand: {
  117. type: Boolean,
  118. default: false
  119. }
  120. },
  121. computed: {
  122. ...mapGetters(['is_show'])
  123. },
  124. data() {
  125. return {
  126. isShopHover: false,
  127. isIndex: false,
  128. thisRoute: '',
  129. goodsCategoryTree: [],
  130. categoryConfig: {},
  131. selectedCategory: -1,
  132. isHide: false
  133. };
  134. },
  135. components: {
  136. NsHeaderTop,
  137. NsHeaderMid,
  138. mapGetters
  139. },
  140. beforeCreate() {},
  141. created() {
  142. this.$store.dispatch('cart/cart_count');
  143. this.getCategoryConfig();
  144. // this.getTree();
  145. if (this.$route.path == '/' || this.$route.path == '/index') {
  146. this.isIndex = true;
  147. }
  148. },
  149. watch: {
  150. $route: function(curr) {
  151. let judgeLength = localStorage.getItem('isAdList')
  152. if (this.$route.path == '/' || this.$route.path == '/index') this.isIndex = true;
  153. else this.isIndex = false;
  154. }
  155. },
  156. methods: {
  157. // 获取配置
  158. getCategoryConfig() {
  159. categoryConfig({
  160. })
  161. .then(res => {
  162. if (res.code == 0 && res.data) {
  163. this.categoryConfig = res.data;
  164. this.getTree(res.data);
  165. }
  166. })
  167. .catch(err => {
  168. this.$message.error(err.message);
  169. });
  170. },
  171. getTree(categoryConfig) {
  172. tree({
  173. level: 3,
  174. template: 2
  175. })
  176. .then(res => {
  177. if (res.code == 0 && res.data) {
  178. this.goodsCategoryTree = res.data || [];
  179. for (let i = 0; i < this.goodsCategoryTree.length; i++) {
  180. if (this.goodsCategoryTree[i].child_list > 3) {
  181. this.isHide = true
  182. }
  183. }
  184. }
  185. })
  186. .catch(err => {
  187. this.$message.error(err.message);
  188. });
  189. },
  190. //鼠标移入显示商品分类
  191. shopHover() {
  192. this.isShopHover = true;
  193. },
  194. //鼠标移出商品分类隐藏
  195. shopLeave() {
  196. this.isShopHover = false;
  197. }
  198. }
  199. };
  200. </script>
  201. <style scoped lang="scss">
  202. .header {
  203. width: 100%;
  204. background-color: #fff;
  205. .shadow {
  206. box-shadow: -1px 3px 12px -1px rgba(0, 0, 0, 0.3);
  207. }
  208. .border {
  209. border: 1px solid #f5f5f5;
  210. }
  211. .nav {
  212. width: 1210px;
  213. margin: 0 auto;
  214. position: relative;
  215. .shop-list-content {
  216. width: 240px;
  217. height: 500px;
  218. position: absolute;
  219. left: 0;
  220. top: 1px;
  221. background-color: rgba(0, 0, 0, 0.6);
  222. display: none;
  223. padding: 0;
  224. box-sizing: border-box;
  225. font-size: $ns-font-size-base;
  226. z-index: 10;
  227. color: #FFFFFF;
  228. &::-webkit-scrollbar {
  229. display: none;
  230. }
  231. .shop-list {
  232. width: 240px;
  233. height: 500px;
  234. overflow-y: auto;
  235. overflow-x: hidden;
  236. &::-webkit-scrollbar {
  237. display: none;
  238. }
  239. a:hover {
  240. color: $base-color;
  241. }
  242. .list-item {
  243. padding-left: 40px;
  244. padding-right: 15px;
  245. box-sizing: border-box;
  246. a {
  247. display: flex;
  248. justify-content: space-between;
  249. align-items: center;
  250. height: 46px;
  251. white-space: nowrap;
  252. overflow: hidden;
  253. text-overflow: ellipsis;
  254. color: #FFFFFF;
  255. >div {
  256. display: flex;
  257. align-items: center;
  258. }
  259. }
  260. &:hover {
  261. background-color: rgba(31,0,0,0.4);
  262. -webkit-transition: 0.2s ease-in-out;
  263. -moz-transition: -webkit-transform 0.2s ease-in-out;
  264. -moz-transition: 0.2s ease-in-out;
  265. transition: 0.2s ease-in-out;
  266. }
  267. span:hover {
  268. color: #FD274A;
  269. }
  270. .category-img {
  271. width: 17px;
  272. height: 17px;
  273. margin-right: 10px;
  274. }
  275. .category-name {
  276. overflow: hidden;
  277. text-overflow: ellipsis;
  278. white-space: nowrap;
  279. }
  280. .item-itm {
  281. font-size: 14px;
  282. line-height: 15px;
  283. height: 28px;
  284. overflow: hidden;
  285. a {
  286. margin-top: 5px;
  287. margin-right: 10px;
  288. color: #BFBFBF;
  289. &:hover {
  290. color: #FD274A !important;
  291. }
  292. }
  293. &.item-itm-img {
  294. margin-left: 27px;
  295. }
  296. }
  297. .cate-part {
  298. display: none;
  299. position: absolute;
  300. left: 240px;
  301. top: 0;
  302. z-index: auto;
  303. // width: 998px;
  304. width: 760px;
  305. height: 498px;
  306. overflow-y: auto;
  307. border: 1px solid #f7f7f7;
  308. background-color: #fff;
  309. -webkit-box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
  310. -moz-box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
  311. box-shadow: 2px 0 5px rgba(0, 0, 0, 0.05);
  312. -webkit-transition: top 0.25s ease;
  313. -o-transition: top 0.25s ease;
  314. -moz-transition: top 0.25s ease;
  315. transition: top 0.25s ease;
  316. &.show {
  317. display: block;
  318. }
  319. &::-webkit-scrollbar {
  320. display: none;
  321. }
  322. }
  323. .cate-part-col1 {
  324. float: left;
  325. width: 100%;
  326. .cate-detail-item {
  327. position: relative;
  328. min-height: 36px;
  329. padding-left: 20px;
  330. &:last-child {
  331. margin-bottom: 30px;
  332. }
  333. .cate-detail-tit {
  334. margin-top: 30px;
  335. margin-right: 20px;
  336. white-space: nowrap;
  337. text-overflow: ellipsis;
  338. font-weight: 700;
  339. a {
  340. display: block;
  341. color: #333333;
  342. }
  343. a:hover {
  344. color: #FD274A;
  345. }
  346. }
  347. .cate-detail-con {
  348. overflow: hidden;
  349. padding: 6px 0 6px 17px;
  350. display: flex;
  351. flex-wrap: wrap;
  352. // border-top: 1px dashed #eee;
  353. a {
  354. justify-content: start;
  355. font-size: 12px;
  356. height: 30px;
  357. /* float: left; */
  358. margin: 4px 40px 4px 0;
  359. padding: 0 10px;
  360. white-space: nowrap;
  361. line-height: 30px;
  362. color: #666;
  363. width: calc((100% - 120px) / 4);
  364. display: flex;
  365. box-sizing: border-box;
  366. margin-top: 20px;
  367. .cate-detail-img {
  368. width: 30px;
  369. height: 30px;
  370. margin-right: 10px;
  371. }
  372. &:nth-child(4n+4) {
  373. margin-right: 0;
  374. }
  375. }
  376. a:hover {
  377. color: #FD274A;
  378. }
  379. }
  380. &:first-child .cate-detail-con {
  381. border-top: none;
  382. }
  383. }
  384. }
  385. // .sub-class-right {
  386. // display: block;
  387. // width: 240px;
  388. // height: 439px;
  389. // float: right;
  390. // border-left: solid 1px #e6e6e6;
  391. // overflow: hidden;
  392. // .adv-promotions {
  393. // display: block;
  394. // height: 441px;
  395. // margin: -1px 0;
  396. // a {
  397. // background: #fff;
  398. // display: block;
  399. // width: 240px;
  400. // height: 146px;
  401. // border-top: solid 1px #e6e6e6;
  402. // img {
  403. // background: #d3d3d3;
  404. // width: 240px;
  405. // height: 146px;
  406. // }
  407. // }
  408. // }
  409. // }
  410. }
  411. }
  412. }
  413. .shop-list-active {
  414. display: block;
  415. }
  416. }
  417. }
  418. </style>