<template>
	<view class="center plr-25">

		<view class="flex-column br-12 fs-28 mt-30" style="background: #FFFFFF;">
			<text class="fs-32 fw-700 pad-30" style="text-align: left;">基本信息</text>
			<view class="flex-row-between pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
				<text>姓名</text>
				<text>{{$wskj.isNullStr(userInfo.name)}}</text>
			</view>
			<view class="flex-row-between pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
				<text>手机号</text>
				<text>{{userInfo.mobile}}</text>
			</view>
			<view class="flex-row-between pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
				<text>身份证号</text>
				<text>{{$wskj.isNullStr(userInfo.identityCard)}}</text>
			</view>
		</view>
		<view class="overflow-y">
			<scroll-view scroll-y style="height: 100%;">
				<view @click="onClickSelecte(index)" v-for="(item, index) in houseList" :key="index">
					<view class="flex-column br-12 fs-28 mt-30" style="background: #FFFFFF;">
						<view class="fs-32 fw-700 pad-30 flex-row-between">
							<text>房屋信息</text>
							<image v-if="selecteIndex==index" class="w-45 h-45" src="/pagesMine/static/icon_fwxx_2.png">
							</image>
							<image v-else class="w-45 h-45" src="/pagesMine/static/icon_fwxx_1.png"></image>
						</view>
						<view class="flex-row-between pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
							<text>小区</text>
							<text>{{item.communityName}}</text>
						</view>
						<view class="flex-row-between pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
							<text>具体位置</text>
							<text>{{item.room}}</text>
						</view>
						<view class="flex-row-between pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
							<text>业主姓名</text>
							<text>{{item.name}}</text>
						</view>
						<view class="flex-row-between pad-30" style="border-bottom: 1rpx solid #E9E9E9;">
							<text>业主手机号</text>
							<text>{{item.phone}}</text>
						</view>
					</view>
				</view>

			</scroll-view>
		</view>
		<view class="h-140 pt-20">
			<view class="fullscreen-btn" @click="onSubmit()">
				确定
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				selecteIndex: -1,
				userInfo: '',
				houseList: [],

			};
		},
		onLoad(options) {
			if (options.type == 1) {
				uni.setNavigationBarTitle({
					title: '选择房屋信息'
				})
			} else {
				uni.setNavigationBarTitle({
					title: '房屋信息'
				})
			}
			this.userInfo = uni.getStorageSync('userInfo')
			this.getHouseList()
		},
		methods: {
			onClickSelecte(index) {
				this.selecteIndex = index
			},
			onSubmit() {
				if (this.selecteIndex == -1) {
					this.$wskj.goBack(1)
					return
				}
				this.setHouse()
			},
			getHouseList() {
				const than = this;
				const params = {
					url: '/api/community/myRoomListAll',
					method: 'GET',
				}
				than.$request(params).then(res => {
					than.houseList = res.data
					than.houseList.forEach(function(item, index) {
						if (item.room == than.userInfo.room) {
							than.selecteIndex = index
						}
					});
				})
			},
			setHouse() {
				const params = {
					url: '/api/community/cut/' + this.houseList[this.selecteIndex].communityId + "/" + this.houseList[
						this.selecteIndex].proprietorId,
				}
				this.$request(params).then(res => {
					uni.setStorageSync('fwInfo', res.data)
					this.$wskj.toast("设置成功")
					setTimeout(() => {
						this.$wskj.goBack(1)
					}, 600)
				})
			},
		}
	};
</script>

<style>
	.center {
		height: 100vh;
		display: flex;
		flex-direction: column;
		background: #F2F2F2;
	}

	.item {
		width: 100%;
		height: 200rpx;
		margin-top: 20rpx;
	}

	.item2 {
		width: 100%;
		height: 150rpx;
		margin-top: 20rpx;
	}
</style>