<template>
	<view class="container">
		<!-- 内容区域 -->
		<scroll-view class="content" scroll-y>
			<!-- 有银行卡状态 -->
			<view v-if="bankCardData.bankCardNo" class="card-section">
				<view class="bank-card">
					<view class="card-header">
						<view class="bank-info">
							<view class="bank-name">{{ bankCardData.bankName || '' }}</view>
							<view class="card-type">{{ bankCardData.bankBranch || '储蓄卡' }}</view>
						</view>
						<view class="edit-btn" @click="goEdit">编辑银行卡</view>
					</view>
					<view class="card-number">{{ formatCardNumber(bankCardData.bankCardNo) }}</view>
					<image class="w270 h320" src="@/static/image/bg_bankcard.png" mode=""></image>
				</view>
				
				<!-- 注意事项 -->
				<view class="notes-section">
					<view class="notes-title">注意:</view>
					<view class="notes-item">1、只能绑定认证用户本人的银行卡;</view>
					<view class="notes-item">2、每次更换次数不得超过三次。</view>
				</view>
			</view>
			
			<!-- 空状态 -->
			<view v-else class="empty-section">
				<view class="empty-card-illustration">
					<image class="w322 h198" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/images/img_nocard.png" mode=""></image>
				</view>
				<view class="empty-text">暂未添加银行卡</view>
				<view class="add-btn" @click="goAdd">添加银行卡</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import { getBankCardInfo } from '@/api/bankCard'
export default {
	data() {
		return {
			bankCardData: {}
		}
	},
	onLoad() {
		//this.loadBankCardData()
	},
	onShow() {
		// 从编辑/添加页面返回时刷新数据
		this.loadBankCardData()
	},
	methods: {
		async loadBankCardData() {
			try {
				uni.showLoading({ title: '加载中...' })
				const res = await getBankCardInfo()
				uni.hideLoading()
				if (res.code === 200 && res.data) {
					this.bankCardData = res.data
				} else {
					uni.showToast({
						icon: 'none',
						title: res.msg
					})
				}
			} catch (e) {
				uni.hideLoading()
				console.error('加载银行卡信息失败', e)
				this.bankCardData = {}
			}
		},
		formatCardNumber(cardNumber) {
			if (!cardNumber) return ''
			if (cardNumber.length < 4) return cardNumber
			// 显示最后4位，其他用*代替
			const lastFour = cardNumber.substring(cardNumber.length - 4)
			return `**** **** **** ${lastFour}`
		},
		goBack() {
			uni.navigateBack()
		},
		goAdd() {
			uni.navigateTo({
				url: '/pages_user/addBankCard'
			})
		},
		goEdit() {
			uni.navigateTo({
				url: '/pages_user/editBankCard?id=' + this.bankCardData.id
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.container {
	min-height: 100vh;
	background: #fff;
	display: flex;
	flex-direction: column;
}

.navbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 20rpx 24rpx;
	background: #fff;
	border-bottom: 1rpx solid #f0f0f0;
	position: sticky;
	top: 0;
	z-index: 100;
	
	.nav-left {
		width: 60rpx;
		
		.back-icon {
			font-size: 36rpx;
			color: #333;
			font-weight: bold;
		}
	}
	
	.nav-title {
		flex: 1;
		text-align: center;
		font-size: 36rpx;
		font-weight: bold;
		color: #333;
	}
	
	.nav-right {
		display: flex;
		align-items: center;
		gap: 24rpx;
		width: 60rpx;
		justify-content: flex-end;
		
		.more-icon {
			font-size: 32rpx;
			color: #333;
		}
		
		.eye-icon {
			font-size: 32rpx;
			color: #333;
		}
	}
}

.content {
	flex: 1;
	background: #f5f5f5;
}

.card-section {
	padding: 24rpx;
	
	.bank-card {
		width: 702rpx;
		height: 320rpx;
		box-sizing: border-box;
		background: linear-gradient( 71deg, #388BFF 0%, #0C75FF 100%);
		border-radius: 24rpx 24rpx 24rpx 24rpx;
		padding: 40rpx;
		margin-bottom: 32rpx;
		position: relative;
		image{
			position: absolute;
			top:0;
			right: 0;
			z-index: 0;
		}
		.card-header {
			display: flex;
			align-items: flex-start;
			justify-content: space-between;
			margin-bottom: 60rpx;
			position: relative;
			z-index: 1;
			.bank-info {
				.bank-name {
					font-family: PingFang SC, PingFang SC;
					font-weight: 600;
					font-size: 32rpx;
					color: #FFFFFF;
					margin-bottom: 16rpx;
				}
				
				.card-type {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #fff;
				}
			}
			
			.edit-btn {
				width: 220rpx;
				height: 64rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background: rgba(255,255,255,0.2);
				border-radius: 34rpx 34rpx 34rpx 34rpx;
				border: 2rpx solid #FFFFFF;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #FFFFFF;
			}
		}
		
		.card-number {
			font-family: PingFang SC, PingFang SC;
			font-weight: 600;
			font-size: 48rpx;
			color: #FFFFFF;
		}
	}
	
	.notes-section {
		padding: 32rpx;
		
		.notes-title {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #999999;
			line-height: 40rpx;
		}
		
		.notes-item {
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			font-size: 28rpx;
			color: #999999;
			line-height: 40rpx;
		}
	}
}

.empty-section {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding:0 24rpx;
	margin-top: 140rpx;
	// min-height: 60vh;
	
	.empty-card-illustration {
		margin-bottom: 48rpx;
		
		.card-preview {
			width: 600rpx;
			height: 360rpx;
			background: linear-gradient(135deg, #388BFF 0%, #5BA0FF 100%);
			border-radius: 24rpx;
			position: relative;
			padding: 48rpx 32rpx;
			
			.card-chip {
				width: 60rpx;
				height: 48rpx;
				background: #FFC107;
				border-radius: 8rpx;
				margin-bottom: 32rpx;
			}
			
			.card-strip {
				width: 200rpx;
				height: 40rpx;
				background: rgba(255, 255, 255, 0.3);
				border-radius: 8rpx;
				position: absolute;
				top: 32rpx;
				right: 32rpx;
			}
			
			.card-lines {
				margin-top: 32rpx;
				
				.line {
					height: 24rpx;
					background: rgba(255, 255, 255, 0.6);
					border-radius: 4rpx;
					margin-bottom: 16rpx;
					
					&.line-1 {
						width: 400rpx;
					}
					
					&.line-2 {
						width: 280rpx;
					}
				}
			}
		}
	}
	
	.empty-text {
		font-size: 28rpx;
		color: #999;
		margin-bottom: 48rpx;
	}
	
	.add-btn {
		width: 100%;
		max-width: 600rpx;
		height: 88rpx;
		background: #388BFF;
		border-radius: 44rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 32rpx;
		font-weight: bold;
		color: #fff;
	}
}
</style>













