<template>
	<view class="container">
		<view class="login_text">
			<view class="login_input flex" style="padding-top: 45rpx;">
				<view class="login_name">姓名</view>
				<view class="login_name"><input class="uni-input" type="text" v-model="info.bank_real_name"
						placeholder="请输入真实姓名" /></view>
			</view>
			<view class="login_input flex">
				<view class="login_name"><text>银行</text></view>
				<view class="login_name"><input class="uni-input" type="idcard" v-model="info.bank"
						placeholder="请输入银行" /></view>
			</view>
			<view class="login_input flex">
				<view class="login_name"><text>银行卡账号</text></view>
				<view class="login_name"><input class="uni-input" type="idcard" v-model="info.bank_code"
						placeholder="请输入银行卡账号" /></view>
			</view>
			<view class="login_input flex">
				<view class="login_name"><text>开户行</text></view>
				<view class="login_name"><input class="uni-input" type="idcard" v-model="info.bank_name"
						placeholder="请输入开户行" /></view>
			</view>
		</view>
		<view class="submission">
			<button class="golden" type="golden" hover-class="none" @click="submission">确认</button>
		</view>
	</view>
</template>
<script>
	import { bankInfo,addBank } from '@/api/set.js';
	export default {
		data() {
			return{
				info:{
					id:'',
					bank_real_name:'',
					bank_code:'',
					bank:'',
					bank_name:'',
					default:0
				}
			};
		},
		onLoad(option) {
			if(option.id){
				this.info.id = option.id
				this.getList()
			}
			// getMoneyLog({
			// 		page: navItem.page,
			// 		limit: navItem.limit
			// 	},navItem.type)
		},
		onShow() {},
		methods: {
			getList(){
				let obj = this
				bankInfo({
					id:obj.info.id
				}).then(res => {
					obj.info = res.data.info
				});
			},
			submission(){
				let obj = this
				if(!obj.info.bank_real_name){
					uni.showToast({
						title: '请输入真实姓名',
						icon: 'none',
					})
					return
				}
				if(!obj.info.bank){
					uni.showToast({
						title: '请输入银行',
						icon: 'none',
					})
					return
				}
				if(!obj.info.bank_code){
					uni.showToast({
						title: '请输入银行卡号',
						icon: 'none',
					})
					return
				}
				if(obj.info.bank_code.length < 16){
					uni.showToast({
						title: '请输入正确的银行卡号',
						icon: 'none',
					})
					return
				}
				if(!obj.info.bank_name){
					uni.showToast({
						title: '请输入开户行',
						icon: 'none',
					})
					return
				}
				let data = ''
				if(obj.info.id){
					data = {
						bank:obj.info.bank,//银行
						bank_name:obj.info.bank_name,//开户行
						bank_code:obj.info.bank_code,//银行卡号
						real_name:obj.info.bank_real_name,//开户人
						default:0,//1设为默认，0取消默认
						id:obj.info.id
					}
				}else{
					data = {
						bank:obj.info.bank,//银行
						bank_name:obj.info.bank_name,//开户行
						bank_code:obj.info.bank_code,//银行卡号
						real_name:obj.info.bank_real_name,//开户人
						default:0,//1设为默认，0取消默认
					}
				}
				addBank(data).then(res => {
					uni.showToast({
						title: res.msg,
						icon: 'none',
						duration: 1000
					})
					setTimeout(function () {
						uni.navigateTo({
							url:'/pages/user/set/bindBank'
						})
					}, 1000);
				});
			},
		},
	};
</script>
<style lang="scss" scoped>
	.login_text {
		width: 100%;
		// padding: 25rpx 0rpx;
		font-size: 28rpx !important;
		padding: 0rpx 25rpx;
	}
	
	.login_input {
		border-bottom: 1px solid #464755;
		padding: 35rpx;
	}
	.uni-input {
		width: 450rpx;
		text-align: left !important;
		font-size: 26rpx;
	}
	.submission {
		padding: 80rpx 25rpx;
	
		.golden {
			background: #0C5AFA;
			color: #ffffff;
		}
	}
	
	.login_name {
		color: #ffffff;
	}
</style>
