131 lines
3.3 KiB
Vue
Raw Normal View History

<template>
<div>
<common current-name="supplier">
<template #main>
<banner name="supplier" :imglist="bannerList"></banner>
<filtertop :list="treeList" @select="selected"></filtertop>
<div class="goods-list-warp">
<div class="goods-list">
<template v-for="(n, index) in list" :key="n.id">
<div class="goods-item">
<goodsItem :data="n"></goodsItem>
</div>
</template>
</div>
<el-pagination
:current-page="pagination.current"
:page-sizes="[10, 20, 50, 100]"
:page-size="pagination.size"
layout="total, sizes, prev, pager, next, jumper"
:total="pagination.total"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
>
</el-pagination>
</div>
</template>
</common>
</div>
</template>
<script setup name="ecommerce">
import common from './components/common.vue';
import banner from './components/banner.vue';
import filtertop from './components/filtertop.vue';
import goodsItem from './components/goodsItem.vue';
import { ref, reactive, onMounted, watch, computed } from 'vue';
import { agriculturalList, transaction } from '@/apis/agricultural.js';
let treeList = reactive([]);
let list = reactive([]);
let params = reactive({
current: 1,
size: 10,
parentId: null,
childrenId: null,
});
let pagination = reactive({
current: 1,
size: 10,
total: 0,
});
let bannerList = reactive(['images/ecommerce/' + 'banner1.png', 'images/ecommerce/' + 'banner1.png']);
const getList = () => {
params.current = pagination.current;
params.size = pagination.size;
agriculturalList(params).then((res) => {
if (res.code === 200) {
list.splice(0, list.length, ...res.data.records);
pagination.total = res.data.total;
}
});
};
onMounted(() => {
getList();
getTree();
});
const handleSizeChange = (val) => {
pagination.size = val;
getList();
};
const handleCurrentChange = (val) => {
pagination.current = val;
getList();
};
const getTree = () => {
transaction().then((res) => {
if (res.code === 200) {
let a = res.data.sort((a, b) => Number(b.id) - Number(a.id));
treeList.splice(0, treeList.length, ...a);
// console.log('treeList', treeList);
}
});
};
const selected = (data) => {
// 获取所有值并转为数组
const val = Object.values(data);
console.log(data);
if (val.length === 1) {
params.parentId = val[0].id;
} else {
if (val[0].id === '') {
params.childrenId = '';
params.parentId = null;
} else {
params.childrenId = val[val.length - 1].id;
params.parentId = val[val.length - 1].parentId;
}
}
getList();
};
</script>
<style lang="scss" scoped>
.goods-list-warp {
margin-top: 16px;
2025-05-20 13:05:37 +08:00
width: 100%;
.goods-list {
display: inline-flex;
justify-content: space-around;
2025-05-20 13:05:37 +08:00
width: 100%;
flex-wrap: wrap;
gap: 10px;
.goods-item {
display: inline-block;
overflow: hidden;
margin-bottom: 16px;
2025-05-20 13:05:37 +08:00
width: calc((100% - 50px) / 5);
border-radius: 16px;
background: $color-fff;
}
}
2025-05-20 13:05:37 +08:00
/* 添加伪元素占位 */
.goods-list::after {
content: '';
flex: auto;
}
}
</style>