CategorySortTop.vue 8.0 KB

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