Files
kangyuan-mobile/components/goods/goods2.vue
T
2026-05-26 15:52:30 +08:00

116 lines
2.8 KiB
Vue

<template>
<view>
<view class="navs flex-center ju-flex-start">
<view
class="navItem flex-center flex-column"
:class="{ tabIndex: i == tabIndex }"
v-for="(v, i) in props.list"
@click="navChange(i)"
>
<view class="navText">
{{ v.name }}
</view>
<image src="/static/index/active.png" mode="scaleToFill" />
</view>
</view>
<mescroll-body
:down="downOption"
@init="mescrollInit"
top="0"
@down="downCallback"
:up="upOption"
@up="upCallback"
@emptyclick="emptyClick"
:height="10"
>
<goods-item :goods="goods" v-if="goods.length > 0"></goods-item>
</mescroll-body>
</view>
</template>
<script setup>
import { ref } from 'vue';
import useMescroll from '@/uni_modules/mescroll-uni/hooks/useMescroll.js';
import SpuApi from '@/sheep/api/product/spu';
import goodsItem from '../goodsItem/goodsItem2.vue';
let props = defineProps({
list: {
type: Array,
default: () => [],
},
});
let tabIndex = ref(0);
let goods = ref([]);
const { mescrollInit, downCallback, getMescroll } = useMescroll(); // 调用mescroll的hook
defineExpose({ getMescroll }); // 使父组件可以通过ref调用到getMescroll方法 (必须)
const downOption = {
use: false, // 是否启用下拉刷新; 默认true
};
const upOption = {
noMoreSize: 4,
empty:{
tip: '~ 搜索无数据 ~', // 提示
}
};
const upCallback = (mescroll) => {
SpuApi.getSpuPage({
pageNo: mescroll.num,
pageSize: mescroll.size,
tagTypeId: props.list[tabIndex.value].id,
})
.then((res) => {
const list = res.data.list || []; // 当前页数据
if (mescroll.num == 1) goods.value = []; //如果是第一页需手动制空列表
goods.value = goods.value.concat(list); //追加新数据
mescroll.endSuccess(list.length); // 请求成功, 结束加载
})
.catch(() => {
mescroll.endErr(); // 请求失败, 结束加载
});
mescroll.endErr(); // 请求失败, 结束加载
};
//点击空布局按钮的回调
const emptyClick = () => {
uni.showToast({
title: '点击了按钮,具体逻辑自行实现',
});
};
// let tabIndex = ref(0);
const navChange = (i) => {
// scrollToLastY()
goods.value = [];
tabIndex.value = i;
const m = getMescroll();
m.setPageNum(1);
m.resetUpScroll(false);
};
</script>
<style lang="scss" scoped>
.navs {
.navItem {
color: #777777;
font-size: 24rpx;
width: 20%;
// text-align: center;
image {
width: 40rpx;
height: 12rpx;
opacity: 0;
margin-top: 12rpx;
}
}
.tabIndex {
color: #333333;
font-size: 32rpx;
font-weight: 500;
image {
opacity: 1;
}
}
}
</style>