优化分类列表

This commit is contained in:
TOP糯米 2023-03-08 12:57:04 +08:00
parent 1cb80769a9
commit bc819831f0
3 changed files with 26 additions and 17 deletions

View File

@ -75,6 +75,10 @@ export default {
type: Number, type: Number,
default: 0, default: 0,
}, },
activeId: {
type: [String, Number],
default: 0,
},
data: { data: {
type: Array, type: Array,
default: [], default: [],
@ -108,7 +112,6 @@ export default {
// H5tabbar // H5tabbar
this.wrapHeight -= this.$utils.rpx2px(100); this.wrapHeight -= this.$utils.rpx2px(100);
// #endif // #endif
// this.switchCate(5);
}, },
destroyed() {}, destroyed() {},
methods: { methods: {
@ -247,6 +250,11 @@ export default {
this.$emit("clickItem", id); this.$emit("clickItem", id);
}, },
}, },
watch: {
activeId(activeId) {
this.switchCate(activeId);
},
},
}; };
</script> </script>

View File

@ -49,7 +49,7 @@ export default {
config: (state) => state.system.config, config: (state) => state.system.config,
}), }),
}, },
onLoad() { async onLoad() {
let x = this.config.windowWidth - this.$utils.rpx2px(94); let x = this.config.windowWidth - this.$utils.rpx2px(94);
let y = this.config.windowHeight - this.$utils.rpx2px(94); let y = this.config.windowHeight - this.$utils.rpx2px(94);
// H5tabBar // H5tabBar
@ -61,7 +61,7 @@ export default {
y: y - this.$utils.rpx2px(40), y: y - this.$utils.rpx2px(40),
}; };
// //
this.loadHot(); await this.loadHot();
this.loadCate(); this.loadCate();
}, },
onShow() {}, onShow() {},
@ -72,8 +72,8 @@ export default {
/** /**
* 热门推荐 * 热门推荐
*/ */
loadHot() { async loadHot() {
this.$request({ await this.$request({
api: "service.hotCate", api: "service.hotCate",
}).then((response) => { }).then((response) => {
let child = []; let child = [];
@ -95,8 +95,8 @@ export default {
/** /**
* 分类 * 分类
*/ */
loadCate() { async loadCate() {
this.$request({ await this.$request({
api: "service.cate", api: "service.cate",
}) })
.then((response) => { .then((response) => {

View File

@ -1,7 +1,7 @@
<template> <template>
<app-layout minHeight="unset" btnType="back" title="服务列表" headerBackgroundColor="#FFFFFF" backgroundColor="#FFFFFF"> <app-layout minHeight="unset" btnType="back" title="服务列表" headerBackgroundColor="#FFFFFF" backgroundColor="#FFFFFF">
<view class="cate"> <view class="cate">
<app-cate :offsetHeight="0" :data="data" cateType="list" @clickItem="clickItem" /> <app-cate :offsetHeight="0" :data="data" cateType="list" @clickItem="clickItem" :activeId="currentId" />
</view> </view>
<view class="common-bottom-components" :style="{ bottom: config.safeAreaInsets.bottom + 'px' }"> <view class="common-bottom-components" :style="{ bottom: config.safeAreaInsets.bottom + 'px' }">
<view class="cart" @click="utils.toPage('/pages/service/cart')"> <view class="cart" @click="utils.toPage('/pages/service/cart')">
@ -28,9 +28,10 @@ export default {
data() { data() {
return { return {
utils: this.$utils, utils: this.$utils,
cateId: 0,
data: [], data: [],
bottom: 0, bottom: 0,
currentId: 0,
}; };
}, },
components: { components: {
@ -42,14 +43,14 @@ export default {
config: (state) => state.system.config, config: (state) => state.system.config,
}), }),
}, },
onLoad(e) { async onLoad(e) {
if (e.id) { if (!e.id) {
this.cateId = e.id;
} else {
this.$utils.toast("参数错误"); this.$utils.toast("参数错误");
return; return;
} }
this.loadList(); await this.loadList(e.id);
// watch
this.currentId = e.id;
}, },
onShow() {}, onShow() {},
onReady() {}, onReady() {},
@ -59,10 +60,10 @@ export default {
/** /**
* 加载列表 * 加载列表
*/ */
loadList() { async loadList(cateId) {
this.$request({ await this.$request({
api: "service.list", api: "service.list",
query: "id=" + this.cateId, query: "id=" + cateId,
}) })
.then((response) => { .then((response) => {
response.data.forEach((item) => { response.data.forEach((item) => {