<template>
	<view class="content">
		<block v-if="listsArr.length > 0">
			<image class="indexTop" src="/static/index_top.png" mode="scaleToFill"></image>
			<view class="indexTips">
				<view class="indexTips-name">计算历史记录</view>
				<view class="indexTips-text">根据您填写的内容生成以下结果</view>
				<view class="indexTips-text">详细业务请联系您的推荐人</view>
			</view>
			<view class="indexCont">
				<view class="indexCont-white" v-for="(item, index) in listsArr" :key="index">
					<view class="resultTitle">
						{{item.institution}}
					</view>
					<view class="resultList">
						<view class="item">
							<view class="item-label">
								<view class="item-label-name">
									欠款金额：
								</view>
								<view class="item-label-text">
									{{item.total}}元
								</view>
							</view>
							<view class="item-label">
								<view class="item-label-name">
									首付金额：
								</view>
								<view class="item-label-text" v-if="item.base">
									{{item.base.first_amount}}元
								</view>
							</view>
							<view class="item-label">
								<view class="item-label-name">
									分期金额：
								</view>
								<view class="item-label-text" v-if="item.base">
									{{item.base.periods_amount}}元
								</view>
							</view>
							<view class="item-label">
								<view class="item-label-name">
									分期期数：
								</view>
								<view class="item-label-text" v-if="item.base">
									{{item.base.periods}}期
								</view>
							</view>
							<view class="item-label">
								<view class="item-label-name">
									手续费费率：
								</view>
								<view class="item-label-text" v-if="item.base">
									{{item.base.tax}}%
								</view>
							</view>
							<view class="item-label">
								<view class="item-label-name">
									每期还款本金：
								</view>
								<view class="item-label-text" v-if="item.base">
									{{item.base.every_total}}元
								</view>
							</view>
							<view class="item-label">
								<view class="item-label-name">
									每期还款手续费：
								</view>
								<view class="item-label-text" v-if="item.base">
									{{item.base.every_tax}}元
								</view>
							</view>
							<view class="item-label">
								<view class="item-label-name">
									总还款金额：
								</view>
								<view class="item-label-text" v-if="item.base">
									{{item.base.total}}元
								</view>
							</view>
							<view class="item-label">
								<view class="item-label-name">
									总还款本金：
								</view>
								<view class="item-label-text" v-if="item.base">
									{{item.base.principal}}元
								</view>
							</view>
							<view class="item-label">
								<view class="item-label-name">
									总还款手续费：
								</view>
								<view class="item-label-text" v-if="item.base">
									{{item.base.tax_amount}}元
								</view>
							</view>
						</view>
						<view class="tips">温馨提示：{{item.description}}</view>
						<view class="see">
							<view class="see-go" @click="generalClick(item)">点击查看还款计划表</view>
						</view>
					</view>
				</view>
			</view>
		</block>
		<view class="pack-center pages-hint" v-else>
		    <image src="https://cdn.shuiganying.com/images/2023/04/04/40b2f4bfe2dfb828688fcd3766d6b541.png"></image>
		    <view class="reportTips">
		        <view class="reportTips-title">暂无数据</view>
		        <view class="reportTips-text">抱歉，暂没有历史记录</view>
		    </view>
		</view>
		
		<!-- 还款计划表弹出 -->
		<view class="tipsBack" v-if="generalShow" :catchtouchmove="true"></view>
		<view class="tipsCont" v-if="generalShow" :catchtouchmove="true">
			<view class="tipsWhite">
				<view class="tipsTitle">还款计划表（单位：元）</view>
				<view class="tipsList">
					<view class="tipsList-tab">
						<view class="tips-tab-item">期数</view>
						<view class="tips-tab-item">还款金额</view>
						<view class="tips-tab-item">本金</view>
						<view class="tips-tab-item">手续费</view>
					</view>
					<view class="tipsList-data">
						<view class="tipsList-label" v-for="(items, index) in timeArr" :key="index">
							<view class="tips-label-item">第{{index+1}}期</view>
							<view class="tips-label-item">{{items.total}}</view>
							<view class="tips-label-item">{{items.principal}}</view>
							<view class="tips-label-item">{{items.tax}}</view>
						</view>
						<view class="tipsList-label">
							<view class="tips-label-item">合计</view>
							<view class="tips-label-item">{{timeAll.total}}</view>
							<view class="tips-label-item">{{timeAll.principal}}</view>
							<view class="tips-label-item">{{timeAll.tax}}</view>
						</view>
					</view>
				</view>
				<view class="tipsWhite-btn">
					<view @click="otherSee" class="tipsWhite-btn-go">
						其他还款方式
					</view>
				</view>
				<image class="close" @click="generalShow = false" src="/static/close.png" mode="widthFix"></image>
			</view>
		</view>
	
		<!-- 数据缓冲阶段 -->
		<view class="pack-center pages-hint grey" v-if="paySuccess">
		    <image src="/static/loadingGif.gif"></image>
		    <view>加载中...</view>
		</view>
	</view>
