<template>
	<view class="content">
		<view class="top">
			<view class="base">
				<view class="base-tab">
					<view class="base-tab-item">
						<image class="base-tab-img" src="/static/icon//bankIcon_01_active.png" mode="aspectFill"></image>
						<view class="base-tab-cont">
							<view class="base-tab-name">
								银行信息
							</view>
							<view class="base-tab-tips" @click="$Router.replace({name: 'ModifyBank', params: {id: baseId}})">
								去完善 >
							</view>
						</view>
					</view>
					<view class="base-tab-spot">
						<text></text>
						<text></text>
						<text></text>
					</view>
					<view class="base-tab-item">
						<image class="base-tab-img" src="/static/icon/bankIcon_02.png" mode="aspectFill"></image>
						<view class="base-tab-cont">
							<view class="base-tab-name">
								其他信息
							</view>
							<view class="base-tab-tips">
								待完善
							</view>
						</view>
					</view>
				</view>
				
				<view class="white">
					<view class="base-title">
						<view class="base-name">
							基本信息
						</view>
						<!-- <view class="base-number">
							6/12
						</view> -->
					</view>
					<view class="base-list">
						<view class="base-block" :class="{baseAline : items.type === 'text' || items.type === 'textarea' }" v-for="(items, itemsIndex) in backParams" :key="itemsIndex">
							<view class="base-block-name" v-if="items.label == 2">
								<text>*</text>{{items.title}}
								<image class="base-notesIcon" v-if="items.reason != ''" @click="seeTips('驳回原因', items.reason.description)" src="/static/icon/notesIcon.png" mode="aspectFill"></image>
							</view>
							
							<!-- 描述 -->
							<block v-if="items.label == 2">
								<view class="base-block-textarea" v-if="items.type === 'textarea'">
									<mouldText class="idcardAdd-depict-textarea" :blur-placeholder="items.placeholder" :blur-value="items.value" @onTextarea="($event) => {items.value = $event}"></mouldText>
								</view>
							</block>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="introduce-btn">
			<view @click="$Router.replace({name: 'ModifyBank', params: {id: baseId}})" class="btn" size="mini">上一步</view>
			<button class="btn" size="mini" :disabled="disabled" @click="infoSubmit">提交审核</button>
		</view>
		
		<!-- 驳回提示 -->
		<mouldTips :see-data="seeData" @tipsClose="($event) => {seeData.seeShow = $event}"></mouldTips>
	</view>
</template>

