Category.vue 4.8 KB

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