<template>
	<view class="phone-list-page">
		<view class="icon-title-navBar-box">
			<view @click="goUpPage" class="nav-bar-icon"></view>
			<text class="nav-bar-title">成绩</text>
		</view>
		<!-- 查询职业 -->
		<view class="phone-search-box">
			<input class="search-input" placeholder="请输入职业名称" v-model="data.zyName" />
			<view class="search-icon" @click="handleSearch">
				<uni-icons type="search" size="24" color="#fff"></uni-icons>
			</view>
		</view>
		<!-- 课程列表 -->
			<scroll-view scroll-y="true" refresher-enabled="true" :refresher-triggered="data.loading"
				:refresher-threshold="50" refresher-background="transparent" @refresherrefresh="onRefresh"
				class="admin-phone-scroll-view">
				<uni-list class="admin-list-box">
					<uni-list-item v-for="item in data.list" class="admin-list-item-box">
						<template v-slot:body>
							<view class="item-card-row">
								<!-- 数量 -->
								<view class="ks-item-top">
									<view class="ks-name">{{item.ksName}}</view>
									<view class="ks-zyLevelName">{{item.zyLevelName}}</view>
								</view>
								
								<view class="ks-totalTm-row">
									<view class="ks-totalTm">
										<icon class="phone-user-icon" />姓名：{{item.realName}} 
									</view>
									<view class="ks-totalTm">
										<icon class="phone-tel-icon" />手机号：{{item.userName}} 
									</view>
								</view>
								<view class="ks-totalTm">
									<icon class="phone-time-icon" />{{item.answerStartTime}} - {{item.answerEndTime}}
								</view>
								<!-- <view class="ks-totalTm">
									<icon class="phone-time-icon" /> {{item.userScore}} / {{item.okScore}}/{{item.ksScore}}
								</view> -->
								<!-- 分数 -->
								<view class="ks-score-content">
									<view class="ks-score">
										<icon class="phone-zongfen-icon" />总分：<text>{{item.ksScore}}</text>
									</view>
									<view class="ks-okScore cj-okScore">
										<icon class="phone-jigefen-icon" />及格分：<text>{{item.okScore}}</text>
									</view>
									<view class="ks-getScore">
										<icon class="phone-defen-icon" />得分：<text>{{item.userScore}}</text>
									</view>
								</view>
								<button @click="checkKecheng(item)" type="primary" size="mini"
									class="item-view-btn">查看内容</button>
							</view>
						</template>
					</uni-list-item>
					<uni-load-more :status="data.state" @click="getMore(0)"
						:contentText="data.contentText"></uni-load-more>
				</uni-list>
			</scroll-view>

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

<script setup>
	import customTabbarAdminVue from "@/components/custom-tabbar/custom-tabbar-admin.vue";
	import {
		ref,
		reactive
	} from "vue";
	import {
		onLoad
	} from "@dcloudio/uni-app";
	import * as kaoshiApi from "@/api/kaoshi.js"
	import {
		formatDuration
	} from "@/utils/common.js"
	

	const data = reactive({
		zyName: '', // 职业名称
		list: [], // 考试列表
		loading: false,
		page: 0,
		size: 10,
		state: 'more',
		contentText: {
			contentdown: '查看更多',
			contentrefresh: '加载中',
			contentnomore: '没有更多'
		}
	})

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

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

	function checkKecheng(item) {
		uni.navigateTo({
			url: `/pages/admin/Chengji/ksScoreShijuan?hisId=${item.hisId}`
		})
	}

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

	function refreshData() {
		const opt = {
			page: 1,
			size: 10, // 固定查询10条
			zyName: data.zyName
		}
		data.list = [];
		// 数学
		data.state = 'loading';
		data.page++;
		opt.page = data.page;

		kaoshiApi.getAdminKsChengjiList(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 = {
			page: 1,
			size: 10, // 固定查询10条
			zyName: data.zyName
		}
		if (data.state == 'no-more') return;
		data.state = 'loading';
		data.page++;
		opt.page = data.page;
		kaoshiApi.getAdminKsChengjiList(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(() => {
		getMore()
	})
</script>

<style lang="scss" scoped>
	.phone-kecheng-page {
		background-color: #ccc;
		box-sizing: border-box;
	}

	.phone-search-content {
		position: relative;
		background-color: #fff;
		height: 42px;

		.search-input {
			height: 42px;
			line-height: 40px;
			border-radius: 20px;
			border: 1px solid #ccc;
			padding: 0 70px 0 20px;
		}

		.search-icon {
			position: absolute;
			right: 5px;
			top: 4px;
			padding: 6px;
			background-color: #ccc;
			border-radius: 20px;
			width: 50px;
			text-align: center;
		}
	}
</style>