<template>
	<view class="selectBuilding">
		<view class="searchStyle">
			<u-search placeholder="输入楼盘名称" v-model="search" :show-action="false"></u-search>
		</view>
		<view class="searchResultStyle">
			<u-radio-group v-model="result" @change="radioGroupChange">
				<u-radio v-for="(item, index) in list" :key="index" :name="item.id+'-'+item.propertyName"  label-size="34">
					{{item.propertyName}}
				</u-radio>
			</u-radio-group>
		</view>
	</view>

</template>

<script>
	var config = require("@/config");
	export default {
		name: "selectBuilding",
		data() {
			return {
				search: "",
				list: [],
				result: ""
			};
		},
		watch:{
			search(newState){
				this.init(newState)
			}
		},
		methods:{
			radioGroupChange(e){
				console.log()
				let lopan = {
					id: e.split('-')[0],
					name: e.split('-')[1]
				}
				uni.setStorageSync("buildingID", lopan);
				uni.navigateBack({
					delta:-1
				})
			},
			init(e){
				let data = {houseName:decodeURI(e)||''}
				uni.request({
					url: config.service.getUser,
					method: "GET",
					data,
					header: {
						'content-type': 'application/json',
						'Authorization': 'Bearer ' + uni.getStorageSync('weapp_session_login_data').token
					},
					success: (res) => {
						this.list = res.data.data.houseList
					}
				})
			}
		},
		onLoad() {
			this.init("")
		}
	}
</script>

<style lang="scss" scoped>
	.selectBuilding {
		background: #dedede;

		.searchStyle {
			padding: 20rpx;
		}

		.searchResultStyle {
			/deep/ .u-radio-group {
				display: flex;
				flex-direction: column;
			}

			/deep/ .u-radio {
				display: flex;
				flex-direction: row-reverse;
				width: 100% !important;
				justify-content: space-between;
				background: #fff;
				box-shadow: 0px 4px 5px 3px #ccc;
				margin: 15rpx 0;
				padding: 20rpx;
			}
			/deep/ .u-radio__label {
				width: 100%;
			}
		}
	}
</style>
