<template>
	<view class="container">
		<!-- 导航栏 -->
		<view class="navbar">
			<view class="nav-left" @click="goBack">
				<text class="back-icon"><</text>
			</view>
			<view class="nav-title">我的银行卡</view>
			<view class="nav-right">
				<text class="more-icon">...</text>
				<text class="eye-icon">O</text>
			</view>
		</view>
		
		<!-- 内容区域 -->
		<scroll-view class="content" scroll-y>
			<!-- 有银行卡状态 -->
			<view v-if="bankCardData.id" 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.cardType || '储蓄卡' }}</view>
						</view>
						<view class="edit-btn" @click="goEdit">编辑银行卡</view>
					</view>
					<view class="card-number">{{ formatCardNumber(bankCardData.cardNumber) }}</view>
				</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">
					<view class="card-preview">
						<view class="card-chip"></view>
						<view class="card-strip"></view>
						<view class="card-lines">
							<view class="line line-1"></view>
							<view class="line line-2"></view>
						</view>
					</view>
				</view>
				<view class="empty-text">暂未添加银行卡</view>
				<view class="add-btn" @click="goAdd">添加银行卡</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import { getBankCardInfo } from '@/api-js/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 {
					this.bankCardData = {}
				}
			} 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 {
		background: linear-gradient(135deg, #388BFF 0%, #5BA0FF 100%);
		border-radius: 24rpx;
		padding: 48rpx 32rpx;
		margin-bottom: 32rpx;
		position: relative;
		
		.card-header {
			display: flex;
			align-items: flex-start;
			justify-content: space-between;
			margin-bottom: 60rpx;
			
			.bank-info {
				.bank-name {
					font-size: 32rpx;
					font-weight: bold;
					color: #fff;
					margin-bottom: 8rpx;
				}
				
				.card-type {
					font-size: 24rpx;
					color: rgba(255, 255, 255, 0.8);
				}
			}
			
			.edit-btn {
				padding: 8rpx 24rpx;
				background: rgba(255, 255, 255, 0.9);
				border: 2rpx solid #388BFF;
				border-radius: 44rpx;
				font-size: 24rpx;
				color: #388BFF;
			}
		}
		
		.card-number {
			font-size: 48rpx;
			font-weight: bold;
			color: #fff;
			letter-spacing: 4rpx;
		}
	}
	
	.notes-section {
		background: #fff;
		border-radius: 16rpx;
		padding: 32rpx;
		
		.notes-title {
			font-size: 28rpx;
			font-weight: bold;
			color: #333;
			margin-bottom: 16rpx;
		}
		
		.notes-item {
			font-size: 26rpx;
			color: #666;
			line-height: 1.8;
			margin-bottom: 8rpx;
			
			&:last-child {
				margin-bottom: 0;
			}
		}
	}
}

.empty-section {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 120rpx 24rpx;
	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>