<script>
	import { userBank, cacheBank, bankPut, cacheBankPut } from '@/apis/interfaces/user'
	
	import mouldCheckbox from '@/components/mould-checkbox.vue'
	import mouldInput from '@/components/mould-input.vue'
	import mouldRadio from '@/components/mould-radio.vue'
	import mouldText from '@/components/mould-text.vue'
	import mouldSelect from '@/components/mould_select.vue'
	import mouldDate from '@/components/mould-date.vue'
	import mouldTips from '@/components/mould-tips.vue'
	export default {
		components: {
			mouldCheckbox,
			mouldInput,
			mouldRadio,
			mouldText,
			mouldSelect,
			mouldDate,
			mouldTips
		},
		data() {
			return {
				baseId    : '', // 银行id
				businessId: '',
				disabled  : false, // 按钮状态
				backParams: '', // 基础信息
				
				// 查看提示组件
				seeData     : {
					seeShow : false,
					seeTitle: '',  
					seeText : '',
				},
				
				values   : '',
				
				marriage: [],
				marriageIndex : 0,  // 婚姻选择index
				
				education: [],
				educationIndex: 0,  // 学历选择index
				
				cacheData: [] ,//缓存数据
			}
		},
		
		onShow() {
			this.baseId = this.$Route.query.id

			// 获取基础信息
			this.baseInfo();
		},
		
			
		methods: {
			// 基础信息
			baseInfo() {
				uni.showLoading({
					title: '加载中...',
					mask : true
				})
				userBank(this.$Route.query.id).then(res => {
					// 是否使用首次录入信息
					// if(res.is_finish == 0 && res.user_bank) {
					// 	this.popFirst = true
					// 	this.baseId   = res.user_bank.user_bank_id
					// }
					
					let { item, params, business_order_user_bank_id } = res;
					cacheBank(business_order_user_bank_id).then(StorageRes => {
						this.userId = res.business_order_user_bank_id
						uni.hideLoading()
						if(StorageRes === ''){
							this.backParams = params
							return
						}
						let storageParams = []
						storageParams = params.map(val => {
							if(val.type == 'checkbox' && StorageRes[val.key].length > 0){
								val.value = StorageRes[val.key]
								return val
							}
							if(val.type == 'select' && StorageRes[val.key] === null){
								val.value = 0
								return val
							}
							val.value = StorageRes[val.key] === null ? "" : StorageRes[val.key]
							return val;
						})
						this.backParams = storageParams
						
					}).catch(StorageErr => {
						uni.showToast({
							title: StorageErr.message,
							icon : 'none'
						})
					})
				}).catch( err => {
					uni.showToast({
						title: err.message,
						icon: "none"
					})
				})
			},
			
			// 线上保存 - 缓存
			cacheSave() {
				let SaveArr = new Object;
				this.backParams.map(val => {
					SaveArr[val.key] = val.value
				})
				
				cacheBankPut(this.$Route.query.id, {...SaveArr}).then(res => {}).catch( err => {
					uni.showToast({
						title: err.message,
						icon: "none"
					})
				})
			},
			
			
			// 提交信息
			infoSubmit() {
				let SaveArr = this.backParams.map(val => {
					return {
						key: val.key,
						value: val.value
					}
				})
				
				bankPut(this.$Route.query.id, {
					data: SaveArr
				}).then(res => {
					// 保存
					this.cacheSave();
					
					uni.showToast({
						title: res,
						icon: "none"
					})
					this.disabled = true
					setTimeout(() => {
						this.$Router.replace({name: 'User'})
						uni.hideLoading() 
						// uni.removeStorage({//通过key（键值名）来删除对应数据
						// 	key:"saveArr" + this.$Route.query.id,
						// 	success() {}
						// })
					}, 1500)
				}).catch( err => {
					uni.showToast({
						title: err.message,
						icon: "none"
					})
				})
			},
			
			// 提示组件 -- 赋值
			seeTips(title, text) {
				this.seeData.seeShow = true
				this.seeData.seeTitle = title
				this.seeData.seeText = text
			},
		}
	}
</script>