</template>

<script>
	import { Lists } from '@/apis/interfaces/index'
	export default {
		data() {
			return {
				listsArr   : [], // 结果列表
				timeArr    : [], // 还款计划表列表
				timeAll    : '', // 还款计划表总计
				otherArr   : '', // 其他携带数据
				userId     : '',
				generalShow: false,
				paySuccess : true,
			}
		},
		onLoad(options) {
			this.userId = options.user_id
		},
		onShow() {
			// 获取历史结果
			this.listsInfo()
		},
		
		methods: {
			// 历史结果
			listsInfo() {
				Lists({
					user_id: this.userId
				}).then(res => {
					this.paySuccess = false
					this.listsArr = res
				}).catch(err => {
					uni.showToast({
						title: err.message,
						icon: "none" 
					})
				})
			},
			
			// 查看还款计划表
			generalClick(arr){
				this.otherArr    = arr
				this.timeArr     = arr.project
				this.timeAll     = arr.project_total
				this.generalShow = !this.generalShow
			},
			
			// 其他方式
			otherSee() {
				let newData = JSON.stringify(this.otherArr);
				uni.navigateTo({
					url: `/pages/result/other?data=${encodeURIComponent(newData)}`
				})
				
				this.generalShow = false
			}
		}
	}
</script>

