CategorySortTop.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. <template>
  2. <div ref="category_sort" class="2" id="category_sort" >
  3. <ul class="menu_wrap" ref="menu_wrap" @scroll="scrollMenu">
  4. <!-- 一级分类 start-->
  5. <li
  6. class="menu_item"
  7. v-for="(item1, firstIndex) in cateData.data"
  8. v-bind:key="firstIndex"
  9. style="position: static"
  10. @mouseover="selectTab(firstIndex, item1.categoryId)"
  11. >
  12. <a class="first_cat" @click.stop="toGoodsList(item1)">
  13. <span class="label">{{ item1.categoryName }} </span>
  14. <span class="icont">></span>
  15. </a>
  16. <div class="children" @click.stop="void 0">
  17. <!-- 二级分类 start-->
  18. <div v-if="cateDataFirst.data.length > 0">
  19. <dl
  20. class="fore_dl"
  21. v-for="(item2, index) in cateDataFirst.data"
  22. v-bind:key="index"
  23. >
  24. <dt>
  25. <a class="second" @click.stop="toGoodsList(item2)">
  26. {{ item2.categoryName }}</a
  27. >
  28. <i>&gt;</i>
  29. </dt>
  30. <dd>
  31. <!-- 三级分类 start-->
  32. <a
  33. class="third"
  34. @click.stop="toGoodsList(item3)"
  35. v-for="(item3, thirdIndex) in item2.children"
  36. v-bind:key="thirdIndex"
  37. >{{ item3.categoryName }}</a
  38. >
  39. </dd>
  40. </dl>
  41. </div>
  42. <SldCommonEmpty v-else totalWidth="900" totalHeight="300" style="color: #666" />
  43. <!-- 二级分类 end-->
  44. </div>
  45. </li>
  46. <!-- 一级分类 end-->
  47. </ul>
  48. <!-- <img v-show="showDown" src="/arrows_down_double-34.svg" class="img" /> -->
  49. </div>
  50. </template>
  51. <script setup>
  52. // import { lang_zn } from "@/assets/language/zh";
  53. import { getCurLanguage } from '@/composables/common.js';
  54. const route = useRoute();
  55. const router = useRouter();
  56. const { proxy } = getCurrentInstance();
  57. // const L = lang_zn;
  58. const L = getCurLanguage();
  59. const cateShow = ref(false);
  60. const cateDataFirst = reactive({ data: [] });
  61. const cateCache = reactive({ data: [] });
  62. const showDown = ref(false)
  63. //获取商品分类下面的一级菜单
  64. const cateData = reactive({ data: [] });
  65. const getInitData = (index, params) => {
  66. get("v3/goods/front/goods/category/topCategory").then((res) => {
  67. if (res.state == 200) {
  68. cateData.data = res.data;
  69. if(cateData.data.length < 9){
  70. showDown.value = false
  71. }else{
  72. showDown.value = true
  73. }
  74. }
  75. })
  76. };
  77. getInitData(0, {});
  78. const selectTab = (index, categoryId) => {
  79. // cateShow.value = true
  80. cateDataFirst.data = [];
  81. let params = {
  82. categoryId1: categoryId,
  83. };
  84. let index1 = cateCache.data.findIndex((item) => item.categoryId == categoryId);
  85. if (index1 > -1) {
  86. cateDataFirst.data = cateCache.data[index1].list;
  87. } else {
  88. getSortChild(index, params);
  89. }
  90. };
  91. const getSortChild = (index, params) => {
  92. get("v3/goods/front/goods/category/bottomCategory", params).then((res) => {
  93. if (res.state == 200) {
  94. let index1 = cateCache.data.findIndex(
  95. (item) => item.categoryId == params.categoryId1
  96. );
  97. if (index1 > -1) {
  98. cateDataFirst.data = cateCache.data[index1].list;
  99. } else {
  100. cateDataFirst.data = res.data;
  101. cateCache.data.push({ categoryId: params.categoryId1, list: res.data });
  102. }
  103. }
  104. });
  105. };
  106. const scrollMenu = (e) => {
  107. if(Math.floor(e.target.scrollTop) + Math.floor(e.target.clientHeight) >= Math.floor(e.target.scrollHeight)){
  108. showDown.value = false
  109. }else{
  110. showDown.value = true
  111. }
  112. }
  113. const toGoodsList = (item) => {
  114. let newWin = router.resolve({
  115. path:'/goods/list/'+ calcProductName(item.categoryName) +'_v-'+item.categoryId+'_gid-'+item.grade+'_pid-'+item.pid,
  116. });
  117. window.open(newWin.href, "_blank");
  118. };
  119. </script>
  120. <style lang="scss" scoped>
  121. @import "@/assets/style/theme.scss";
  122. .index {
  123. background: #f8f8f8;
  124. padding-bottom: 10px;
  125. }
  126. #category_sort {
  127. font-size: 12px;
  128. position: relative;
  129. left: 0px;
  130. top: 0px;
  131. width: 100%;
  132. height: 306px;
  133. z-index: 9;
  134. -webkit-box-sizing: border-box;
  135. box-sizing: border-box;
  136. background-color: #fff;
  137. .img{
  138. width: 24px;
  139. position: absolute;
  140. bottom: 0;
  141. left: 113px;
  142. animation: im_icon 1s linear infinite;
  143. }
  144. @keyframes im_icon{
  145. 0%{
  146. opacity: 0.5;
  147. transform: translate(0,0);
  148. }
  149. 50%{
  150. opacity: 1;
  151. transform: translate(0,5px);
  152. }
  153. 100%{
  154. opacity: 0.5;
  155. transform: translate(0,0);
  156. }
  157. }
  158. .menu_wrap {
  159. overflow-y: auto;
  160. overflow-x: hidden;
  161. height: 100%;
  162. direction: rtl;
  163. width: 300px;
  164. &::-webkit-scrollbar {
  165. /*滚动条整体样式*/
  166. width : 5px; /*高宽分别对应横竖滚动条的尺寸*/
  167. height: 5px;
  168. }
  169. &::-webkit-scrollbar-thumb {
  170. /*滚动条里面小方块*/
  171. border-radius: 10px;
  172. box-shadow : inset 0 0 5px rgba(0, 0, 0, 0.2);
  173. background : $colorMain;
  174. }
  175. &::-webkit-scrollbar-track {
  176. /*滚动条里面轨道*/
  177. box-shadow : inset 0 0 5px rgba(0, 0, 0, 0.2);
  178. border-radius: 10px;
  179. background : #ededed;
  180. }
  181. .menu_item {
  182. line-height: 1.4;
  183. padding: 9px 0;
  184. position: relative;
  185. border-left: 3px solid transparent;
  186. cursor:pointer;
  187. direction: ltr;
  188. text-align: left;
  189. .first_cat {
  190. display: flex;
  191. width: 100%;
  192. font-size: 14px;
  193. color: #333;
  194. padding: 0 10px 0 15px;
  195. overflow: hidden;
  196. position: relative;
  197. .label {
  198. display: inline-block;
  199. flex: 1;
  200. width: 100%;
  201. text-overflow: ellipsis;
  202. overflow: hidden;
  203. white-space: nowrap;
  204. }
  205. .icont {
  206. display: inline-block;
  207. width: 10px;
  208. }
  209. &:hover {
  210. color: $colorMain;
  211. }
  212. }
  213. &:hover {
  214. background: #F6F8FA;
  215. // border-left-color: $colorMain;
  216. .children {
  217. display: inline-block;
  218. -webkit-animation: showMore 0.2s ease-in-out;
  219. animation: showMore 0.2s ease-in-out;
  220. @-webkit-keyframes showMore {
  221. 0% {
  222. opacity: 0;
  223. }
  224. to {
  225. opacity: 1;
  226. }
  227. }
  228. @keyframes showMore {
  229. 0% {
  230. opacity: 0;
  231. }
  232. to {
  233. opacity: 1;
  234. }
  235. }
  236. }
  237. }
  238. .children {
  239. display: none;
  240. width: max-content;
  241. height: 306px;
  242. background-color: #fff;
  243. position: absolute;
  244. top: 0;
  245. left: 300px;
  246. padding-top: 10px;
  247. padding-right: 10px;
  248. overflow: hidden;
  249. box-shadow: 0px 5px 10px 0px rgba(153, 153, 153, 0.15);
  250. .fore_dl {
  251. width: 100%;
  252. clear: both;
  253. overflow: hidden;
  254. font-size: 14px !important;
  255. }
  256. dt {
  257. position: relative;
  258. float: left;
  259. width: 180px;
  260. padding: 5px 30px 0 0;
  261. font-weight: 700;
  262. line-height: 2em;
  263. overflow: hidden;
  264. white-space: nowrap;
  265. margin-left: 30px;
  266. i {
  267. position: absolute;
  268. top: 7px;
  269. right: 8px;
  270. width: 14px;
  271. height: 14px;
  272. font: 400 9px/14px consolas;
  273. color: #333;
  274. }
  275. .second {
  276. color: #666;
  277. font: 700 12px/40px "microsoft yahei";
  278. width: 100%;
  279. overflow: hidden;
  280. display: inline-block;
  281. text-align: left;
  282. line-height: 18px;
  283. text-overflow: ellipsis;
  284. letter-spacing: normal;
  285. &:hover {
  286. color: $colorMain;
  287. }
  288. }
  289. }
  290. dd {
  291. border-top: none;
  292. border-bottom: 1px dashed #dddddd;
  293. width: auto;
  294. padding: 4px 0;
  295. float: left;
  296. line-height: 16px;
  297. margin-left: 15px;
  298. min-height: 32px;
  299. }
  300. .third {
  301. float: left;
  302. padding: 0 8px;
  303. margin: 2px 0;
  304. line-height: 16px;
  305. height: 16px;
  306. border-right: 1px solid #e0e0e0;
  307. white-space: nowrap;
  308. font-size: 12px;
  309. letter-spacing: normal;
  310. &:hover {
  311. color: $colorMain;
  312. }
  313. &:last-child {
  314. border-right: none;
  315. }
  316. }
  317. }
  318. }
  319. }
  320. }
  321. </style>