Category.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <div>
  3. <SldHomeTopSearch />
  4. <NavCatHeader />
  5. <div class="bottom_line"></div>
  6. <div class="goods_sort">
  7. <div class="boxbg" style="z-index: 2; position: relative">
  8. <div class="class_ification_wrap clearfix">
  9. <!-- 一级分类 -->
  10. <ul
  11. :class="{
  12. fl: true,
  13. class_ification: true,
  14. fixed: isTop,
  15. bottomFixed: isBottom,
  16. }"
  17. >
  18. <li
  19. v-for="(item, index) in navList.data"
  20. :key="index"
  21. :class="index === indexNum ? 'on cat_item' : 'cat_item'"
  22. >
  23. <div @click="toTop(item.categoryId, index)">{{ item.categoryName }}</div>
  24. </li>
  25. </ul>
  26. <ul class="class_detail">
  27. <li :class="['detail_item', cateStyle]">
  28. <div class="detail_title">{{ childCate.categoryName }}</div>
  29. <div class="cat_wrap_dd">
  30. <div
  31. class="cat_dd_item"
  32. v-for="(item2, cateIndex) in childCate.data"
  33. :key="cateIndex"
  34. v-show="childCate.data && childCate.data.length"
  35. >
  36. <div
  37. class="fl cat_left"
  38. :style="{ color: color, cursor: 'pointer' }"
  39. >
  40. <nuxt-link
  41. target="_blank"
  42. style="color: inherit"
  43. :to="'/goods/list/'+ calcProductName(item2.categoryName) +'_v-'+ item2.categoryId + '_pid-' + item2.pid + '_gid-' + item2.grade"
  44. >
  45. {{ item2.categoryName }} >
  46. </nuxt-link>
  47. </div>
  48. <div class="cat_add_right">
  49. <span
  50. v-for="(item3, index) in item2.children"
  51. :key="index"
  52. >
  53. <nuxt-link
  54. target="_blank"
  55. style="color: inherit"
  56. :to="'/goods/list/'+ calcProductName(item3.categoryName) +'_v-'+ item3.categoryId + '_pid-' + item3.pid + '_gid-' + item3.grade"
  57. >
  58. {{ item3.categoryName }}
  59. </nuxt-link>
  60. </span>
  61. </div>
  62. </div>
  63. <div
  64. class="detail_none flex_row_center_center"
  65. v-if="!(childCate.data && childCate.data.length) && !firstLoading"
  66. >
  67. <img :src="noneUrl" style="width: 100px; margin-bottom: 15px" />
  68. <p>{{ L["暂无数据"] }}</p>
  69. </div>
  70. </div>
  71. </li>
  72. </ul>
  73. </div>
  74. </div>
  75. </div>
  76. </div>
  77. </template>
  78. <script setup>
  79. // import { lang_zn } from "@/assets/language/zh";
  80. import { getCurLanguage } from '@/composables/common.js';
  81. // const L = lang_zn;
  82. const L = getCurLanguage();
  83. const firstLoading = ref(true); //是否第一次加载
  84. const noneUrl = ref("/common_empty.png");
  85. let indexNum = ref(0);
  86. const router = useRouter();
  87. const navList = reactive({ data: {} });
  88. const isTop = ref(false);
  89. const isBottom = ref(false);
  90. useHead({
  91. title: 'Categories',
  92. meta: [
  93. {
  94. name: "description",
  95. content: 'Categories',
  96. },
  97. {
  98. name: "keywords",
  99. content: 'Categories',
  100. },
  101. ],
  102. });
  103. const getInitData = async (index, params) => {
  104. //SSR
  105. const { data: value } = await useFetchRaw(
  106. apiUrl + "v3/goods/front/goods/category/topCategory",
  107. { params }
  108. );
  109. const res = value._rawValue;
  110. if (res.state == 200) {
  111. navList.data = res.data;
  112. getChild(navList.data[0].categoryId, index);
  113. }
  114. };
  115. getInitData(0, {});
  116. const childCate = reactive({
  117. categoryName: "",
  118. data: [],
  119. });
  120. const cateStyle = ref("item_style1");
  121. const getChild = async (categoryId1, index) => {
  122. const { data: value } = await useFetchRaw(
  123. apiUrl + "v3/goods/front/goods/category/bottomCategory?categoryId1=" + categoryId1,
  124. { key: categoryId1.toString() }
  125. );
  126. const res = value._rawValue;
  127. if (res.state == 200) {
  128. childCate.data = res.data;
  129. childCate.categoryName = navList.data[index].categoryName;
  130. }
  131. };
  132. const toTop = (categoryId, index) => {
  133. indexNum.value = index;
  134. let odd = (index + 1) % 9;
  135. cateStyle.value = `item_style${odd}`;
  136. getChild(categoryId, index);
  137. };
  138. onMounted(() => {
  139. setTimeout(() => {
  140. sldStatEvent({ behaviorType: 'pv',pageUrl: defaultUrl + router.currentRoute.value.path, referrerPageUrl: apiUrl });
  141. }, 3000)
  142. });
  143. </script>
  144. <style lang="scss" scoped>
  145. @import "@/assets/style/category.scss";
  146. @import "@/assets/style/base.scss";
  147. .detail_none {
  148. flex-direction: column;
  149. margin-top: 7px;
  150. width: inherit;
  151. height: 200px;
  152. }
  153. .detail_none p {
  154. padding: 7px;
  155. }
  156. </style>