<template>
	<view class="container">
		<view class="empty" v-if="communityList.length == 0">
			<image src="https://static.hshuishang.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 }}</div>
						<div class="communityItem_left_msg_msg">{{ item.addr }}</div>
					</div>
				</div>
				<div 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>
				</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.workCommunityList, "POST", {
				user_id: uni.getStorageSync('userId'),
			}).then(res => {
				res.rows.forEach(item => {
					item.pic = item.pic ? (item.pic.startsWith('http') ? item.pic : picUrl + item.pic) : ''
				});
				this.communityList = res.rows
			})
		},

		choseCommunity(e) {
			this.currentCommunity = e
			uni.setStorageSync('changeWorkOrderData', { id: e.community_id, name: e.name });
			uni.setStorageSync('currentCommunityAddr',e.addr);
			NavgateTo("1")
		},
	},

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

	onReachBottom() { },
}
</script>

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