<template>
	<view class="container">
		<view class="empty" v-if="communityList.length == 0">
			<view class="emptyTitle">绑定房源</view>
			<view class="emptyMsg">请绑定房源信息  以便使用其他功能</view>
			<image src="http://localhost:8080/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://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>
				</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: {
		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)
			NavgateTo("1")
		},
	},

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

	},

	onReachBottom() { },
}
</script>

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