<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="handleUp">上一步</view>
			<view class="btn mt20" @click="handleSelect">去选宿舍</view>
			<view class="btn mt20" @click="handlePay">继续支付</view>
			<view class="btn jump mt20" @click="handleJump">跳过选择宿舍</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>
	</view>
</template>

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

const dataList = ref([])

const isPay = ref()

const popup_web = ref()

onLoad(() => {
	getInfo()
})

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 handleSelect = () => {
	if (isPay.value == 0) {
		uni.showToast({
			title: '未完成缴费，不可进行当前操作',
			icon: 'none'
		})
	} else if (isPay.value == 1) {
		uni.navigateTo({
			url: '/pages/select/select'
		})
	}
}

// 点击跳过按钮回调
const handleJump = () => {
	uni.showModal({
		title: '提示',
		content: '确定跳过选择宿舍前往军训服装尺码采集吗？',
		success: (res) => {
			if (res.confirm) {
				window.location.href = `https://wj.qq.com/s2/14907423/70b4/`
			}
		}
	})
}

// 继续支付按钮
const handlePay = () => {
	popup_web.value.open()
}

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: 50rpx;
	}

	.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%;
			}
		}
	}
}
</style>
