<template>
	<view class="container">
		<view class="page">
			<view class="search">
				<uni-search-bar placeholder="请输入您的小区名" bgColor="#EEEEEE" @confirm="search" />
				<view class="list">
					<view class="item" :class="{'active': item.platformCode === currentHouseCode}" @click="onChangeHouse(item)" v-for="item in houseList" :key="item.platformCode">{{item.platformName}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				houseList: [],
				currentHouseCode: ''
			}
		},
		methods: {
			onChangeHouse(item) {
				if(item.platformCode === this.currentHouseCode) return
				uni.setStorageSync('platform_code', item.platformCode)
				uni.reLaunch({
					url: '/pages/home/index'
				})
			},
			search(value) {
				console.log(value)
			}
		},
		onLoad() {
			this.currentHouseCode = uni.getStorageSync('platform_code')
			let userType = uni.getStorageSync('user_type')
			if(userType === '1') {
				let data = uni.getStorageSync('user_house_list')
				this.houseList = JSON.parse(data)
			} else {
				let data = uni.getStorageSync('employee_house_list')
				this.houseList = JSON.parse(data)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		padding: 15rpx;
		background-color: #ffffff;
	}

	.search {
		.list {
			padding:20rpx 30rpx;
			.item {
				font-size: 28rpx;
				color: #373737;
				height: 84rpx;
				line-height: 84rpx;
				border-bottom: 1px solid #F8F6F9;
				&.active {
					color: #6A59F2;
				}
			}
		}
	}
</style>