<template>
	<view class="container">
		<view class="empty" v-if="communityList.length == 0">
			<image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_newEmpty.png"
				alt="" />
			没有添加任何房产

		</view>

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

		<div class="addBtn" @click="addCommunity">添加我的房产</div>
	</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: {
		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);
			uni.setStorageSync("isShowNav", e.room_owner_list[0].type)
			console.log("🚀 ~ choseCommunity ~ e.room_owner_list[0].type:", e.room_owner_list[0].type)
			NavgateTo("1")
		},
	},

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

	},

	onReachBottom() { },
}
</script>

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