|
|
|
@ -39,7 +39,7 @@
|
|
|
|
|
class="tab-category-menu__right flex-1"
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
v-for="item in categroyData"
|
|
|
|
|
v-for="item in list"
|
|
|
|
|
:key="item.id"
|
|
|
|
|
@mouseenter="handleCategoryHover(item.id)"
|
|
|
|
|
class="category-menu-right__wrap"
|
|
|
|
@ -61,10 +61,8 @@
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<script>
|
|
|
|
|
import {
|
|
|
|
|
ApiGetCategoryOneList,
|
|
|
|
|
ApiGetCategoryTwoAndGoods,
|
|
|
|
|
} from "@/plugins/api/goods";
|
|
|
|
|
import { mapState } from "vuex";
|
|
|
|
|
import { ApiGetCategoryTwoAndGoods } from "@/plugins/api/goods";
|
|
|
|
|
import { CATEGROY_LEVEL } from "@/constants";
|
|
|
|
|
const CATEGROY_HIDE_PAGES = [/\/account/]; // 隐藏热门分类tab的页面
|
|
|
|
|
|
|
|
|
@ -76,10 +74,11 @@ export default {
|
|
|
|
|
categroyTwoVisible: false, // 是否展示二级分类
|
|
|
|
|
categroyVisible: false, // 是否展示一级分类
|
|
|
|
|
currentCategroyId: 0, // 当前鼠标悬停的一级分类id
|
|
|
|
|
categroyData: [],
|
|
|
|
|
list: [],
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
...mapState(["categroyData"]),
|
|
|
|
|
showCategroyTab() {
|
|
|
|
|
return !CATEGROY_HIDE_PAGES.some((reg) => {
|
|
|
|
|
return reg.test(this.$route.path);
|
|
|
|
@ -91,28 +90,32 @@ export default {
|
|
|
|
|
return this.$route.path === "/";
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
created() {
|
|
|
|
|
this.getCategroyData();
|
|
|
|
|
watch: {
|
|
|
|
|
categroyData: {
|
|
|
|
|
immediate: true,
|
|
|
|
|
handler(val) {
|
|
|
|
|
if (val.length > 0) {
|
|
|
|
|
this.getCategroyData();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
// 获取热门分类信息
|
|
|
|
|
async getCategroyData() {
|
|
|
|
|
const { result } = await ApiGetCategoryOneList();
|
|
|
|
|
if (result && result.length > 0) {
|
|
|
|
|
this.categroyData = await Promise.all(
|
|
|
|
|
result.map(async (item) => {
|
|
|
|
|
const { result: resultGoods } = await ApiGetCategoryTwoAndGoods({
|
|
|
|
|
categoryId: item.id,
|
|
|
|
|
});
|
|
|
|
|
if (resultGoods && resultGoods.length > 0) {
|
|
|
|
|
return {
|
|
|
|
|
...item,
|
|
|
|
|
list: resultGoods,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
this.list = await Promise.all(
|
|
|
|
|
this.categroyData.map(async (item) => {
|
|
|
|
|
const { result: resultGoods } = await ApiGetCategoryTwoAndGoods({
|
|
|
|
|
categoryId: item.id,
|
|
|
|
|
});
|
|
|
|
|
if (resultGoods && resultGoods.length > 0) {
|
|
|
|
|
return {
|
|
|
|
|
...item,
|
|
|
|
|
list: resultGoods,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
// 一级分类鼠标悬停
|
|
|
|
|
handleCategoryHover(id) {
|
|
|
|
|