CategorySort.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <template>
  2. <div ref="category_sort" class="3" id="category_sort">
  3. <ul class="menu_wrap">
  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. >
  11. <a class="first_cat" @mouseover="selectTab(firstIndex, item1.categoryId)" @click.stop="toGoodsList(item1)">
  12. {{ item1.categoryName }}</a
  13. >
  14. <div class="children" @click.stop="void 0">
  15. <div v-if="cateDataFirst.data.length > 0">
  16. <dl
  17. class="fore_dl"
  18. >
  19. <dd v-for="(item2, index) in cateDataFirst.data"
  20. v-bind:key="index">
  21. <a class="third" @click.stop="toGoodsList(item2)">
  22. {{ item2.categoryName }}</a
  23. >
  24. </dd>
  25. </dl>
  26. </div>
  27. <SldCommonEmpty v-else totalWidth="900" totalHeight="300" style="color: #666" />
  28. </div>
  29. </li>
  30. </ul>
  31. </div>
  32. </template>
  33. <script setup>
  34. // import { lang_zn } from "@/assets/language/zh";
  35. import { getCurLanguage } from '@/composables/common.js';
  36. const route = useRoute();
  37. const router = useRouter();
  38. const { proxy } = getCurrentInstance();
  39. // const L = lang_zn;
  40. const L = getCurLanguage();
  41. const cateShow = ref(false);
  42. const cateDataFirst = reactive({ data: [] });
  43. const cateCache = reactive({ data: [] });
  44. onMounted(() => {
  45. let path = route.path;
  46. if (path == "/") {
  47. proxy.$refs.category_sort.style.display = "block";
  48. } else if (path == "/goods/Category") {
  49. proxy.$refs.category_sort.style.display = "none";
  50. }
  51. });
  52. //获取产品分类下面的一级菜单
  53. const cateData = reactive({ data: [] });
  54. const getInitData = async (index, params) => {
  55. const { data: value } = await useFetchRaw(
  56. apiUrl + "v3/goods/front/goods/category/getSecondCategory"
  57. );
  58. const res = value._rawValue;
  59. if (res.state == 200) {
  60. cateData.data = res.data.slice(0, 12);
  61. }
  62. };
  63. getInitData(0, {});
  64. const selectTab = (index, categoryId) => {
  65. // cateShow.value = true
  66. cateDataFirst.data = [];
  67. let params = {
  68. categoryId: categoryId,
  69. grade:3
  70. };
  71. // let index1 = cateCache.data.findIndex((item) => item.categoryId == categoryId);
  72. // if (index1 > -1) {
  73. // cateDataFirst.data = cateCache.data[index1].list;
  74. // } else {
  75. getSortChild(index, params);
  76. // }
  77. };
  78. const getSortChild = (index, params) => {
  79. get("v3/goods/front/goods/category/listByPId", params).then((res) => {
  80. if (res.state == 200) {
  81. // let index1 = cateCache.data.findIndex(
  82. // (item) => item.categoryId == params.categoryId1
  83. // );
  84. // if (index1 > -1) {
  85. // cateDataFirst.data = cateCache.data[index1].list;
  86. // } else {
  87. cateDataFirst.data = res.data;
  88. // cateCache.data.push({ categoryId: params.categoryId1, list: res.data });
  89. // }
  90. }
  91. });
  92. };
  93. const toGoodsList = (item) => {
  94. let newWin = router.resolve({
  95. // path: "/goods/list",
  96. path:'/goods/list/'+ calcProductName(item.categoryName) +'_v-'+item.categoryId+'_gid-'+item.grade+'_pid-'+item.pid,
  97. // query: {
  98. // categoryId: item.categoryId,
  99. // g: item.grade,
  100. // pid: item.pid,
  101. // },
  102. });
  103. window.open(newWin.href, "_blank");
  104. };
  105. </script>
  106. <style lang="scss" scoped>
  107. @use "@/assets/style/theme.scss" as *;
  108. .index {
  109. background: #f8f8f8;
  110. padding-bottom: 10px;
  111. }
  112. ul,
  113. ol,
  114. li {
  115. list-style: none;
  116. }
  117. a,
  118. a:visited,
  119. a:link {
  120. text-decoration: none;
  121. color: #666;
  122. }
  123. #category_sort {
  124. font-size: 12px;
  125. display: none;
  126. position: relative;
  127. left: 0px;
  128. top: 0px;
  129. width: 100%;
  130. height: 306px;
  131. z-index: 9;
  132. -webkit-box-sizing: border-box;
  133. box-sizing: border-box;
  134. .menu_wrap {
  135. overflow-y: auto;
  136. overflow-x: hidden;
  137. height: 100%;
  138. .menu_item {
  139. line-height: 1.4;
  140. padding: 10px 0;
  141. position: relative;
  142. border-left: 3px solid transparent;
  143. cursor:pointer;
  144. .first_cat {
  145. width: 100%;
  146. display: block;
  147. font-size: 14px;
  148. color: #333;
  149. padding: 0 10px 0 15px;
  150. text-overflow: ellipsis;
  151. overflow: hidden;
  152. position: relative;
  153. letter-spacing: normal;
  154. &:hover {
  155. color: $colorMain;
  156. }
  157. }
  158. &:hover {
  159. border-left-color: #00985e;
  160. .children {
  161. display: inline-block;
  162. -webkit-animation: showMore 0.2s ease-in-out;
  163. animation: showMore 0.2s ease-in-out;
  164. @-webkit-keyframes showMore {
  165. 0% {
  166. opacity: 0;
  167. }
  168. to {
  169. opacity: 1;
  170. }
  171. }
  172. @keyframes showMore {
  173. 0% {
  174. opacity: 0;
  175. }
  176. to {
  177. opacity: 1;
  178. }
  179. }
  180. }
  181. }
  182. .children {
  183. display: none;
  184. width: 1013px;
  185. height: 306px;
  186. background-color: #fff;
  187. position: absolute;
  188. top: 0;
  189. left: 187px;
  190. padding: 10px 0;
  191. overflow: hidden;
  192. box-shadow: 0px 5px 10px 0px rgba(153, 153, 153, 0.15);
  193. .fore_dl {
  194. width: 100%;
  195. clear: both;
  196. overflow: hidden;
  197. }
  198. dt {
  199. position: relative;
  200. float: left;
  201. width: 84px;
  202. padding: 5px 30px 0 0;
  203. font-weight: 700;
  204. line-height: 2em;
  205. overflow: hidden;
  206. white-space: nowrap;
  207. margin-left: 30px;
  208. i {
  209. position: absolute;
  210. top: 7px;
  211. right: 8px;
  212. width: 14px;
  213. height: 14px;
  214. font: 400 9px/14px consolas;
  215. color: #333;
  216. }
  217. .second {
  218. color: #666;
  219. font: 700 12px/40px "microsoft yahei";
  220. width: 54px;
  221. overflow: hidden;
  222. display: inline-block;
  223. text-align: right;
  224. line-height: 18px;
  225. text-overflow: ellipsis;
  226. letter-spacing: normal;
  227. &:hover {
  228. color: $colorMain;
  229. }
  230. }
  231. }
  232. dd {
  233. border-top: none;
  234. border-bottom: 1px dashed #dddddd;
  235. width: 790px;
  236. padding: 4px 0;
  237. float: left;
  238. line-height: 16px;
  239. margin-left: 15px;
  240. min-height: 32px;
  241. }
  242. .third {
  243. float: left;
  244. padding: 0 8px;
  245. margin: 2px 0;
  246. line-height: 16px;
  247. height: 16px;
  248. border-right: 1px solid #e0e0e0;
  249. white-space: nowrap;
  250. font-size: 12px;
  251. letter-spacing: normal;
  252. &:hover {
  253. color: $colorMain;
  254. }
  255. &:last-child {
  256. border-right: none;
  257. }
  258. }
  259. }
  260. }
  261. }
  262. }
  263. </style>