<template>
	<page-meta :page-font-size="fontValue+'px'" :root-font-size="fontValue+'px'"></page-meta>
	<view class="certificate-list">
		<Navbar title="存证超期" :showRightText="false" :isBack="true"/>
		<view style="width: 94%;height: 80rpx;margin: 10rpx auto;">
			<u-search shape="square" placeholder="搜索"  v-model="keyword" :showAction="true" actionText="搜索" :animation="false" @custom="searchList"></u-search>
		</view>
		<scroll-view style="width: 100%;height: 85vh;" @scrolltolower="onScrollTolower" scroll-y="true">	
			<view class="info-item" v-for="(item, index) in infoList" :key="index"> 
				<view style="width: 100%;height: 100%;padding-top: 10rpx;font-size: 24rpx;">
					<view class="label-box">
						<view class="label-view" style="width: 50%;">
							<view class="label">姓名：</view>
							<view class="text">{{item.name}}</view> 
						</view> 
						<view class="label-view" style="width: 50%;">
							<view class="label">身份证号：</view>
							<view class="text">{{item.idNumber}}</view> 
						</view>  
					</view>
					<view class="label-box">
						<view class="label-view" style="width: 50%;">
							<view class="label">证件类型：</view>
							<view class="text">{{item.certificateTypeName}}</view> 
						</view>  
						<view class="label-view" style="width: 50%;">
							<view class="label">证件编号：</view>
							<view class="text">{{item.certificateNo}}</view> 
						</view>  
					</view>
					<view class="label-box">
						<view class="label-view" style="width: 50%;">
							<view class="label">有效期至：</view>
							<view class="text">{{item.issueLifespan}}</view> 
						</view> 
						<view class="label-view" style="width: 50%;">
							<view class="label">存证截止日期：</view>
							<view class="text">{{item.processDate}}</view> 
						</view>  
					
					</view>
					<view class="label-box">
						<view class="label-view" style="width: 50%;">
							<view class="label">实际取证日期：</view>
							<view class="text">{{item.realProcessDate}}</view> 
						</view>  
						<view class="label-view" style="width: 50%;">
							<view class="label">超期天数：</view>
							<view class="text">{{item.processGapDate}}</view> 
						</view>  
					</view> 
					<view class="label-box">
						<view class="label-view" style="width: 50%;">
							<view class="label">邮箱：</view>
							<view class="text">{{item.email}}</view> 
						</view>  
						<view class="label-view" style="width: 50%;">
							<view class="label">二维码：</view>
							<view class="text">{{item.verificationCode}}</view> 
						</view> 
					</view> 
				</view>
			</view>
			<view style="margin: 20px 0" v-if="infoList.length > 0">
				<u-loadmore :status="status" nomoreText="没有更多数据了" />
			</view>
			<view v-else class="flex justify-center align-center" style="height: 50vh">
				<u-empty icon="../../static/images/not_order.png" text="暂无数据" textColor="#000" />
			</view>
		</scroll-view> 
	</view>
</template>

<script>
import { certificateLifespanApi } from '@/api/certificateManage/index.js';
 
export default {
  data() {
    return {
		fontValue:uni.getStorageSync('fontSize') || 8,
		keyword:"",
		pageNum: 1,
		pageSize: 10,
		total: 0,
		infoList: [],
		status: 'loadmore',
    }
  },
  onLoad() {
  	
  },
  onShow(){
	  this.getList()
  }, 
  methods: {
		//搜索
		searchList(value){
			this.pageNum=1
			this.infoList=[]
			this.getList()
		},
		// 翻页
		onScrollTolower(){
			console.log(this.infoList.length)
			if(this.total>this.infoList.length){
				this.pageNum++
				this.getList()
			}
		},
		//获取列表
		async getList() { 
			console.log('获取列表')
			const params = {
				pageNum: this.pageNum,
				pageSize: this.pageSize, 
				keyword: this.keyword
			} 
			try {
			const res = await certificateLifespanApi(params)
				console.log('?? ~ getList ~ res:', res)
				this.total = res.total; 
				if(this.pageNum==1){
					this.infoList = res.rows
				}else{
					this.infoList.push(...res.rows)
				}
				this.status = this.total == this.infoList.length ? 'nomore' : 'loadmore'
			} catch (error) {
				console.log(error)
			}
		}, 
		handleEdit(certificate) {
		  // 处理编辑事件
		  // uni.$u.toast(`编辑第${index + 1}个地址`)
		  console.log('?? ==='+certificate)
			uni.navigateTo({
			  // url: `/pages/mine/me/upcertificate?certificate=${encodeURIComponent(JSON.stringify(certificate))}`
			  url: `/pages/mine/me/upcertificate?certificate=${JSON.stringify(certificate)}`
			})
		},
		addInfo() {
		  uni.navigateTo({
			url: `/pages/mine/me/upcertificate`
		  })
		},
  }
}
</script>

<style lang="scss" scoped>
.certificate-list {
  height: 100vh; 
  background-color: #f8f8f8;
  padding: 30rpx;
}
.info-item{
	width: 100%;
	height: auto;
	display: flex;
	align-items: center; 
	margin: 10rpx auto;
	border-bottom: 1px solid #ccc;
}
.label-box{
	width: 100%;
	height: auto;
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 2px;
}
.label-view{
	width: 100%;
	display: flex; 
	align-items: center;
}
.label{
	font-weight: 600;
}
.text{
	
}
</style>