<template>
	<view class="container">
		<view class="title">
		   <view>
				<text class="line"></text>银行卡号
			</view>
		   <text class="page_mark">5/8</text>
		 </view>
		 <div class="content">
		     <div class="contentDetail employ">
		       <div class="contentItem">
				 <text>开户行</text>
		         <input class="form-control" name="" placeholder="请输入" v-model="applyParam.bankAccountOpening"/>
		       </div>
		       <div class="contentItem">
					<text>银行卡号</text>
					<input class="form-control" placeholder="请输入" type="number" maxlength="19" v-model="applyParam.bankAccountId"
					 auto-blur=true @blur="checkInput(applyParam.bankAccountId)"/>
		       </div>
		       <div class="contentItem">
				 <text>再次输入银行卡号以确认</text>
		         <input class="form-control" placeholder="请输入" type="number" v-model="sureBankAccountId" maxlength="19"
				  auto-blur=true @blur="checkInput(sureBankAccountId)" />
		       </div>
		     </div>
		   </div>
		 <view class="fixed" @click="saveInfo()">
		   保存并下一步
		 </view>
	</view>
</template>

<script>
	import api from '@/api/api';
	export default{
		data(){
			return {
				sureBankAccountId:'',
				applyParam:{
					bankAccountOpening:'',
					bankAccountId:''
				}
			}
		},
		components:{},
		onLoad(){
			if(uni.getStorageSync('applyId')){
				this.queryById(uni.getStorageSync('applyId'))
			}
		},
		methods:{
			queryById(id){
				api.queryById(id).then((res)=>{
					console.log(res)
					if(res['success']){
						this.applyParam = res['data']['data'];
					}
				})
			},
			//去除输入空格
			checkInput(str){
				str = str.replace(/\s*/g,"");
			},
			saveInfo(){
				if(this.applyParam.bankAccountId || this.sureBankAccountId){
					if(this.applyParam.bankAccountId != this.sureBankAccountId){
						uni.showToast({
							title: '两次银行卡号不一致,请重新输入',
							duration: 2000,
							icon: 'none'
						})
						return;
					}
				}
				this.applyParam = {
						...this.applyParam,
						applyType:2,
						operatStep:5,
						// userId:uni.getStorageSync('cffp_userId'),
						userId:42,
						id:17
				}
				api.saveApplyInfo(this.applyParam).then((res)=>{
					if(res['success']){
						uni.navigateTo({
							// url:`personal-statement?id=${res['data']['id']}`
							url:`personal-statement`
						});
					}else{
						uni.showToast({
							title: res['message'],
							duration: 2000,
							icon: 'none'
						})
						return;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	@import 'applyCommon.scss';
</style>