<template>
	<view class="container">
		<image class="image" src="/static/9.png" mode="aspectFill"></image>
		<view class="title">缴费详情</view>

		<view class="box header">
			<view class="box_item">缴费类别</view>
			<view class="box_item">应缴金额</view>
			<view class="box_item">实缴金额</view>
		</view>
		<view class="box" v-for="(item, index) in dataList" :key="index">
			<view class="box_item">{{ item.payName }}</view>
			<view class="box_item">{{ item.yjje }}</view>
			<view class="box_item">{{ item.sjje }}</view>
		</view>
		<view class="nodata" v-if="!dataList.length">暂无数据</view>

		<!-- 按钮区域 -->
		<view class="btns">
			<view class="btn" @click="handlePay">在线缴费</view>
			<view class="btn mt20" @click="handleSelect">去选宿舍</view>
			<view class="btn mt20" @click="handleUp">上一步</view>
		</view>

		<!-- web弹窗区域 -->
		<uni-popup ref="popup_web" :is-mask-click="false">
			<view class="pop_web">
				<!-- 关闭图标 -->
				<uni-icons class="pop_close" type="closeempty" color="#808080" size="20" @click="handleClose_web"></uni-icons>
				<view class="web">
					<iframe class="iframe" src="https://pay.ncjti.edu.cn" frameborder="0"></iframe>
				</view>
			</view>
		</uni-popup>

		<!-- 提示缴费弹窗区域 -->
		<uni-popup ref="popup_tips" :is-mask-click="false">
			<view class="pop_tips">
				<image class="pop_img" src="/static/3.png" mode="aspectFill"></image>
				<!-- 关闭图标 -->
				<uni-icons class="pop_close" type="closeempty" color="#808080" size="20" @click="handleClose_tips"></uni-icons>
				<view class="pop_title">温馨提示</view>
				<view class="pop_text">
					{{ pop_info }}
				</view>
				<view class="pop_btn" @click="handleFinish_tips">去完成缴费</view>
			</view>
		</uni-popup>
	</view>
</template>

<script setup>
import { ref } from 'vue'
import { onLoad, onShow } from '@dcloudio/uni-app'
import { getStudentPayInfo } from '@/api/index.js'

const dataList = ref([])

const isPay = ref()

const popup_web = ref()

const popup_tips = ref()

const pop_info = ref()

onShow(() => {
	getInfo()
	pop_info.value = uni.getStorageSync('settingInfo').chooseDormitory
})

const getInfo = async () => {
	const res = await getStudentPayInfo({
		admissNum: uni.getStorageSync('studentInfo').admissNum
	})
	// console.log(res)
	if (res.code == 200) {
		dataList.value = res.data.pays
		isPay.value = res.data.isPay
	}
}

// 上一步按钮回调
const handleUp = () => {
	uni.navigateTo({
		url: '/pages/arrive/arrive'
	})
}

const handleClose_tips = () => {
	popup_tips.value.close()
}

const handleFinish_tips = () => {
	window.location.href = `https://pay.ncjti.edu.cn`
}

// 点击去选宿舍按钮回调
const handleSelect = () => {
	if (isPay.value == 0) {
		popup_tips.value.open()
	} else if (isPay.value == 1) {
		uni.navigateTo({
			url: '/pages/select/select'
		})
	} else {
		uni.showToast({
			title: '查询不到付费信息',
			icon: 'none'
		})
	}
}

// 继续支付按钮
const handlePay = () => {
	window.location.href = `https://pay.ncjti.edu.cn`
}

const handleClose_web = () => {
	popup_web.value.close()
}
</script>

<style lang="scss" scoped>
.container {
	display: flex;
	flex-direction: column;
	align-items: center;
	box-sizing: border-box;
	padding: 30rpx;
	min-height: 100vh;

	.image {
		width: 300rpx;
		height: 300rpx;
	}

	.title {
		margin-top: 20rpx;
	}

	.box {
		display: flex;
		align-items: center;
		justify-content: space-evenly;
		width: 100%;
		height: 70rpx;
		border-bottom: 2rpx solid #e6e6e6;

		.box_item {
			flex: 1;
			box-sizing: border-box;
			padding: 0 10rpx;
			text-align: center;
			text-overflow: ellipsis;
			white-space: nowrap;
			overflow: hidden;
		}
	}

	.header {
		margin-top: 30rpx;
		border: none;
		background-color: #f0f3f7;
	}

	.nodata {
		margin-top: 15rpx;
	}

	.btns {
		margin-top: 50rpx;
		width: 100%;

		.btn {
			display: flex;
			align-items: center;
			justify-content: center;
			width: 100%;
			height: 100rpx;
			font-size: 32rpx;
			color: #fff;
			border-radius: 8rpx;
			background-color: #0061ff;
		}

		.mt20 {
			margin-top: 20rpx;
		}

		.jump {
			background-color: #c34747;
		}
	}

	.pop_web {
		position: relative;
		box-sizing: border-box;
		padding: 80rpx 20rpx 50rpx;
		width: 90vw;
		height: 90vh;
		border-radius: 15rpx;
		background: linear-gradient(180deg, #ebf2ff 0%, #ffffff 100%);

		.pop_close {
			position: absolute;
			top: 19rpx;
			right: 29rpx;
		}

		.web {
			height: calc(90vh - 90rpx);

			.iframe {
				width: 100%;
				height: 100%;
			}
		}
	}

	.pop_tips {
		position: relative;
		box-sizing: border-box;
		padding: 150rpx 20rpx 50rpx;
		width: 659rpx;
		height: 728rpx;
		border-radius: 15rpx;
		background: linear-gradient(180deg, #ebf2ff 0%, #ffffff 100%);

		.pop_img {
			position: absolute;
			top: -103rpx;
			left: 227rpx;
			width: 206rpx;
			height: 206rpx;
		}

		.pop_close {
			position: absolute;
			top: 19rpx;
			right: 29rpx;
		}

		.pop_title {
			margin-bottom: 28rpx;
			font-size: 32rpx;
			font-weight: bold;
		}

		.pop_text {
			font-size: 28rpx;
			line-height: 50rpx;
		}

		.pop_btn {
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 90rpx auto 0;
			width: 543rpx;
			height: 100rpx;
			color: #fff;
			font-size: 32rpx;
			border-radius: 8rpx;
			background-color: #0061ff;
		}
	}
}
</style>
