<template>
	<view class="house-index">
		<house-list :list="houseList"></house-list>
	</view>
</template>

<script>
	import houseList from '@/components/house/houseList.vue'
	import {
		getHouseListByPage
	} from '@/request/api/house'
	export default {
		data() {
			return {
				houseList: []
			}
		},
		onShow() {
			this.getHouseList();
		},
		methods: {
			getHouseList() {
				getHouseListByPage({
					currPage: 1,
					pageSize: 10,
					projectId: 9
				}).then(res => {
					if (res.code === 200) {
						let commonUrl =
							'https://file-node.oss-cn-shanghai.aliyuncs.com/youji/f488a1cc0e904ed089d52d88e3c1b33d';
						this.houseList = res.data.dataList.map(node => {
							if (node.picture) {
								let picture = JSON.parse(node.picture);
								if (picture.length === 0) {
									node['privewImage'] = commonUrl;
								} else {
									node['privewImage'] = picture[0].url;
								}
							} else {
								node['privewImage'] = commonUrl;
							}
							return node;
						});
					}
				})
			}
		},
		components: {
			houseList
		}
	}
</script>

<style lang="scss">
	.house-index {
		padding: 0 30rpx;
	}
</style>