mirror of
https://github.com/Dichgrem/Vue.git
synced 2026-02-05 10:31:57 -05:00
fix:loveacts_select
This commit is contained in:
@@ -12,13 +12,12 @@
|
||||
|
||||
<div class="body">
|
||||
<van-list
|
||||
v-model:loading="loading"
|
||||
:finished="finished"
|
||||
:loading="loading"
|
||||
:finished="true"
|
||||
finished-text="没有更多了"
|
||||
@load="onLoad"
|
||||
>
|
||||
<ActItem
|
||||
v-for="item in actList"
|
||||
v-for="item in filteredActList"
|
||||
:key="item.id"
|
||||
:data="item"
|
||||
@goDetails="goDetails"
|
||||
@@ -40,48 +39,42 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
actList: [],
|
||||
allActList: [], // 用于存储所有活动数据
|
||||
loading: false,
|
||||
finished: false,
|
||||
currentPage: 1,
|
||||
keyword: "",
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
// 创建一个计算属性来根据关键字筛选活动列表
|
||||
filteredActList() {
|
||||
if (!this.keyword.trim()) {
|
||||
return this.allActList; // 如果关键字为空,返回所有活动
|
||||
}
|
||||
const searchTerm = this.keyword.trim().toLowerCase();
|
||||
return this.allActList.filter(item => {
|
||||
const title = (item.title || '').toLowerCase();
|
||||
// 注意:模拟数据中的字段是 'palce' 而不是 'place'
|
||||
const place = (item.palce || '').toLowerCase();
|
||||
return title.includes(searchTerm) || place.includes(searchTerm);
|
||||
});
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
fetchActList(currentPage = 1) {
|
||||
const that = this;
|
||||
const payload = {
|
||||
currentPage,
|
||||
pageSize: 10,
|
||||
keyword: this.keyword,
|
||||
};
|
||||
|
||||
// 获取完整的活动列表
|
||||
fetchActList() {
|
||||
this.loading = true;
|
||||
axios
|
||||
.get("/api/actList", { params: payload })
|
||||
.then(function (response) {
|
||||
.get("/api/actList")
|
||||
.then(response => {
|
||||
const { error, data = {} } = response.data;
|
||||
if (error === 0) {
|
||||
const currentPage = data.current;
|
||||
const list = data.list;
|
||||
|
||||
if (currentPage === 1) {
|
||||
that.actList = list;
|
||||
} else {
|
||||
that.actList.push(...list);
|
||||
}
|
||||
|
||||
that.currentPage = currentPage;
|
||||
that.finished = data.pageCount === currentPage;
|
||||
this.allActList = data.list || [];
|
||||
}
|
||||
})
|
||||
.finally(function () {
|
||||
that.loading = false;
|
||||
.finally(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
onLoad() {
|
||||
this.fetchActList(this.currentPage + 1);
|
||||
},
|
||||
goMyApply() {
|
||||
this.$router.push("/myApply");
|
||||
},
|
||||
@@ -89,14 +82,9 @@ export default {
|
||||
this.$router.push("/actDetails?id=" + id);
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
keyword() {
|
||||
this.currentPage = 1;
|
||||
this.fetchActList(1);
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.fetchActList(1);
|
||||
// 组件加载时获取所有数据
|
||||
this.fetchActList();
|
||||
},
|
||||
};
|
||||
</script>
|
||||
@@ -137,4 +125,4 @@ export default {
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
|
||||
cursor: pointer;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
Reference in New Issue
Block a user