<style>
	.indexTop {
		width: 100%;
		height: 440rpx;
	}
	
	.indexTips {
		position: absolute;
		top: 0;
		left: 0;
		padding: 60rpx 40rpx 0;
		box-sizing: border-box;
		color: #fff;
	}
	
	.indexTips-name {
		font-weight: 600;
		font-size: 44rpx;
	}
	
	.indexTips-text {
		margin-top: 20rpx;
		font-size: 28rpx;
	}
	
	.indexCont {
		width: 100%;
		padding: 30rpx;
		box-sizing: border-box;
		position: absolute;
		margin-top: 240rpx;
		top: 0;
		left: 0;
	}
	
	.indexCont-white {
		height: 100%;
		background: white;
		border-radius: 20rpx;
		padding: 30rpx;
		box-sizing: border-box;
		margin-bottom: 30rpx;
	}
	
	.resultTitle {
		font-weight: 600;
		font-size: 34rpx;
		color: #0c58d2;
		margin-bottom: 20rpx;
	}
	
	.item-label {
		line-height: 48rpx;
		padding: 15rpx 0;
		display: flex;
		margin-right: 20rpx;
		font-weight: 400;
	}
	
	.item-label-name {
		color: #999999;
	}
	
	.textShadow {
		filter: blur(6px);
	}
	
	.tips {
		font-weight: 400;
		background-color: #f7faff;
		border-radius: 10rpx;
		padding: 20rpx 30rpx;
		text-align: justify;
		box-sizing: border-box;
		font-size: 26rpx;
		color: #999999;
		line-height: 40rpx;
		margin-top: 20rpx;
	}
	
	.see {
		text-align: center;
		margin-top: 30rpx;
	}
	
	.see-go {
		display: inline-block;
		border: 2rpx solid #0c58d2;
		color: #0c58d2;
		line-height: 74rpx;
		padding: 0 25rpx;
		border-radius: 10rpx;
	}
	
	.indexLock {
		width: 34rpx;
		vertical-align: -4rpx;
		margin-right: 10rpx;
	}
	
	
	/* 计划表弹出 */
	.tipsBack {
		position: fixed;
		width: 100vw;
		height: 100vh;
		left: 0;
		top: 0;
		z-index: 9;
		background-color: rgba(0, 0, 0, .6);
	}
	.tipsCont {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-box-pack: center;
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		z-index: 10;
		padding: 0 10%;
		box-sizing: border-box;
		text-align: center;
	}
	
	.tipsWhite {
		background-color: #ffffff;
		border-radius: 20rpx;
		padding: 30rpx;
		box-sizing: border-box;
		position: relative;
	}
	
	.close {
		position: absolute;
		left: calc(50% - 35rpx);
		width: 70rpx;
		bottom: -120rpx;
		z-index: 999;
	}
	
	.tipsTitle {
		font-weight: 600;
		font-size: 34rpx;
	}
	
	.tipsList {
		margin: 20rpx 0;
		font-size: 28rpx;
		font-weight: 400;
	}
	
	.tipsList-tab {
		display: flex;
		background: #e5edf8;
		line-height: 90rpx;
		border-radius: 20rpx 20rpx 0 0;
	}
	
	.tips-tab-item, .tips-label-item {
		flex: 4;
		text-align: center;
	}
	.tipsList-data {
		background: #fafafa;
		border-radius: 0 0 20rpx 20rpx;
		max-height: 30vh;
		overflow: hidden;
		overflow-y: scroll;
	}
	.tipsList-label {
		display: flex;
		line-height: 80rpx;
		border-bottom: 2rpx solid #eeeeee;
	}
	
	.tipsList-label:last-child {
		border: none;
	}
	
	.tipsWhite-btn {
		text-align: center;
		padding: 30rpx 0 20rpx;
	}
	
	.tipsWhite-btn-go {
		display: inline-block;
		width: 70%;
		line-height: 88rpx;
		border-radius: 80rpx;
		background-color: #0c58d2;
		color: #fff;
	}
	
	.postertBack {
	    width: 100vw;
	    height: 100vh;
	    position: fixed;
	    background-color: rgba(0,0,0,.6);
	    left: 0;
	    top: 0;
	    z-index: 999;
	}
	
	.postertCont {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-box-pack: center;
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		z-index: 1000;
		padding: 0 10%;
		box-sizing: border-box;
	}
	
	.postertContTop {
		top: -200rpx;
	}
	
	.poster-back {
		position: relative;
		padding-top: 100%;
		width: 100%;
	}
	
	.poster-img, .poster-Cont {
		position: absolute;
		width: 100%;
		height: 100%;
		left: 0;
		top: 0;
	}
	
	.poster-Cont {
		padding: 50rpx;
		box-sizing: border-box;
		color: #fff;
	}
	
	.poster-Cont-code {
		background: #fff;
		border-radius: 20rpx;
		padding: 30rpx;
		box-sizing: border-box;
	}
	
	.poster-Cont-code image {
		width: 100%;
	}
	
	.poster-Cont-url {
		display: flex;
		padding: 30rpx 0 40rpx;
	}
	
	.poster-url-number {
		flex: 1;
		padding-right: 20rpx;
		box-sizing: border-box;
	}
	
	.poster-url-copy {
		font-weight: 600;
	}
	
	.poster-Cont-btn {
		text-align: center;
	}
	
	.poster-Cont-down {
		display: inline-block;
		width: 80%;
		background-color: #fff;
		border-radius: 80rpx;
		line-height: 90rpx;
		color: #051437;
		font-weight: 600;
	}
	
	.poster-Cont-down-img {
		width: 40rpx;
		margin-left: 15rpx;
		vertical-align: -8rpx;
		animation: bounce-down 2s linear infinite;
	}
	
	
	@keyframes bounce-down {
	    25% {
	        transform: translateX(-4px);
	    }
	
	    50%,
	    100% {
	        transform: translateX(0);
	    }
	
	    75% {
	        transform: translateX(4px);
	    }
	}
	
	.sign-img-btn {
		position: absolute;
		left: calc(50% - 35rpx);
		width: 70rpx;
		top: calc(100% + 240rpx);
		z-index: 999;
	}
	
	.poster-img-btn {
		width: 70rpx;
		display: block;
		margin: 30rpx auto 0;
	}
	
	/* 暂无数据 */
	.reportTips-title {
	    color: #000;
	    font-size: 34rpx;
	    line-height: 80rpx;
	}
	
	.reportTips-text {
	    font-size: 26rpx;
	}
	
	.reportTips-btn {
	    background-color: #3b7cff;
	    display: inline-block;
	    color: #fff;
	    line-height: 78rpx;
	    padding: 0 60rpx;
	    border-radius: 10rpx;
	    margin-top: 50rpx;
	}
	
	.pack-center {
		z-index: 99999;
	}
	
	.grey {
	    background-color: #f9f9f9;
	    z-index: 9999999;
	}
</style>