优化,完善代码

This commit is contained in:
2026-05-14 14:42:51 +08:00
parent 79a21ff0a5
commit 16c91facac
26 changed files with 1792 additions and 1322 deletions

View File

@@ -1,7 +1,7 @@
<template>
<view class="u-margin-left-20 u-margin-right-20">
<u-navbar :is-back="true" title="搜索" :border-bottom="false"></u-navbar>
<u-search placeholder="请输入资产名称/位置等信息" v-model="keyword" @search="clickSearch(value)"
<u-search placeholder="请输入品牌名称/位置等信息" v-model="keyword" @search="clickSearch(value)"
:focus="true" action-text="取消" @custom="cancelSearch"></u-search>
<!-- 搜索记录 -->
<template v-if="historyList.length > 0">

View File

@@ -1,12 +1,9 @@
<template>
<view class="search-list-page">
<!-- 顶部导航栏 -->
<!-- <customNavbar title="搜索资产" /> -->
<u-navbar title="搜索资产" :autoBack="true" :background="background" title-color="#2D2B2C"
back-icon-color="#2D2B2C">
</u-navbar>
<view class="search-list-content">
<!-- 筛选标签栏 -->
<view class="filter-dropdown-wrapper">
<u-sticky offset-top="0">
<view class="sticky" style="width: 100vw;">
@@ -15,7 +12,6 @@
</view>
</u-sticky>
</view>
<!-- 搜索栏 -->
<view class="search-bar-wrapper">
<view class="search-bar">
<view class="city-select" @click="location()">{{ city ||'宜昌市'}} <text class="icon-down"></text>
@@ -26,7 +22,6 @@
</view>
</view>
</view>
<!-- 标签组 -->
<view class="tag-group">
<view class="tag-item" :class="{ active: selectedTags.includes(tag) }"
v-for="(tag, index) in tagGroupList" :key="index" @click="onTagClick(tag)">
@@ -39,32 +34,35 @@
<u-waterfall v-model="flowList" ref="uWaterfall">
<template v-slot:left="{ leftList }">
<view class="demo-warter" v-for="(item, index) in leftList" :key="index">
<u-lazy-load threshold="750" border-radius="8" :image="item.coverImgUrl" :index="index"
@click="clickImage(item.assetsNo)" mode="aspectFill"></u-lazy-load>
<view class="img-box" @click="clickImage(item.assetsNo)">
<img class="img" :src="item.coverImgUrl" alt="" />
</view>
<view class="item-title">{{ item.assetsName }}</view>
<view class="item-desc">{{ item.assetsType }} {{ item.footPrint }} {{ item.orientation ||'未知'}}
</view>
<view class="item-tags">
<view class="tag" v-for="(tag, tagIndex) in item.tags" :key="tagIndex">{{ tag }}</view>
</view>
<view class="item-price">¥{{ item.rentFee || '未知'}}/<text></text></view>
</view>
</template>
<template v-slot:right="{ rightList }">
<view class="demo-warter" v-for="(item, index) in rightList" :key="index">
<u-lazy-load threshold="750" border-radius="8" :image="item.coverImgUrl" :index="index"
@click="clickImage(item.assetsNo)" mode="aspectFill"></u-lazy-load>
<view class="img-box" @click="clickImage(item.assetsNo)">
<img class="img" :src="item.coverImgUrl" alt="" />
</view>
<view class="item-title">{{ item.assetsName }}</view>
<view class="item-desc">{{ item.assetsType}} {{ item.footPrint }} {{ item.orientation ||'未知'}}</view>
<view class="item-tags">
<view class="tag" v-for="(tag, tagIndex) in item.tags" :key="tagIndex">{{ tag }}</view>
</view>
<view class="item-price">¥{{ item.rentFee || '未知'}}/<text></text></view>
</view>
</template>
</u-waterfall>
<u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus" @loadmore="loadMore"
<!-- 修复状态 + 去掉自带loadmore -->
<u-loadmore bg-color="rgb(240, 240, 240)" :status="loadStatus"
style="height: 80rpx;line-height: 80rpx;"></u-loadmore>
<u-back-top :scroll-top="scrollTop" top="1000"></u-back-top>
<u-no-network></u-no-network>
</view>
@@ -72,8 +70,8 @@
</template>
<script>
import config from "@/common/config.js" // 全局配置文件
import searchData from '@/common/utils/searchData.js'; //筛选菜单数据
import config from "@/common/config.js"
import searchData from '@/common/utils/searchData.js';
import filterDropdown from '@/components/zy/filterDropdown.vue';
export default {
components: {
@@ -82,26 +80,22 @@
data() {
return {
city: null,
selectedBizZone: null,
selectedLayout: null,
selectedDecorationStatus: null,
selectedFeatures:[],
indexArr: [],
valueArr: [],
defaultSelected: [],
filterData: [],
searchData: {},
pageNum: 1,
pageNo: 1, // ✅ 统一页码
pageSize: 20,
scrollTop: 0,
houseList: [],
loadStatus: 'loadmore',
loadStatus: 'more', // ✅ 修复为正确状态
flowList: [],
// 标签组数据和选中状态
tagGroupList: ['全套家具', '配套齐全', '优选好房', '生活便利'],
imageModeMap: {},
defaultImgUrl: '/public/static/index/assets.jpg',
tagGroupList: [],
selectedTags: [],
background: {
// 渐变色
backgroundImage: 'linear-gradient(-90deg, #F9DED9 0%, #F8DFC0 99%);'
},
}
@@ -119,18 +113,21 @@
if (villageName) {
this.searchData.villageName = villageName
}
// 获取街道数据
this.findFilterTabData()
this.findHouseList(null,option.keyword)
},
onShow() {
},
onPageScroll(e) {
this.scrollTop = e.scrollTop;
},
// 下拉刷新
// ✅ 保留页面触底(瀑布流必须用这个)
onReachBottom() {
this.loadMore()
},
onPullDownRefresh() {
this.resetAndLoad();
// 关闭刷新
uni.stopPullDownRefresh();
},
computed: {
staticHost() {
@@ -138,20 +135,13 @@
}
},
methods: {
// 标签点击事件
onTagClick(tag) {
// 检查标签是否已选中
const isSelected = this.selectedTags.includes(tag);
if (isSelected) {
// 如果已选中,则移除
this.selectedTags = this.selectedTags.filter(item => item !== tag);
} else {
// 如果未选中,则添加
this.selectedTags.push(tag);
}
// 这里可以添加根据标签筛选数据的逻辑
console.log('标签点击:', tag);
console.log('当前选中的标签:', this.selectedTags);
this.resetAndLoad()
},
location() {
@@ -165,14 +155,15 @@
resetAndLoad() {
this.pageNo = 1;
this.flowList = [];
this.loadStatus = 'loadmore';
this.loadStatus = 'more'; // ✅ 修复
this.$nextTick(() => {
this.$refs.uWaterfall && this.$refs.uWaterfall.clear();
this.findHouseList();
});
},
findHouseList(type = null,keyWord = null) {
if (this.loadStatus !== 'loadmore') return;
findHouseList(type = null,keyword = null) {
// ✅ 正确判断
if (this.loadStatus !== 'more') return;
this.loadStatus = 'loading';
@@ -181,16 +172,20 @@
assetsType: type,
pageNo: this.pageNo,
pageSize: this.pageSize,
keyWord: this.keyWord,
bizZone: this.searchData.bizZone
keyWord: keyword,
bizZone: this.searchData.bizZone,
layout: this.searchData.layout,
renovationStatus: this.searchData.decoration,
features: this.searchData.feature
}).then(result => {
const rows = result.data.result || [];
// 第一页无数据
if (this.pageNo === 1 && rows.length === 0) {
this.flowList = [];
this.loadStatus = 'nomore';
return;
}
rows.forEach(row => {
if (row.coverImgUrl) {
row.coverImgUrl = this.$config.staticUrl + row.coverImgUrl
@@ -198,32 +193,29 @@
row.coverImgUrl = this.$config.staticUrl + this.defaultImgUrl
}
})
// 追加数据
this.flowList = this.flowList.concat(rows);
// 判断是否还有下一页(核心)
if (rows.length < this.pageSize) {
this.loadStatus = 'nomore';
} else {
this.pageNo++; // ✅ 只有这里能 +1
this.loadStatus = 'loadmore';
this.pageNo++;
this.loadStatus = 'more'; // ✅ 恢复
}
this.keyWord = null
}).catch(err => {
console.log("获取资产信息失败:", err);
this.loadStatus = 'loadmore';
this.loadStatus = 'more'; // ✅ 恢复
}).finally(() => {
uni.stopPullDownRefresh();
});
},
loadMore() {
// 只有在 loadStatus 为 'loadmore' 时才触发
if (this.loadStatus !== 'loadmore') return;
// 调用接口获取下一页
if (this.loadStatus !== 'more') return;
this.findHouseList();
},
async findFilterTabData() {
// 填充商圈数据到筛选菜单
const bizZones = await this.getBizZone();
const features = await this.getFeatures();
let featureSubMenu = [];
@@ -232,7 +224,6 @@
name: bizZones[i],
value: bizZones[i]
});
}
for (let i = 0; i < features.length; i++) {
featureSubMenu.push({
@@ -240,7 +231,7 @@
value: features[i]
})
}
searchData[2].submenu.push({
searchData[1].submenu.push({
name:"基础配套",
type:"radio-multi",
submenu: featureSubMenu
@@ -261,6 +252,18 @@
}
return [];
},
getImageSize(url, index) {
uni.getImageInfo({
src: url,
success: (res) => {
const { width, height } = res;
this.$set(this.imageModeMap, index, width >= height ? 'widthFix' : 'aspectFit');
},
fail: () => {
this.$set(this.imageModeMap, index, 'aspectFit');
}
});
},
clickImage(houseId) {
this.$u.route({
url: '/pages-assets/assets/assetsDetail',
@@ -269,11 +272,9 @@
}
})
},
//接收菜单结果
confirm(e) {
let bizZone = e.value[0][0]
let price = e.value[1][0]
let combo = e.value[2]
let combo = e.value[1]
let layout = combo[0]
let decoration = combo[1]
let feature = combo[2]
@@ -281,9 +282,6 @@
if (bizZone) {
this.searchData.bizZone = bizZone
}
if (price) {
this.searchData.price = price
}
if (layout && layout.length > 0) {
this.searchData.layout = layout.toString()
}
@@ -308,13 +306,11 @@
}
.search-list-content {
// padding-top: 20rpx;
background: linear-gradient(-90deg, #F9DED9 0%, #F8DFC0 99%);
border-radius: 0rpx;
padding-bottom: 20rpx;
}
// 搜索栏样式
.search-bar-wrapper {
padding: 10rpx 20rpx;
}
@@ -365,12 +361,9 @@
}
.filter-dropdown-wrapper {
// padding: 0 20rpx;
border-radius: 10rpx;
margin-bottom: 20rpx;
}
// 标签组样式
.tag-group {
padding: 15rpx 20rpx;
display: flex;
@@ -444,15 +437,8 @@
right: 20rpx;
}
// 图片样式
.u-lazy-load {
width: 100%;
height: 300rpx;
}
.item-cover {
font-size: 55rpx;
color: $u-type-warning;
}
.item-title {
@@ -485,7 +471,6 @@
padding: 0 15rpx 8rpx 15rpx;
}
// 标签样式
.item-tags {
display: flex;
flex-wrap: wrap;
@@ -506,4 +491,15 @@
color: $u-tips-color;
margin-top: 3px;
}
.img{
width: 100%;
height: 230rpx;
display: block;
}
.img-box {
border-radius: 10rpx;
width: 100%;
height: 230rpx;
overflow: hidden;
}
</style>