<template>
	<view class="phone-list-page phone-banzheng-page">
		<view class="phone-filter-navBar-box">
			<view @click="goUpPage" class="nav-bar-icon"></view>
			<text class="nav-bar-title">办证管理</text>
			<icon class="nav-search-icon" @click="downBtn"></icon>
		</view>
		<!-- 课程列表 -->
		<scroll-view scroll-y="true" refresher-enabled="true" :refresher-triggered="data.loading"
			:refresher-threshold="50" refresher-background="transparent" @refresherrefresh="onRefresh"
			class="phone-scroll-view">
			<uni-list>
				<uni-list-item v-for="item in data.list" class="banzheng-list-item-box">
					<template v-slot:body>
						<view class="banzheng-list-card-box" @click="checkKecheng(item)">
							<view class="card-head-row">
								<view class="head-name">{{item.realName}}</view>
								<view class="head-status">
									<text>{{item.statusBanzheng}}</text>
									<text class="status-line" v-if="item.statusKaoshi != '-'">|</text>
									<text v-if="item.statusKaoshi != '-'">{{item.statusKaoshi}}</text>
								  </view>
							</view>
							<view class="card-body-row">
								<img :src="item.icon">
								<view class="body-content-row">
									<view>
										<text>手机号：</text>{{item.userName}}
										<button type="default" class="phone-green-btn">打电话</button>
									</view>
									<view><text>证件号：</text>{{item.idcard}}</view>
									<view>
										<view><icon></icon>报证机构：{{item.jgName}}</view>
										<view><icon></icon>职业名称：{{item.zyName}}</view>
									</view>
								</view>
							</view>
						</view>
					</template>
				</uni-list-item>
				<uni-load-more :status="data.state" @click="getMore(0)" :contentText="data.contentText"></uni-load-more>
			</uni-list>
		</scroll-view>

		<!-- 页面底端 -->
		<customTabbarClientVue></customTabbarClientVue>
	</view>
</template>

<script setup>
	import customTabbarClientVue from "@/components/custom-tabbar/custom-tabbar-admin.vue";

	import {
		ref,
		reactive
	} from "vue";
	import {
		onLoad,
		onShow
	} from "@dcloudio/uni-app";
	import {getKaozhengList} from '@/api/banzheng.js'
	import {
		formatSecondsToCnhms
	} from "@/utils/common.js"

	const data = reactive({
		jgId: '', // 机构ID
		realName: '', // 姓名
		statusBanzheng: '', // 办证状态
		statusKaoshi: '', // 考试状态
		userName: '', // 手机号
		zyId: '', // 职业ID
		zyLevel: '', // 职业等级ID
		list: [], // 办证列表
		loading: false,
		page: 0,
		size: 10,
		state: 'more',
		contentText: {
			contentdown: '查看更多',
			contentrefresh: '加载中',
			contentnomore: '没有更多'
		},
		from: ''
	})

	function goUpPage() {
		uni.redirectTo({
			url: '/pages/admin/ShouYe/shouye'
		})
	}

	function handleSearch() {
		data.page = 0;
		refreshData();
	}

	function checkKecheng(item) {
		uni.navigateTo({
			url: `/pages/admin/tongzhi/details?noticeId=${item.noticeId}`
		})
	}

	function onRefresh() {
		data.page = 0;
		data.list = [];
		data.loading = true;
		refreshData();
	}

	function refreshData() {
		const opt = {
			jgId: data.jgId, // 机构ID
			realName: data.realName, // 姓名
			statusBanzheng: data.statusBanzheng, // 办证状态
			statusKaoshi: data.statusKaoshi, // 考试状态
			userName: data.userName, // 手机号
			zyId: data.zyId, // 职业ID
			zyLevel: data.zyId, // 职业等级ID
			page: 1,
			size: 10, // 固定查询10条
		}
		data.list = [];
		// 数学
		data.state = 'loading';
		data.page++;
		opt.page = data.page;

		getKaozhengList(opt).then(res => {
			data.list = data.list.concat(res.data.data);
			data.loading = false;

			if (res.data.total > data.list.length) {
				data.state = 'more';
				data.loading = false;
			} else {
				data.state = 'no-more';
				data.loading = false;
			}
		}).catch(err => {
			data.state = 'more';
			data.loading = false;
		})
	}

	function getMore() {
		const opt = {
			jgId: data.jgId, // 机构ID
			realName: data.realName, // 姓名
			statusBanzheng: data.statusBanzheng, // 办证状态
			statusKaoshi: data.statusKaoshi, // 考试状态
			userName: data.userName, // 手机号
			zyId: data.zyId, // 职业ID
			zyLevel: data.zyId, // 职业等级ID
			page: 1,
			size: 10, // 固定查询10条
		}
		if (data.state == 'no-more') return;
		data.state = 'loading';
		data.page++;
		opt.page = data.page;
		getKaozhengList(opt).then(res => {
			data.list = data.list.concat(res.data.data);
			data.loading = false;

			if (res.data.total > data.list.length) {
				data.state = 'more';
				data.loading = false;
			} else {
				data.state = 'no-more';
				data.loading = false;
			}
		}).catch(err => {
			data.state = 'more';
			data.loading = false;
		})
	}

	onLoad((options) => {
		data.from = options.from;
	})

	onShow(() => {
		getMore()
	})
</script>
