<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>
		<view style="width:92%;height: 80rpx;display: flex;align-items: center;">
			<view @click="checkedAll" class="button-view" style="background: #00337A;margin-right: 10px;">全选</view>
			<view @click="handleSelfSave" class="button-view" style="background: #3989FF;margin-right: 10px;">自主存证</view>
			<view @click="handleAdminBack" class="button-view" style="background: #3989FF;">管理员存证</view>
		</view>
		<scroll-view style="width: 100%;height: 82vh;" @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 style="width: 10%;" @click="checkSelect(item)">
							<u-checkbox-group v-model="item.checked">
								<u-checkbox :customStyle="{margin: '0rpx 10rpx'}" :label="''" :name="item.taskNo"></u-checkbox>
							</u-checkbox-group>
						</view>
						<view class="label-view" style="width: 90%;">
							<view class="label">任务编号：</view>
							<view class="text">{{item.taskNo}}</view> 
						</view> 
					</view>
					<view class="label-box" @click="checkSelect(item)">
						<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" @click="checkSelect(item)">
						<view class="label-view" style="width: 50%;">
							<view class="label">出生日期：</view>
							<view class="text">{{item.birthday}}</view> 
						</view>  
						<view class="label-view" style="width: 50%;">
							<view class="label">出生地点：</view>
							<view class="text">{{item.birthAddr}}</view> 
						</view>  
					</view>
					<view class="label-box" @click="checkSelect(item)">
						<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" @click="checkSelect(item)">
						<view class="label-view" style="width: 50%;">
							<view class="label">签发地：</view>
							<view class="text">{{item.issueAddr}}</view> 
						</view>  
						<view class="label-view" style="width: 50%;">
							<view class="label">签发日期：</view>
							<view class="text">{{item.issueDay}}</view> 
						</view>  
					</view>
					<view class="label-box" @click="checkSelect(item)">
						<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.isEleName}}</view> 
						</view>  
					</view> 
					<view class="label-box" @click="checkSelect(item)">
						<view class="label-view" style="width: 50%;">
							<view class="label">设备编号：</view>
							<view class="text">{{item.deviceNo}}</view> 
						</view>  
						<view class="label-view" style="width: 50%;">
							<view class="label">槽位编号：</view>
							<view class="text">{{item.soltNo}}</view> 
						</view> 
					</view> 
					<view class="label-box" @click="checkSelect(item)">
						<view class="label-view" style="width: 50%;">
							<view class="label">验证码：</view>
							<view class="text">{{item.verificationCode}}</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" @click="checkSelect(item)">
						<view class="label-view" style="width: 50%;">
							<view class="label">创建时间：</view>
							<view class="text">{{item.createTime}}</view> 
						</view>   
						<view class="label-view" style="width: 50%;">
							<view class="label">处理结果：</view>
							<view class="text">{{item.processStateName}}</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 { certificateSaveListApi } from '@/api/certificateReturnManage/index.js';
 
export default {
  data() {
    return {
		fontValue:uni.getStorageSync('fontSize') || 8,
		keyword:"",
		pageNum: 1,
		pageSize: 10,
		total: 0,
		infoList: [],
		status: 'loadmore',
		isCheckAll:false,
		chosenList:[]
    }
  },
  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 certificateSaveListApi(params)
				console.log('?? ~ getList ~ res:', res)
				this.total = res.total; 
				res.rows.forEach(item=>{
					item.checked=[]; 
				})
				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)
			}
		},
		// 单选
		checkSelect(chosen){
			this.infoList.forEach(item=>{
				if(item.taskNo==chosen.taskNo){
					if(item.checked.length==0){ 
						item.checked=[item.taskNo]
					}else{ 
						item.checked=[]
					}
				}
			})
		},
		// 全选
		checkedAll(){
			this.isCheckAll=!this.isCheckAll
			if(this.isCheckAll){
				this.infoList.forEach(item=>{
					item.checked=[item.taskNo]
				}) 
			}else{
				this.infoList.forEach(item=>{
					item.checked=[]
				}) 
			}
		}, 
		/** 自主存证 */
		handleSelfSave(){
			this.chosenList=[]
			this.infoList.forEach(item=>{ 
				if(item.checked.length>0){ 
					this.chosenList.push(item)
				} 
			})
			console.log(this.chosenList)
			if(this.chosenList.length>0){
				uni.showModal({
					title: `确认自主存证？`,
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							this.batchSelfSave();
						}
					}
				});
			}else{
				uni.$u.toast(`未勾选任务！`)
			} 
		},
		async batchSelfSave() {
			console.log(this.chosenList)
			// const params = {
			// 	pageNum: this.pageNum,
			// 	pageSize: this.pageSize, 
			// 	keyword: this.keyword
			// } 
			// try {
			// const res = await certificateTaskListApi(params)
			// 	console.log('?? ~ getList ~ res:', res)
				 
			// } catch (error) {
			// 	console.log(error)
			// }
		},
		/** 管理员存证 */
		handleAdminBack(){
			this.chosenList=[]
			this.infoList.forEach(item=>{ 
				if(item.checked.length>0){ 
					this.chosenList.push(item)
				} 
			})
			console.log(this.chosenList)
			if(this.chosenList.length>0){
				uni.showModal({
					title: `确认管理员存证？`,
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							this.batchAdminSave();
						}
					}
				});
			}else{
				uni.$u.toast(`未勾选任务！`)
			} 
		},
		async batchAdminSave() {
			console.log(this.chosenList)
			// const params = {
			// 	pageNum: this.pageNum,
			// 	pageSize: this.pageSize, 
			// 	keyword: this.keyword
			// } 
			// try {
			// const res = await certificateTaskListApi(params)
			// 	console.log('?? ~ getList ~ res:', res)
				 
			// } catch (error) {
			// 	console.log(error)
			// }
		},
		
  }
}
</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{
	
}
.button-view{
	width:20%;height:50rpx;line-height: 50rpx;text-align: center;
	color: #FFF;border-radius: 10rpx;font-size: 22rpx;
}
</style>