Files
property-resident-side/property-uniapp-project/pageSubPack/online-repair/selectHouse.vue
2026-04-29 17:39:55 +08:00

149 lines
3.4 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="house-container">
<!-- 房屋列表 -->
<view class="house-list">
<view
class="house-item"
:class="{ active: selectedHouse.id === item.id }"
@click="selectHouse(item)"
v-for="item in houseList"
:key="item.id"
>
<image src="http://47.104.199.163:9090/images/repair/house.png" style="width: 48rpx;height: 48rpx;"></image>
<view class="house-name">
{{ item.villageName }}
<view class="house-detail">{{ item.houseType }}</view>
</view>
<uni-icons type="checkbox-filled" size="20" color="#007aff" v-if="selectedHouse.id === item.id"></uni-icons>
</view>
</view>
<!-- 确认按钮 -->
<button class="confirm-btn" @click="confirmSelect">确认</button>
</view>
</template>
<script setup>
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { getHouseList } from '../api/api.js'
// 房屋列表数据
const houseList = ref([])
// 选中的房屋
const selectedHouse = ref({})
// 分页参数
const pageNum = ref(1)
const pageSize = ref(10)
// 预传入的房屋ID从表单页带过来
const preSelectedHouseId = ref('')
// 获取房屋列表
const fetchHouseList = async () => {
try {
const res = await getHouseList({ pageNum: pageNum.value, pageSize: pageSize.value })
if (res.code === 200) {
const list = res.rows || []
houseList.value = list
if (houseList.value.length > 0) {
if (preSelectedHouseId.value) {
const found = houseList.value.find(item => String(item.id) === String(preSelectedHouseId.value))
selectedHouse.value = found || houseList.value[0]
} else {
selectedHouse.value = houseList.value[0]
}
}
}
} catch (e) {
uni.showToast({ title: '获取房屋列表失败', icon: 'none' })
}
}
onLoad((options) => {
if (options.houseId) {
preSelectedHouseId.value = options.houseId
}
fetchHouseList()
})
// 选择房屋
const selectHouse = (item) => {
selectedHouse.value = item
}
// 确认选择并返回
const confirmSelect = () => {
if (!selectedHouse.value) {
uni.showToast({ title: '请选择房屋', icon: 'none' })
return
}
// 把选中的房屋信息传给表单页通过uni.$emit
uni.$emit('selectHouse', {
id: selectedHouse.value.id,
name: `${selectedHouse.value.villageName} ${selectedHouse.value.houseType}`
})
// 返回上一页
uni.navigateBack({ delta: 1 })
}
</script>
<style scoped>
.house-container {
padding: 15px;
height: 100vh;
box-sizing: border-box;
display: flex;
flex-direction: column;
justify-content: space-between;
background: #f9f9f9;
}
.house-list {
flex: 1;
}
.house-item {
display: flex;
justify-content: flex-start;
align-items: center;
padding: 15px 10px;
background-color: #fff;
border-radius: 8px;
margin-bottom: 10px;
}
.house-item.active {
border-color: #007aff;
background: #f0f8ff;
border: 1px solid #2F77FD;
}
.house-name {
font-size: 16px;
color: #333;
font-weight: 500;
display: flex;
flex-direction: column;
align-items: flex-start;
margin-left: 30rpx;
width: 80%;
}
.house-detail {
font-size: 12px;
color: #666;
margin-top: 4px;
}
.confirm-btn {
width: 100%;
height: 44px;
line-height: 44px;
background: #007aff;
color: #fff;
border-radius: 8px;
font-size: 28rpx;
margin-top: 20px;
margin-bottom: 20rpx;
}
</style>