<template>
	<view class="container">
		<view class="listTpl flex" v-if="list.length > 0" v-for="item,index in list">
			<view class="infoTpl">
				<view class="tplName flex_item">
					<image src="../../../static/image/img34.png" style="width: 40rpx;height: 30rpx;position: relative;top:10rpx;" mode="widthFix"></image>
					<view class="titleBox">
						<view class="name">{{item.bank}}</view>
						<view class="tip">持卡人：{{item.bank_real_name}}</view>
					</view>
				</view>
				<view class="cardNum flex_item">
					<view class="num" v-if="!item.show">{{item.bank_code1}}</view>
					<view class="num1" v-else>{{item.bank_code}}</view>
					<view @click="showChange(index,item.show)">
						<image :src="item.show?'/static/image/img35.png':'/static/image/img36.png'" style="width: 50rpx;height: 50rpx;" mode="widthFix"></image>
					</view>
				</view>
			</view>
			<view class="tplTip flex_item" @click="edit(item.id,'edit')">
				<view class="edit">去修改</view>
				<uni-icons type="right" color="#fff"></uni-icons>
			</view>
			<view class="del" @click="del(item.id)">
				<image src="/static/image/img37.png" style="width: 32rpx;height: 32rpx;" mode="widthFix"></image>
			</view>
		</view>
		<view  class="noData" v-if="list.length == 0">暂无银行卡数据~</view>
		<view class="submission">
			<button class="golden" type="golden" hover-class="none" @click="edit(0,'add')">添加银行卡</button>
		</view>
	</view>
</template>
<script>
	import { getBank,delBank } from '@/api/set.js';
	export default {
		data() {
			return{
				list:[],
			};
		},
		onLoad() {},
		onShow() {
			this.getList()
		},
		methods: {
			showChange(index,show){
				this.list[index].show = !show
			},
			getList(){
				let obj = this
				getBank({
					page:1,
					limit:100
				}).then(res => {
					let data = res.data.list
					let reg = /^(.{4})(?:\d+)(.{4})$/
					data.forEach(item => {
						item.show = false
						item.bank_code1 = item.bank_code.replace(reg, "**** **** **** $2")
					})
					obj.list = data
				});
			},
			del(id){
				let obj = this
				uni.showModal({
					title: '提示',
					content: '您确定要删除该银行卡吗？',
					success: (res) => {
						if(res.confirm) {
							delBank({
								id:id
							}).then(res => {
								uni.showToast({
									title: res.msg,
									icon: 'none',
									duration: 1000
								})
								setTimeout(function () {
									obj.getList()
								}, 100);
							});
						} else {
							console.log('cancel') //点击取消之后执行的代码
						}
					}
				})
			},
			edit(id,type){
				if(type == 'add'){
					uni.navigateTo({
						url:'/pages/user/set/editBank'
					})
				}else{
					uni.navigateTo({
						url:'/pages/user/set/editBank?id='+id
					})
				}
			}
		},
	};
</script>
<style lang="scss" scoped>
	.container{
		padding: 25rpx 25rpx;
		
	}
	.del{
		position: absolute;
		right: 35rpx;
		top: 35rpx;
	}
	.listTpl{
		color: #fff;
		background: #1F2A4A;
		padding: 36rpx 38rpx;
		border-radius: 20rpx;
		margin-bottom: 25rpx;
		position: relative;
		.infoTpl{
			.tplName{
				align-items: flex-start;
				.titleBox{
					padding-left: 25rpx;
					.name{
						font-weight: bold;
						font-size: 30rpx;
						color: #FFFFFF;
					}
					.tip{
						font-weight: 500;
						font-size: 25rpx;
						color: rgba(255, 255, 255, 0.64);
						padding-top: 12rpx;
					}
				}
			}
			.cardNum{
				font-weight: bold;
				color: #FFFFFF;
				padding-top: 50rpx;
				padding-bottom: 20rpx;
				.num{
					margin-right: 35rpx;
					font-size: 45rpx;
				}
				.num1{
					margin-right: 35rpx;
					font-size: 38rpx;
				}
			}
		}
	}
	.noData{
		color: rgba(255, 255, 255, 0.64);
		font-size: 25rpx;
		padding: 30rpx 0rpx;
		text-align: center;
	}
	.submission {
		padding: 80rpx 25rpx;
	
		.golden {
			background: #0C5AFA;
			color: #ffffff;
		}
	}
	.edit{
		font-size: 30rpx;
	}
</style>
