<template>
	<view class="container">
		<!-- <view class="searchBox" :style="{ height: localHeight + 'px', paddingTop: top + 'px' }">
			<view class="searchBox_add">
				<view class="searchBox_left">
					<u-icon bold color="#000" size="40" name="arrow-left" @click="back"></u-icon>
				</view>
				<view class="searchBox_mid">我的房产</view>
				<view class="searchBox_right"></view>
			</view>
		</view> -->
		<view class="empty" v-if="communityList.length == 0">
			<view class="emptyTitle">绑定房源</view>
			<view class="emptyMsg">请绑定房源信息 以便使用其他功能</view>
			<image src="https://static.hshuishang.com/community_no_image3.png" alt="" />
		</view>

		<view class="communityList">
			<view class="communityItem" v-for="item in communityList" :key="item.community_id"
				@click="choseCommunity(item)">
				<view class="communityItem_left">
					<view class="communityItem_left_img">
						<image :src="item.pic" mode="aspectFill"></image>
					</view>
					<view class="communityItem_left_msg">
						<view class="communityItem_left_msg_tit">{{ item.name }}<span>（ {{ item.room_owner_list.length
						}}
								）</span></view>
						<view class="communityItem_left_msg_msg">{{ item.addr }}</view>
					</view>
				</view>
				<view class="communityItem_right">
					<image src="https://static.hshuishang.com/property-img-file/com_check1.png"
						v-if="item.community_id != currentCommunity.id"></image>
					<image src="https://static.hshuishang.com/property-img-file/com_check2.png"
						v-if="item.community_id == currentCommunity.id"></image>
				</view>
			</view>
		</view>

		<view class="addBtn" @click="addCommunity">去绑定房源</view>
	</view>
</template>

<script>
import {
	request,
	NavgateTo,
	isPhone,
	picUrl
} from '../../../utils';
import {
	apiArr
} from '../../../api/community';
export default {
	data() {
		return {
			communityList: [],
			page_num: 1,
			page_size: 10,
			currentCommunity: {}
		}
	},
	methods: {
		back() {
			NavgateTo("/packages/community/index/index")
		},
		addCommunity() {
			NavgateTo("/packages/community/addCommunity/index")
		},
		async getList() {
			await request(apiArr.commInfo, "POST", {
				user_id: uni.getStorageSync('userId'),
				longitude: uni.getStorageSync('location').lng,
				latitude: uni.getStorageSync('location').lat,
				page_num: this.page_num,
				page_size: this.page_size
			}).then(res => {
				res.rows.forEach(item => {
					item.pic = item.pic.startsWith('http') ? item.pic : picUrl + item.pic
				});
				this.communityList = res.rows.filter(item => item.front_end_display !== 1)
			})
		},
		// toUpview(item) {
		// 	uni.setStorageSync('changeCommData', { id: item.community_id, name: item.name });
		// 	NavgateTo("/packages/community/index/index")
		// },

		choseCommunity(e) {
			this.currentCommunity = e
			uni.setStorageSync('changeCommData', { id: e.community_id, name: e.name });
			uni.setStorageSync('currentCommunityAddr', e.addr);
			// 缓存该小区已绑定房产的门牌号（room_name，如「1栋1单元1层103」），供到家服务等下单页缺省填写
			const owner = (e.room_owner_list && e.room_owner_list.length) ? e.room_owner_list[0] : null
			uni.setStorageSync('currentRoomNo', owner && owner.room_name ? owner.room_name : '');
			NavgateTo("1")
		},
	},

	onLoad(options) {
		this.currentCommunity = uni.getStorageSync('changeCommData')
		console.log(this.currentCommunity, 'currentCommunity');
		this.getList();

	},

	onReachBottom() { },
}
</script>

<style>
@import url("./index.css");
</style>