<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="item.type == 'bank'?'/static/image/bank.png':
					item.type == 'wx'?'/static/image/wx.png':'/static/image/alipay.png'" style="width: 40rpx;height: 40rpx" mode="widthFix"></image>
					<view class="titleBox">
						<view class="name">{{item.type == 'bank'?item.bank:item.type == 'wx'?'微信账号':'支付宝账号'}}</view>
						<view class="tip" v-if="item.type == 'bank'">持卡人：{{item.bank_real_name}}</view>
						<view class="tip" v-else>真实姓名：{{item.name}}</view>
					</view>
				</view>
				<view class="cardNum flex_item" v-if="item.type == 'bank'">
					<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 class="cardNum flex_item" v-else>
					<view class="num">{{item.phone}}</view>
				</view>
			</view>
			<view class="tplTip flex_item" @click="edit(item.id,item.type,'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,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,item){
				if(item == 'add'){
					uni.navigateTo({
						url:'/pages/user/set/editBank'
					})
				}else{
					uni.navigateTo({
						url:'/pages/user/set/editBank?id='+id+'&type='+type
					})
				}
			}
		},
	};
</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>
