<template>
	<view class="car">
		<!-- 列表 -->
		<view class="carlists">
			<box-list :datainfo="list" :rylxList="rylxList" :voList="voList" :wtdt="wtdt" type='authen' @getDetail="getDetail" @getDelFn="getDelFn"></box-list>
			<!-- <car-list :datainfo="list" :ygztList="ygztList" :yglbList="yglbList" :wtdt="wtdt" type='rzstaff' @getDetail="getDetail" @getDelFn="getDelFn" @getShFn="getShFn"></car-list> -->
		</view>
		<block>
			<view style="height: 100rpx;"></view>
			<view class="rfbtn" @click="getAddFn">添加认证信息</view>
		</block>
		
		<loading></loading>
	</view>
</template>

<script>
	import config from '@/config'
	const baseUrl = config.baseUrl
	import boxList from "@/mine/components/box/list.vue"
	import {gettenantList} from "@/api/login.js"
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	import {residentInfoDel,listAuthentication,deleteResident} from "@/api/work/people.js"
	import {getDictionaryFn} from "@/api/system/user.js"
	export default{
		components:{boxList},
		data(){
			return{
				list:[],
				pageSize: 10,
				pageNum: 1,
				reachflag: true,
				wtdt:'',
				userId:this.$store.state.user.userId,
				rylxList:[],
				voList:[],
			}
		},
		onUnload() {
			uni.$off('residentInfoList')
		},
		onLoad: function() {
			uni.$on('residentInfoList',(res)=>{
				this.getrefreshData()
			})
			this.init();
			this.gettenantList()
			this.getDataFn();
		},
		// 上拉触底加载更多触发事件
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		methods:{
			checkPermi, checkRole,
			getTabFn(val){
				this.tabval=val;
				this.getrefreshData()
			},
			getrefreshData(){
				this.pageNum=1;
				this.list=[];
				this.reachflag=true;
				this.getDataFn()
			},
			getDelFn(data){
				var that=this;
				var info=JSON.parse(JSON.stringify(data))
				var params={
					residentId:info.residentId,
					userId:info.userId,
					tenantId:info.tenantId,
					examine:info.examine,
					houseId:info.houseId,
				}
				deleteResident(params).then(res=>{
					if(res.code==200){
						this.$toast("删除成功");
						setTimeout(function(){
							that.getrefreshData()
						},1500)
					}
				})
			},
			// 获取租户列表
			gettenantList(){
				gettenantList().then(res=>{
					if(res.code==200){
						if(res.data.voList&&res.data.voList.length){
							this.voList = res.data.voList.map(v => {
								return {
									dictLabel: v.companyName,
									dictValue: v.tenantId
								}
							})
						}
						
					}else{
						this.$toast(res.msg)
					}
				})
			},
			init(){
				getDictionaryFn('resident_Type').then(res=>{
					if(res.code==200){
						this.rylxList = res.data.map(v => {
							return {
								dictLabel: v.dictLabel,
								dictValue: v.dictValue
							}
						})
					}
				})
			},
			getShFn(data){
				var that=this;
				var info=JSON.parse(JSON.stringify(data))
				var ite=JSON.parse(JSON.stringify(info.ite))
				var params={
					staffId:ite.staffId,
					userId:ite.userId,
					examine:info.sh
				}
				// params.examine=info.sh;
				examineStaff(params).then(res=>{
					if(res.code==200){
						this.$toast('审核成功')
						setTimeout(function(){
							that.getrefreshData()
						},1200)
					}
				})
			},
			getAddFn(){
				var type='rzadd';
				this.$tab.navigateTo(`/mine/pages/info/authenadd?type=${type}`)
				// if(this.list&&this.list.length){
				// 	var id=this.list[0].residentId
				// 	this.$tab.navigateTo(`/mine/pages/info/authenadd?type=${type}&id=${id}`) 
				// }else{
				// 	this.$tab.navigateTo(`/mine/pages/info/authenadd?type=${type}`) 
				// }
				
			},
			getDetail(e){
				this.$tab.navigateTo("/mine/pages/info/authenadd?type=rz&id="+e)
			},

			getDataFn(){
				var params={
					pageSize:this.pageSize,
					pageNum: this.pageNum,
					userId:this.userId
				}
				// if(this.text){
				// 	params.staffName=this.text
				// }
				// if(this.sfxx){
				// 	params.staffCategory=this.sfxxid
				// }
				listAuthentication(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 = '到底了~';
							}
						}
						var arr=JSON.parse(JSON.stringify((res.rows)))
						arr.forEach(ite=>{
							ite.hideflag=true;
							if(ite.phoneNumber){
								ite.phoneNumbera=this.HideType(ite.phoneNumber)
							}
							// if(ite.idCard){
							// 	ite.idCarda=this.HideType(ite.idCard)
							// }
						})
						if (this.pageNum == 1) {
							this.list = arr;
						} else {
							this.list = this.list.concat(arr)
						}
					}else{
						this.$toast(res.msg)
					}
				})
			},
			getDelFn(data){
				var that=this;
				var info=JSON.parse(JSON.stringify(data))
				var params={
					staffId:info.staffId,
					userId:info.userId,
					tenantId:info.tenantId,
				}
				residentInfoDel(params).then(res=>{
					if(res.code==200){
						this.$toast("删除成功");
						setTimeout(function(){
							that.getrefreshData()
						},1500)
					}
				})
			},
			HideType(data,flag,type){
				const firstPart = data.slice(0, 1);  
				  // 生成中间8位的星号  
				  const middlePart = '*'.repeat(data.length-2);  
				  // 获取后4位  
				  const lastPart = data.slice(data.length-1); 
				  var s= firstPart + middlePart + lastPart;
				  return s
			},
		}
	}
</script>
<style>
	page{background: #F3F3F0;}
</style>
<style lang="scss" scoped>
.car{padding: 12rpx 0 10rpx;}
.cartop{position: fixed;left: 0;right: 0;top: 0;background-color: #ffffff;z-index: 2;
	.topa{padding: 20rpx 20rpx 32rpx;
		.resetimg{width: 36rpx;height: 36rpx;margin-right: 24rpx;flex: 0 0 auto;}
		.chekt{width: 150rpx;overflow: hidden;
			view{font-weight: 500;font-size: 26rpx;color: #272727;flex: 1;}
			image{width: 24rpx;height: 16rpx;margin-left: 18rpx;flex: 0 0 auto;}
		}
		.search{flex: 1;margin-left: 16rpx;height: 64rpx;background: #EEEEEE;border-radius: 32rpx;border: 2rpx solid #E6E6E6;padding-left: 24rpx;box-sizing: border-box;
		image{width: 32rpx;height: 34rpx;margin-right: 22rpx;flex: 0 0 auto;}
		input{flex: 1;font-size: 26rpx;color: #272727;}
		.btn{width: 100rpx;height: 64rpx;background: #3565ED;border-radius: 32rpx;flex: 0 0 auto;font-weight: bold;text-align: center;line-height: 64rpx;
font-size: 26rpx;
color: #FFFFFF;}
		}
	}
	.tablst{background: #F3F3F0;padding:24rpx 16rpx 26rpx 30rpx;overflow: auto;
		.tabs{height: 48rpx;background: #DADADA;border-radius: 24rpx;margin-right: 30rpx;font-weight: 500;display: flex;align-items: center;justify-content: center;padding: 0 24rpx;font-size: 26rpx;box-sizing: border-box;flex: 0 0 auto;color: #666666;
			&.act{border: 2rpx solid #0256FD;background: #FFFFFF;color: #0256FD;}
		}
	}

}
.carlists{padding: 0 18rpx;}
</style>