CategorySortTop.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. background-color: #fff;
  136. .img{
  137. width: 24px;
  138. position: absolute;
  139. bottom: 0;
  140. left: 113px;
  141. animation: im_icon 1s linear infinite;
  142. }
  143. @keyframes im_icon{
  144. 0%{
  145. opacity: 0.5;
  146. transform: translate(0,0);
  147. }
  148. 50%{
  149. opacity: 1;
  150. transform: translate(0,5px);
  151. }
  152. 100%{
  153. opacity: 0.5;
  154. transform: translate(0,0);
  155. }
  156. }
  157. .menu_wrap {
  158. overflow-y: auto;
  159. overflow-x: hidden;
  160. height: 100%;
  161. direction: rtl;
  162. &::-webkit-scrollbar {
  163. /*滚动条整体样式*/
  164. width : 5px; /*高宽分别对应横竖滚动条的尺寸*/
  165. height: 5px;
  166. }
  167. &::-webkit-scrollbar-thumb {
  168. /*滚动条里面小方块*/
  169. border-radius: 10px;
  170. box-shadow : inset 0 0 5px rgba(0, 0, 0, 0.2);
  171. background : $colorMain;
  172. }
  173. &::-webkit-scrollbar-track {
  174. /*滚动条里面轨道*/
  175. box-shadow : inset 0 0 5px rgba(0, 0, 0, 0.2);
  176. border-radius: 10px;
  177. background : #ededed;
  178. }
  179. .menu_item {
  180. line-height: 1.4;
  181. padding: 9px 0;
  182. position: relative;
  183. border-left: 3px solid transparent;
  184. cursor:pointer;
  185. direction: ltr;
  186. text-align: left;
  187. .first_cat {
  188. width: 100%;
  189. display: block;
  190. font-size: 14px;
  191. color: #333;
  192. padding: 0 10px 0 15px;
  193. text-overflow: ellipsis;
  194. overflow: hidden;
  195. position: relative;
  196. letter-spacing: normal;
  197. &:hover {
  198. color: $colorMain;
  199. }
  200. }
  201. &:hover {
  202. background: #F6F8FA;
  203. // border-left-color: $colorMain;
  204. .children {
  205. display: inline-block;
  206. -webkit-animation: showMore 0.2s ease-in-out;
  207. animation: showMore 0.2s ease-in-out;
  208. @-webkit-keyframes showMore {
  209. 0% {
  210. opacity: 0;
  211. }
  212. to {
  213. opacity: 1;
  214. }
  215. }
  216. @keyframes showMore {
  217. 0% {
  218. opacity: 0;
  219. }
  220. to {
  221. opacity: 1;
  222. }
  223. }
  224. }
  225. }
  226. .children {
  227. display: none;
  228. width: 1013px;
  229. height: 306px;
  230. background-color: #fff;
  231. position: absolute;
  232. top: 0;
  233. left: 250px;
  234. padding: 10px 0;
  235. overflow: hidden;
  236. box-shadow: 0px 5px 10px 0px rgba(153, 153, 153, 0.15);
  237. .fore_dl {
  238. width: 100%;
  239. clear: both;
  240. overflow: hidden;
  241. }
  242. dt {
  243. position: relative;
  244. float: left;
  245. width: 180px;
  246. padding: 5px 30px 0 0;
  247. font-weight: 700;
  248. line-height: 2em;
  249. overflow: hidden;
  250. white-space: nowrap;
  251. margin-left: 30px;
  252. i {
  253. position: absolute;
  254. top: 7px;
  255. right: 8px;
  256. width: 14px;
  257. height: 14px;
  258. font: 400 9px/14px consolas;
  259. color: #333;
  260. }
  261. .second {
  262. color: #666;
  263. font: 700 12px/40px "microsoft yahei";
  264. width: 100%;
  265. overflow: hidden;
  266. display: inline-block;
  267. text-align: left;
  268. line-height: 18px;
  269. text-overflow: ellipsis;
  270. letter-spacing: normal;
  271. &:hover {
  272. color: $colorMain;
  273. }
  274. }
  275. }
  276. dd {
  277. border-top: none;
  278. border-bottom: 1px dashed #dddddd;
  279. width: auto;
  280. padding: 4px 0;
  281. float: left;
  282. line-height: 16px;
  283. margin-left: 15px;
  284. min-height: 32px;
  285. }
  286. .third {
  287. float: left;
  288. padding: 0 8px;
  289. margin: 2px 0;
  290. line-height: 16px;
  291. height: 16px;
  292. border-right: 1px solid #e0e0e0;
  293. white-space: nowrap;
  294. font-size: 12px;
  295. letter-spacing: normal;
  296. &:hover {
  297. color: $colorMain;
  298. }
  299. &:last-child {
  300. border-right: none;
  301. }
  302. }
  303. }
  304. }
  305. }
  306. }
  307. </style>