feat: 实现政策列表的级联筛选功能,支持政策类型和二级分类的动态联动。

This commit is contained in:
2026-03-11 11:00:41 +08:00
parent a676deedc1
commit cefa9b7614
2 changed files with 128 additions and 2 deletions

View File

@@ -32,6 +32,7 @@
class="popupList"
v-for="(item, index) in newCkeckData"
:key="index"
v-show="!item.hidden"
>
<view class="tabTitle">
{{ item.name }}

View File

@@ -22,6 +22,23 @@
@click="search()"
/>
</view>
<view
class="inner"
:style="{
width: 'calc(100% + 64rpx)',
marginLeft: '-32rpx',
height: zctopShow ? 'auto' : '122rpx',
position: 'relative',
zIndex: zctopShow ? 100 : 2,
}"
>
<PopupList
:checkData="checkData"
@searchCheck="search"
ref="PopupList"
@popupSearch="popupSearch"
/>
</view>
<view
v-if="total"
style="position: relative; padding: 32rpx 0; color: #000"
@@ -32,7 +49,7 @@
<!-- <scroll-view :scroll-y="true" style="height: calc(100vh - 342rpx);position: relative;z-index: 1;" -->
<scroll-view
:scroll-y="true"
style="height: calc(100vh - 232rpx); position: relative; z-index: 1"
style="height: calc(100vh - 354rpx); position: relative; z-index: 1"
@scrolltolower="getBottomList"
:show-scrollbar="false"
>
@@ -92,6 +109,7 @@
<script>
import PopupList from "/packageRc/components/PopupLists.vue";
import { getPolicyList } from "@/packageRc/apiRc/policy";
import { getDicts } from "@/packageRc/apiRc/system/dict";
export default {
components: {
PopupList,
@@ -106,15 +124,122 @@ export default {
showMorePage: true,
tableData: [],
loading: false,
checkData: [],
zctopShow: false,
policyTypeMList: [],
};
},
onLoad(options) {
this.queryParams.zclx = options.zclx;
this.getCheckData();
},
onShow() {
this.search();
},
watch: {
"checkData": {
handler(newVal) {
if (!newVal || newVal.length < 3 || !this.policyTypeMList.length) return;
const typeL = newVal[0].data[newVal[0].activeIndex].dictValue;
// 政策类型不选时,不显示二级分类
const isHidden = !typeL;
if (newVal[1].hidden !== isHidden) {
this.$set(newVal[1], "hidden", isHidden);
}
// 政策类型不选时确保二级分类已选索引重置为0全部
if (isHidden && newVal[1].activeIndex !== 0) {
this.$set(newVal[1], "activeIndex", 0);
}
let filtered = [];
if (typeL) {
filtered = this.policyTypeMList.filter((item) =>
item.dictValue.startsWith(typeL)
);
} else {
filtered = this.policyTypeMList;
}
// Only update if data changed to avoid infinite loop
const newData = [{ dictLabel: "全部", dictValue: "" }].concat(filtered);
if (JSON.stringify(newVal[1].data) !== JSON.stringify(newData)) {
this.$set(newVal[1], "data", newData);
this.$set(newVal[1], "activeIndex", 0);
}
},
deep: true,
},
},
methods: {
async getCheckData() {
const resLevel = await getDicts("zc_level");
const resType1 = await getDicts("policy_type1");
const resType2 = await getDicts("policy_type2");
this.policyTypeMList = resType2.data;
const type1Data = [{ dictLabel: "全部", dictValue: "" }].concat(
resType1.data || []
);
// policyTypeL 与 zclx 不相关,不再使用 zclx 初始化
const initialTypeLIndex = type1Data.findIndex(
(item) => item.dictValue == this.queryParams.policyTypeL
);
this.checkData = [
{
name: "政策类型",
type: "policyTypeL",
data: type1Data,
activeIndex: initialTypeLIndex > -1 ? initialTypeLIndex : 0,
},
{
name: "二级分类",
type: "policyTypeM",
data: [{ dictLabel: "全部", dictValue: "" }].concat(resType2.data || []),
activeIndex: 0,
hidden: true,
},
{
name: "政策级别",
type: "zcLevel",
data: [{ dictLabel: "全部", dictValue: "" }].concat(resLevel.data || []),
activeIndex: 0,
},
];
},
popupSearch(data) {
// 获取此次提交前,旧的政策类型值
const oldTypeL = this.queryParams.policyTypeL || "";
// 获取弹窗提交的实时选值
const selections = {};
data.forEach((item) => {
const active = item.data[item.activeIndex];
selections[item.type] = active.dictLabel === "全部" ? "" : active.dictValue;
});
// 核心判定逻辑:
// 如果发现“政策类型(policyTypeL)”发生了变化
if (selections.policyTypeL !== oldTypeL) {
// 如果改变成了具体的分类,且二级分类传过来的不是该分类下的子类(说明是残留选项没来得及重置)
// 或者是变回了“全部”
// 那么必须强制清空二级分类
if (!selections.policyTypeL || (selections.policyTypeM && !selections.policyTypeM.startsWith(selections.policyTypeL))) {
selections.policyTypeM = "";
const typeMItem = data.find((it) => it.type === "policyTypeM");
if (typeMItem) typeMItem.activeIndex = 0;
}
}
// 将最终确定的值同步到查询参数中
Object.keys(selections).forEach((key) => {
this.$set(this.queryParams, key, selections[key]);
});
this.search();
},
goPolicyDetail(item) {
uni.navigateTo({
url: `/packageRc/pages/policy/policyDetail?id=${item.id}`,
@@ -208,7 +333,7 @@ export default {
display: flex;
align-items: center;
position: relative;
z-index: 1;
z-index: 110;
margin-top: 24rpx;
.search-icon {