Files
property-resident-side/property-uniapp-project/pageSubPack/my/selectBuilding.vue
wangyuxin fb08057489 分包
2026-04-21 17:24:52 +08:00

498 lines
9.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="contentStyle" style="">
<view class="status-bar"></view>
<uni-nav-bar :title="'选择'+checkType" left-icon="left" @clickLeft="goBackAdd" backgroundColor="transparent"
:border="false">
</uni-nav-bar>
<scroll-view class="page" scroll-y>
<!-- 楼栋网格列表 -->
<view class="building-grid">
<view v-if="dataList.length === 0" class="empty-state">
<uni-icons type="info" size="60" color="#ccc"></uni-icons>
<text class="empty-text">
{{ '暂无数据'}}
</text>
</view>
<view class="building-item"
:class="{ active:(checkType=='楼栋'&& selectedBuilding === item.id)||(checkType=='单元'&& selectedUnit === item.id)||(checkType=='楼层'&&selectedFloor === item.id) ||(checkType=='户号'&&selectedHouseNumber === item.id) }"
v-for="(item, index) in dataList" :key="index" @click="selectBuilding(item)">
<text class="building-text">{{ item.name }}</text>
</view>
</view>
</scroll-view>
</view>
</template>
<script>
export default {
onReady: function(e) {},
components: {
},
computed: {
},
created() {
},
onShow() {
},
onUnload() {},
mounted() {
if (this.checkType == '楼栋') {
this.dataList = this.buildingList
} else if (this.checkType == '单元') {
this.dataList = this.unitList
} else if (this.checkType == '楼层') {
this.dataList = this.floorList
} else if (this.checkType == '户号') {
this.dataList = this.houseNumberList
}
},
data() {
return {
/* 设定状态栏默认高度 */
statusBarHeight: 20,
checkType: uni.getStorageSync('checkType'),
dataList: [],
// 楼栋列表(可动态生成/接口返回)
buildingList: [{
id: 1,
name: '01栋'
},
{
id: 2,
name: '02栋'
},
{
id: 3,
name: '03栋'
},
{
id: 4,
name: '04栋'
},
{
id: 5,
name: '05栋'
},
{
id: 6,
name: '06栋'
},
{
id: 7,
name: '07栋'
},
{
id: 8,
name: '08栋'
},
{
id: 9,
name: '09栋'
},
{
id: 10,
name: '10栋'
},
{
id: 11,
name: '11栋'
},
{
id: 12,
name: '12栋'
}
],
floorList: [{
id: 13,
name: '01层'
},
{
id: 14,
name: '02层'
},
{
id: 15,
name: '03层'
},
{
id: 16,
name: '04层'
}, {
id: 17,
name: '05层'
},
{
id: 18,
name: '06层'
},
{
id: 19,
name: '07层'
},
{
id: 20,
name: '08层'
}, {
id: 21,
name: '09层'
},
{
id: 22,
name: '10层'
},
{
id: 23,
name: '11层'
},
{
id: 24,
name: '12层'
}, {
id: 25,
name: '13层'
},
{
id: 26,
name: '14层'
},
{
id: 27,
name: '15层'
},
{
id: 28,
name: '16层'
},
{
id: 29,
name: '17层'
},
{
id: 30,
name: '18层'
},
{
id: 31,
name: '19层'
},
{
id: 32,
name: '20层'
},
],
unitList: [{
id: 33,
name: '01单元'
},
{
id: 34,
name: '02单元'
},
{
id: 35,
name: '03单元'
},
{
id: 36,
name: '04单元'
},
],
houseNumberList: [{
id: 37,
name: '01'
},
{
id: 38,
name: '02'
},
{
id: 39,
name: '03'
},
{
id: 40,
name: '04'
},
],
// 选中的楼栋
selectedBuilding: uni.getStorageSync('buildingId'),
// 选中的单元
selectedUnit: uni.getStorageSync('unitId'),
// 选中的楼层
selectedFloor: uni.getStorageSync('floorId'),
// 选中的户号
selectedHouseNumber: uni.getStorageSync('houseNumberId'),
}
},
methods: {
selectBuilding(item) {
let modalContent = '确认选择此' + this.checkType + '吗?'
uni.showModal({
title: "确认选择",
content: modalContent,
success: (res) => {
if (res.confirm) {
uni.showLoading({
title: '选择中...',
mask: true
});
if (this.checkType == '楼栋') {
this.selectedBuilding = item.id
uni.setStorageSync('buildingId', item.id);
uni.setStorageSync('buildingName', item.name);
uni.removeStorageSync('unitId');
uni.removeStorageSync('unitName');
uni.removeStorageSync('floorId');
uni.removeStorageSync('floorName');
uni.removeStorageSync('houseNumberId');
uni.removeStorageSync('houseNumberName');
uni.setStorageSync('checkType', '单元');
} else if (this.checkType == '单元') {
this.selectedUnit = item.id
uni.setStorageSync('unitId', item.id);
uni.setStorageSync('unitName', item.name);
uni.removeStorageSync('floorId');
uni.removeStorageSync('floorName');
uni.removeStorageSync('houseNumberId');
uni.removeStorageSync('houseNumberName');
uni.setStorageSync('checkType', '楼层');
} else if (this.checkType == '楼层') {
this.selectedFloor = item.id
uni.setStorageSync('floorId', item.id);
uni.setStorageSync('floorName', item.name);
uni.removeStorageSync('houseNumberId');
uni.removeStorageSync('houseNumberName');
uni.setStorageSync('checkType', '户号');
} else if (this.checkType == '户号') {
this.selectedHouseNumber = item.id
uni.setStorageSync('houseNumberId', item.id);
uni.setStorageSync('houseNumberName', item.name);
}
setTimeout(() => {
uni.showToast({
title: '选择成功',
icon: 'success'
});
}, 500);
setTimeout(() => {
// 提交成功后跳转列表页
uni.hideLoading();
this.goFreash();
}, 2000);
}
},
});
},
goFreash() {
console.log(this.checkType, '刷新页面');
if (this.checkType != '户号') {
uni.redirectTo({
url: '/pageSubPack/my/selectBuilding',
success: res => {},
fail: () => {},
complete: () => {}
});
} else {
uni.redirectTo({
url: '/pageSubPack/my/addHouse',
success: res => {},
fail: () => {},
complete: () => {}
});
}
},
goBackAdd() {
if (this.checkType == '楼栋') {
uni.removeStorageSync('buildingId');
uni.removeStorageSync('buildingName');
} else if (this.checkType == '单元') {
uni.removeStorageSync('unitId');
uni.removeStorageSync('unitName');
} else if (this.checkType == '楼层') {
uni.removeStorageSync('floorId');
uni.removeStorageSync('floorName');
} else if (this.checkType == '户号') {
uni.removeStorageSync('houseNumberId');
uni.removeStorageSync('houseNumberName');
}
uni.redirectTo({
url: '/pageSubPack/my/addHouse',
success: res => {},
fail: () => {},
complete: () => {}
});
},
},
}
</script>
<style lang="scss">
page {
background: linear-gradient(to left bottom, #e2efff 0%, #f9f9f9 50%);
overflow: hidden;
height: 100vh;
}
</style>
<style scoped>
.contentStyle {
display: flex;
flex-direction: column;
height: 100vh;
/* 关键:占满屏幕高度 */
/* background-color: #fff; */
}
.page {
flex: 1;
overflow-y: auto;
padding: 0px 40rpx;
box-sizing: border-box;
}
/* 底部按钮 */
.bottom-btn {
padding: 20rpx 30rpx 40rpx;
}
/* 网格布局3列 */
.building-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 30rpx;
}
/* 空状态 */
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 100rpx 0;
color: #ccc;
}
.empty-text {
font-size: 32rpx;
color: #999;
margin-top: 20rpx;
margin-bottom: 10rpx;
}
/* 楼栋按钮 */
.building-item {
height: 100rpx;
display: flex;
align-items: center;
justify-content: center;
background-color: #f9f9f9;
/* border: 1rpx solid #e5e5e5; */
border-radius: 20rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
transition: all 0.2s ease;
}
/* 选中状态 */
.building-item.active {
background-color: #2F77FD;
/* border-color: #1677ff; */
}
.building-item.active .building-text {
color: #fff;
}
/* 楼栋文字 */
.building-text {
font-size: 32rpx;
color: #333;
font-weight: 500;
}
/* 成功提示弹窗 */
.toast-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
background-color: transparent;
z-index: 9999;
}
.toast-content {
background-color: rgba(0, 0, 0, 0.8);
padding: 40rpx 60rpx;
border-radius: 8rpx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.toast-icon {
width: 60rpx;
height: 60rpx;
line-height: 60rpx;
border-radius: 50%;
background-color: #fff;
color: #1677ff;
font-size: 40rpx;
font-weight: bold;
margin-bottom: 20rpx;
display: flex;
align-items: center;
justify-content: center;
}
.toast-text {
color: #fff;
font-size: 28rpx;
}
.status-bar {
width: 100vw;
height: 46px;
}
</style>