<template>
	<view class="car">
		<!-- 列表 -->
		<view class="carlists">
			<box-list :datainfo="list" :wtdt="wtdt" type='comehouse' @getDetail="getDetail" ></box-list>
		</view>
		<loading></loading>
	</view>
</template>

<script>
	import config from '@/config'
	const baseUrl = config.baseUrl
	import boxList from "@/mine/components/box/list.vue"
	import {houseInfoList} from "@/api/work/work.js"
	import {getDictionaryFn} from "@/api/system/user.js"
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	export default{
		components:{boxList},
		data(){
			return{
				text:'',
				list:[],
				pageSize: 10,
				pageNum: 1,
				reachflag: true,
				wtdt:'',
				fwztList:[],
				userId:this.$store.state.user.userId,
			}
		},
		onUnload() {
			uni.$off('refHouseList')
		},
		onLoad: function(e) {
			uni.$on('refHouseList',(res)=>{
				this.getrefreshData()
			})
			this.init()
			this.getDataFn();
		},
		// 上拉触底加载更多触发事件
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		methods:{
			checkPermi, checkRole,
			init(){
				// 房屋状态
				// getDictionaryFn('house_status').then(res=>{
				// 	if(res.code==200){
				// 		this.fwztList = res.data.map(v => {
				// 			var obj={
				// 				tit: v.dictLabel,
				// 				val: v.dictValue
				// 			}
				// 			this.tablist.push(obj)
				// 			return {
				// 				dictLabel: v.dictLabel,
				// 				dictValue: v.dictValue
				// 			}
				// 		})
				// 	}
				// })
			},
			getAddFn(){
				this.$tab.navigateTo("/mine/pages/house/addhouse")
			},
			getDetail(e){
				this.$tab.navigateTo(`/mine/pages/house/housedetail?id=${e}`)
			},
			getrefreshData(){
				this.pageNum=1;
				this.list=[];
				this.reachflag=true;
				this.getDataFn()
			},
			getDataFn(){
				var params={
					pageSize:this.pageSize,
					pageNum: this.pageNum,
					userId:this.userId
				}
				houseInfoList(params).then(res=>{
					if(res.code==200){
						if (res.rows.length < this.pageSize) {
							this.reachflag = false
							this.wtdt = '到底了~';
						} else {
							var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum -	1)
							if (num < res.total) {
								this.reachflag = true
								this.wtdt = ''
							} else {
								this.reachflag = false
								this.wtdt = '到底了~';
							}
						}
						if (this.pageNum == 1) {
							this.list = res.rows;
						} else {
							this.list = this.list.concat(res.rows)
						}
					}else{
						this.$toast(res.msg)
					}
				})
				
			},
		}
	}
</script>
<style>
	page{background: #F3F3F0;}
</style>
<style lang="scss" scoped>
.car{padding: 24rpx 0 10rpx;}
.carlists{padding: 0 18rpx;}
</style>