<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="/static/在线报修/房屋.png" style="width: 60rpx;height: 60rpx;"></image>
        <view class="house-name">
			{{ item.community }}
		<view class="house-detail">{{ item.address }}</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 { uniShowToast, uniNavigateBack } from '@dcloudio/uni-app'

// 房屋列表数据
const houseList = ref([
  { id: 1, community: '桂花园（别墅）', address: '2号楼2幢' },
  { id: 2, community: '安泰翡翠城', address: '11号楼5单元1801' },
  { id: 3, community: '碧桂园新城·时代之光', address: '3号楼' }
])

// 选中的房屋
const selectedHouse = ref(houseList.value[0]) // 默认选中第一个

// 选择房屋
const selectHouse = (item) => {
  selectedHouse.value = item
}

// 确认选择并返回
const confirmSelect = () => {
  if (!selectedHouse.value) {
    uni.showToast({ title: '请选择房屋', icon: 'none' })
    return
  }
  
  // 把选中的房屋信息传给表单页（通过uni.$emit）
  uni.$emit('selectHouse', {
    name: `${selectedHouse.value.community} ${selectedHouse.value.address}`
  })
  
  // 返回上一页
  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: #fff;
}
.house-list {
  flex: 1;
}
.house-item {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: 15px 10px;
  border: 1px solid #eee;
  border-radius: 8px;
  margin-bottom: 10px;
}
.house-item.active {
  border-color: #007aff;
  background: #f0f8ff;
}
.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: 16px;
  margin-top: 20px;
}
</style>