<template>
	<view class="page">
		<view class="bankClass dis a-start" v-for="(item,index) in cardPackList" :key="item.id">
			<view class="top ">
				<view class="bankLogo">
					<image src="../../static/icon/bjdcar.png" mode=""></image>
				</view>
			</view>
			<view class="botn dis f-c a-s j-s">
				<view class="bankName dis f-c ">
					<text>{{item.bankAccount}}</text>
					<text>储蓄卡</text>
				</view>
				<text>···· ···· ···· {{item.bankNumber.slice(-4)}}</text>
			</view>
			<view style="margin-left: auto;" @click="delbankCard(item.id)">
				<u-icon name="trash-fill" color="#fff" size="50"></u-icon>
			</view>
		</view>
		<view class="bankClassadd dis a-c" @click="getbankCard">
			<u-icon name="plus" color="#000" size="40"></u-icon>
			<text style="margin-left: 10px;">添加银行卡</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cardPackList: [],
			}
		},
		onShow() {
			this.getcardPack(); //获取卡包
		},
		onLoad() {
			this.getcardPack(); //获取卡包
		},
		methods: {
			async getcardPack() {
				let res = await this.$http.get('/userBank/getUserBankList');
				if (res.code == '200' && res.data) {
					this.cardPackList = res.data;
				}
			},
			getbankCard() {
				this.navigate({
					url: '/pages/wallet/bindBank',
				}, "navigateTo", true)
			},
			async delbankCard(id) {
				let res = await this.$http.delete('/userBank/' + id);
				if (res.code == '200') {
					this.getcardPack();
					uni.showToast({
						title: res.msg,
						duration: 2000,
						icon: "success"
					});
				}

			},
		},
	}
</script>

<style>
	page {
		background-color: #f2f2f2;
	}

	.page {
		padding: 10px 10px 50px;
	}

	.bankClass,
	.bankClassadd {
		width: 100%;
		height: 120px;
		background-color: #c65255;
		border-radius: 6px;
		padding: 14px;
		margin-top: 16px;

		.top {
			margin-top: 4px;
		}

		.bankLogo {
			width: 30px;
			height: 30px;
			background-color: #f0cdcb;
			border-radius: 50%;
			padding: 4px;
			box-sizing: border-box;
			margin-right: 10px;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.botn {
			.bankName {
				text {
					font-size: 16px;
					color: #fff;
				}

				text:last-child {
					font-size: 12px;
					color: #ffffffb5;
				}
			}

			text {
				font-size: 24px;
				font-weight: bold;
				color: #fff;
			}
		}

	}

	.bankClassadd {
		background-color: #fff;
		height: 70px;
	}
</style>