<style lang="scss" scoped>
	.top {
		background-color: #f5f5f5;
		border-bottom: transparent 140rpx solid;
		position: relative;
		height: 100vh;
		overflow-y: scroll;
		&::after {
			content: '';
			position: absolute;
			background-color: $mian-color;
			border-radius: 0 0 $radius*5 $radius*5;
			width: 100%;
			height: 260rpx;
			left: 0;
			top: 0;
		}
		.base {
			position: absolute;
			z-index: 9;
			padding: $padding + 20 $padding;
			box-sizing: border-box;
			.base-tab {
				overflow: hidden;
				display: flex;
				padding: 0 $padding 20rpx 10rpx;
				position: relative;
				.base-tab-item {
					color: #ffffff;
					position: relative;
					display: flex;
					.base-tab-img {
						width: 120rpx;
						height: 120rpx;
					}
					.base-tab-cont {
						padding-top: $padding - 15;
						box-sizing: border-box;
						.base-tab-name {
							font-size: $title-size-sm;
						}
						.base-tab-tips {
							font-size: $title-size-sm - 2;
							border: 2rpx solid #ffeaea;
							border-radius: $radius * 4;
							width: 110rpx;
							text-align: center;
							opacity: .8;
							margin-top: 10rpx;
						}
					}
				}
				.base-tab-spot {
					text-align: center;
					width: 180rpx;
					float: left;
					margin-top: $margin;
					text {
						border-radius: 50%;
						background-color: #ffffff;
						display: inline-block;
						margin-left: 15rpx;
						&:nth-child(1) {
							width: 10rpx;
							height: 10rpx;
							opacity: .5;
						}
						&:nth-child(2) {
							width: 14rpx;
							height: 14rpx;
							opacity: .8;
						}
						&:nth-child(3) {
							width: 16rpx;
							height: 16rpx;
						}
					}
				}
			}
			
			.white {
				padding: $padding;
				box-sizing: border-box;
				background-color: #ffffff;
				border-radius: $radius-m;
				overflow: hidden;
				.base-title {
					display: flex;
					line-height: 38rpx;
					.base-name {
						flex: 1;
						color: $mian-color;
						font-weight: 600;
						font-size: $title-size + 2;
					}
					.base-number {
						color: #999999;
						font-size: $title-size-m;
					}
				}
				.base-list {
					margin: 0 -10rpx 0;
					overflow: hidden;
					.base-block {
						// width: calc(50% - 20rpx);
						width: calc(100% - 20rpx);
						margin: 0 10rpx 0;
						float: left;
						.base-block-name {
							margin: $margin + 20 0 $margin - 10;
							color: #111111;
							display: flex;
							text {
								color: $mian-color;
								padding-right: 10rpx;
							}
							.base-notesIcon {
								width: 32rpx;
								height: 32rpx;
								margin: 6rpx 0 0 10rpx;
							}
						}
						.base-block-textarea {
							background-color: #F6F6F6;
							border-radius: $radius-sm;
							padding: $padding;
							font-size: $title-size-lg;
							color: #111111;
						}
						.base-block-write {
							background-color: #F6F6F6;
							border-radius: $radius-sm;
							padding: 0 $padding;
							box-sizing: border-box;
							position: relative;
							display: flex;
							color: #111111;
							font-size: $title-size-m;
							height: 84rpx;
							line-height: 84rpx;
							&.prohibit {
								color: #999999;
							}
							.idcardAdd-picker {
								width: 100%;
								height: 100%;
							}
							.base-block-input {
								width: 100%;
								height: 100%;
								font-size: $title-size-lg;
							}
							.base-block-textarea {
								padding: $padding 0;
							}
							.idcardAdd-input {
								display: flex;
								flex: 1;
							}
							.placeholderClass {
							   color: #999999;
							}
							image {
								width: 24rpx;
								height: 24rpx;
								position: absolute;
								top: $margin;
								right: $margin;
							}
						}
						.base-block-site {
							display: flex;
							margin: 0 -5rpx;
							.base-site-white {
								background-color: #F6F6F6;
								border-radius: $radius-sm;
								flex: 3;
								color: #111111;
								font-size: $title-size-lg;
								height: 84rpx;
								line-height: 84rpx;
								padding: 0 $padding - 10 0 $padding;
								box-sizing: border-box;
								position: relative;
								margin: 0 5rpx;
								width: 100%;
								.picker {
									width: calc(100% - 30rpx)
								}
								image {
									width: 24rpx;
									height: 24rpx;
									position: absolute;
									top: $margin;
									right: 0;
								}
							}
						}
						.idcardAdd-aline {
							font-size: $title-size-m;
							color: #999999;
						}
					}
					.baseAline {
						width: calc(100% - 20rpx);
					}
				}
			}
		}
	}
	
	.introduce-btn {
		position: fixed;
		width: 100%;
		left: 0;
		bottom: 0;
		background-color: #f5f5f5;
		text-align: center;
		padding: $padding $padding - 20;
		box-sizing: border-box;
		z-index: 9;
		.btn {
			background-color: $mian-color;
			border: 2rpx solid transparent;
			box-sizing: border-box;
			color: #ffffff;
			border-radius: $radius-sm;
			width: calc(50% - 30rpx);
			margin: 0 15rpx;
			line-height: 90rpx;
			font-size: $title-size;
			float: left;
			&:first-child {
				background-color: transparent;
				border-color: $mian-color;
				color: $mian-color;
			}
			&[disabled] {
				background-color: #eba5a5;
			}
		}
	}
</style>