jsy-app/components/custom-select-land/custom-select-land.vue

161 lines
3.5 KiB
Vue
Raw Permalink Normal View History

2024-09-18 10:30:10 +08:00
<template>
<u-popup mode="left" :show="show" @close="close">
2024-09-26 12:42:59 +08:00
<u-collapse ref="refCollapse" :value="showIndex" @change="changeItem" @open="openItem" @close="closeItem"
2024-09-18 10:30:10 +08:00
accordion>
2024-09-26 12:42:59 +08:00
<u-collapse-item v-for="(item,i) in indexData.list" :name="i">
2024-09-18 10:30:10 +08:00
<template v-slot:icon>
<view class="iconfont icon-qiye icon"></view>
</template>
<template v-slot:title>
2024-09-25 18:47:15 +08:00
{{item.label}}
2024-09-18 10:30:10 +08:00
</template>
<template v-slot:right-icon>
2024-09-25 18:47:15 +08:00
<u-badge numberType="overflow" type="primary" max="999" :showZero="true"
:value="item.children.length" />
2024-09-18 10:30:10 +08:00
</template>
2024-09-26 12:42:59 +08:00
<view class="u-collapse-content" v-if="showId[item.id]">
2024-09-18 10:30:10 +08:00
<u-list>
<u-list-item v-for="item2 in item.children">
2024-09-26 12:42:59 +08:00
<u-cell @click="select(i,item2)">
2024-09-18 10:30:10 +08:00
<template v-slot:icon>
<view class="iconfont icon-ditu icon"></view>
</template>
<template v-slot:title>
2024-09-26 12:42:59 +08:00
<view :class="[item2.id == indexData.selectItem.id ? 'checked':'']">
{{item2.name}}
</view>
2024-09-18 10:30:10 +08:00
</template>
<template v-slot:right-icon>
2024-09-25 18:47:15 +08:00
<u-badge numberType="overflow" type="success" max="999" :showZero="true"
:value="item2.valueNum" />
2024-09-18 10:30:10 +08:00
</template>
</u-cell>
</u-list-item>
</u-list>
</view>
</u-collapse-item>
</u-collapse>
</u-popup>
</template>
<script>
2024-09-25 18:47:15 +08:00
import store from "@/store"
import {
deptTreeSelectByRole,
getManagerGroundList,
} from "@/api/index.js"
2024-09-18 10:30:10 +08:00
export default {
name: 'custom-select-land',
emits: ["select"],
2024-09-25 18:47:15 +08:00
props: {},
2024-09-18 10:30:10 +08:00
watch: {},
data() {
return {
2024-09-25 18:47:15 +08:00
user: store.state.user.user,
2024-09-18 10:30:10 +08:00
show: false,
2024-09-26 12:42:59 +08:00
showIndex: null,
showId: {},
indexData: getApp().indexData,
2024-09-18 10:30:10 +08:00
}
},
created() {
2024-09-26 12:42:59 +08:00
this.indexData.getList(this.user.userId);
if (this.indexData.selectItem) {
this.showId[this.indexData.selectItem.companyId] = true;
} else {
this.showId[this.indexData.list.id] = true;
}
2024-09-18 10:30:10 +08:00
},
methods: {
2024-09-26 12:42:59 +08:00
//打开弹窗
2024-09-18 10:30:10 +08:00
open() {
2024-09-26 12:42:59 +08:00
this.showIndex = this.indexData.showIndex;
if (this.indexData.list.length > 0) {
2024-09-18 10:30:10 +08:00
this.show = true;
} else {
2024-09-25 18:47:15 +08:00
this.$toast("无数据");
2024-09-18 10:30:10 +08:00
}
},
2024-09-26 12:42:59 +08:00
//关闭弹窗
2024-09-18 10:30:10 +08:00
close() {
2024-09-25 18:47:15 +08:00
this.show = false;
2024-09-18 10:30:10 +08:00
},
2024-09-26 12:42:59 +08:00
//选中数据
select(index, item) {
let oldItem = this.indexData.selectItem;
this.indexData.selectItem = item;
this.indexData.showIndex = index;
if (item.id != oldItem.id) {
2024-09-27 12:01:15 +08:00
/*
1.设置缓存
2.回调的方式通知改变
3.全局订阅的方式通知改变
4.组件回调的方式通知改变
*/
2024-09-26 12:42:59 +08:00
this.indexData.setStorage(2, item);
2024-09-27 12:01:15 +08:00
this.indexData.onEventHandler(this.indexData.eventType.land, item);
uni.$emit("notify-update-land", item);
2024-09-27 11:16:33 +08:00
this.$emit("select", item);
2024-09-26 12:42:59 +08:00
}
2024-09-18 10:30:10 +08:00
this.close();
},
2024-09-26 12:42:59 +08:00
//打开行变化
changeItem(e) {},
//打开行
2024-09-18 10:30:10 +08:00
openItem(e) {
2024-09-26 12:42:59 +08:00
this.showIndex = e;
this.showId[this.indexData.list[e].id] = true;
2024-09-18 10:30:10 +08:00
this.$nextTick(() => {
this.$refs.refCollapse.init();
})
},
2024-09-26 12:42:59 +08:00
closeItem(e) { //折叠行
this.showIndex = null;
2024-09-18 10:30:10 +08:00
}
}
}
</script>
<style lang="scss" scoped>
$list-height: 100px;
::v-deep.u-popup__content {
min-width: 240px;
.u-collapse {
height: 100vh;
overflow-y: auto;
}
.u-cell__right-icon-wrap--down,
.u-cell__right-icon-wrap--up {
transform: none;
}
.u-collapse-item__content__text {
padding: 0;
}
.u-cell__body__content {
.icon {
color: #3c9cff;
font-size: 44rpx;
}
}
.u-collapse-content {
font-size: 28rpx;
.icon {
color: #39ac4f;
}
}
2024-09-26 12:42:59 +08:00
.checked {
border-bottom: 2px solid #66ccff;
}
2024-09-18 10:30:10 +08:00
}
</style>