<style lang="scss">
	.bank-list{
		background: #fff;
		border-radius: 10px;
		margin: 10px;
	
		.item {
			border-bottom: 1px solid #f1f1f1;
			padding: 32rpx 28rpx;
			.icon{width: 40rpx;height: 40rpx;margin-right: 25rpx;}
			.name{font-weight: 500;font-size: 26rpx;color: #333333;}
			.bank_name{font-weight: 500;font-size: 26rpx;color: #999999;}
			.pev{width: 40rpx;height: 40rpx;}
		}
	}
</style>
<template>
	<view class="app-body">
		<view class="bank-list">
			
			<view class="item fx-r" @tap="tapOpen" data-url="save/bank">
				<image class="icon" src="/static/img/bank_bank.png"></image>
				<view class="name">银行卡</view>
				<view class="fx-g1"></view>
				<view class="bank_name">{{ getBank(3) || '未添加' }}</view>
				<image class="pev" src="/static/img/ic_next.png"></image>
			</view>
			
			<view class="item fx-r"  @tap="tapOpen" data-url="save/alipay">
				<image class="icon" src="/static/img/bank_alipay.png"></image>
				<view class="name">支付宝</view>
				<view class="fx-g1"></view>
					<view class="bank_name">{{ getBank(2) || '未添加' }}</view>
				<image class="pev" src="/static/img/ic_next.png"></image>
			</view>
			
			<view class="item fx-r"  @tap="tapOpen" data-url="save/weixin">
				<image class="icon" src="/static/img/bank_weixin.png"></image>
				<view class="name">微信</view>
				<view class="fx-g1"></view>
				<view class="bank_name">{{ getBank(1) || '未添加' }}</view>
				<image class="pev" src="/static/img/ic_next.png"></image>
			</view>
			
			
		</view>
		
	</view>
</template>

<script>
	import {mapState,mapMutations} from 'vuex';
	export default {
		computed: mapState(['user']),
		data() {
			return {
				data	 : [],
				isFirst  : false
			}
		},
		onShow() {
			this.getData();
		},
		methods: {
			//获取事件传递
			onEvent:function(type,data){
				this.getData();
			},
			getData:function(){
				this
					.request
					.post("getBank")
					.then(res=>{
						if(res.code == 200) {
							this.data = res.data
							this.isFirst = true;
						} else {
							this.utils.Tip(res.msg);
						}
					})
					.catch(err=>{
						this.utils.Tip(res.msg);
					});
			},
			tapBack: function() {
				uni.navigateBack();
			},
			
			getBank:function(type) {
				for(let i in this.data) {
					if(this.data[i].type == type) {
						return this.data[i].name;
					}
				}	
				
				return null;
			},
			
			/**
			 * 打开
			 * @param {Object} ev
			 */
			tapOpen: function(ev) {
				let url = ev.currentTarget.dataset.url
				uni.navigateTo({
					url: url
				});
			}
			
			
		}
	}
</script>

