<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">
								待完善
							</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 @click="nextStep" 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">
						<!-- items.type === 'text' || items.type === 'textarea' -->
						<view class="base-block" :class="{baseAline : items.flex == 100, radioAline : items.type == 'radio'}" v-for="(items, itemsIndex) in backParams" :key="itemsIndex" v-if="items.pre_key != null ? isShowBlock(backParams, items): true">
							<view class="base-block-name" v-if="items.label == 1">
								<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>
							
							<!-- 单输入框 -->
							<view class="base-block-write" v-if="items.type === 'price' || items.type === 'number' || items.type === 'text' || items.type === 'password' || items.type === 'mobile' || items.type === 'day'">
								<mouldInput class="idcardAdd-input" :blur-value="items.value" :input-type="items.type" :input-key="items.key" @onValue="($event) => {items.value = $event}"></mouldInput>
							</view>
							
							<!-- 单选 -->
							<view class="idcardAdd-aline" v-if="items.type === 'radio'">
								<radio-group @change="items.value = parseFloat($event.detail.value)">
									<label class="idcardAdd-aline-write" v-for="(limitItem, limitIndex) in items.options" :key="limitIndex">
										<radio :value="limitIndex.toString()" :checked="items.value === limitIndex" color="#4e7bfe" style="transform:scale(.65)"/>
										<text>{{limitItem}}</text>
									</label>
								</radio-group>
							</view>
							
							<!-- 多选 -->
							<block v-if="items.type === 'checkbox'">
								<mouldCheckbox :checkbox-list="items.options" :checkboxVlaue="items.value || []" @onCheckbox="($event) => {items.value = $event}"></mouldCheckbox>
							</block>
							
							<!-- 办卡城市 -->
							<view class="base-block-write" v-if="items.type === 'city'">
								<mouldInput class="idcardAdd-input" :blur-value="items.value" :input-type="items.type" :input-key="items.key" @onValue="($event) => {items.value = $event}"></mouldInput>
							</view>
							
							<!-- 描述 -->
							<block v-if="items.label == 1">
								<view class="base-block-textarea" v-if="items.type === 'textarea'">
									<mouldText class="idcardAdd-depict-textarea" :blur-value="items.value" @onTextarea="($event) => {items.value = $event}"></mouldText>
								</view>
							</block>
							
							<!-- 下拉框 -->
							<view class="base-block-write" v-if="items.type === 'select'">
								<mouldSelect class="idcardAdd-picker" :select-value="items.value.toString()" :select-list="items.options" @bankPicker="($event) => {items.value = $event}"></mouldSelect>
								<image src="@/static/imgs/basic_down.png" mode="aspectFill"></image>
							</view>
							
							<!-- 日期选择 -->
							<view class="base-block-write" v-if="items.type === 'date'">
								<!-- <picker mode="date" :value-date="values[items.key]" :start="startDate" :end="endDate" @change="($event) => {values[items.key] = $event.detail.value}">
									<view class="uni-input">{{values[items.key]}}</view>
								</picker> -->
								<mouldDate :value-date="items.value || '请选择日期'" class="idcardAdd-picker" @onDate="($event) => {items.value = $event}"></mouldDate>
								<image src="@/static/imgs/basic_date.png" mode="aspectFill"></image>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="introduce-btn">
			<button class="btn" size="mini" @click="cacheSave">暂时保存</button>
			<!--  -->
			<view @click="nextStep" class="btn" size="mini">下一步</view>
		</view>
		
		<!-- 驳回提示 -->
		<mouldTips :see-data="seeData" @tipsClose="($event) => {seeData.seeShow = $event}"></mouldTips>
		
		<!-- 是否使用首次录入信息 -->
		<view class="backFirst" v-if="popFirst"></view>
		<view class="contFirst" v-if="popFirst">
			<view class="tipsWhite">
				<view class="tipsWhite-top">
					<view class="tipsWhite-name">
						温馨提示
					</view>
					<view class="tipsWhite-text">
						是否使用首次录入信息
					</view>
				</view>
				<view class="tipsWhite-btn">
					<view class="idcardBtn-go active" @click="popFirst = false">
						暂不使用
					</view>
					<view class="idcardBtn-go" @click="goFirst">
						立即使用
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import { userBank } 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 {
				popFirst  : false, // 首次录入信息状态
				disabled  : false, // 按钮状态
				bankData  : '', // 基础信息
				backParams: [], // 字段数组
				
				// 查看提示组件
				seeData     : {
					seeShow : false,
					seeTitle: '',  
					seeText : '',
				},
				
				values   : '',
				
				marriage: [],
				marriageIndex : 0,  // 婚姻选择index
				
				education: [],
				educationIndex: 0,  // 学历选择index
				
				userId   : '', // 第二个id
				baseId   : '' ,// 第二个id
				
				institutionId: ''
			}
		},
		computed: {
			// isChecked(){
			// 	return (val, vals) => {
			// 		let valsArr = vals || []
			// 		return valsArr.findIndex(v => v == val) >= 0
			// 	}
			// },
			isShowBlock(){
				return (backParams, items) => {
					if(items.pre_key != null){
						let paramsValue = backParams.find(v => v.key == items.pre_key)
						return paramsValue.value == items.pre_value
					}
					return true
				}
			}
		},
				
		onShow() {
			// 获取基础信息
			this.baseInfo();
		},
		
		methods: {
			// 基础信息
			baseInfo() {
				userBank(this.$Route.query.id).then(res => {
					let storageName = uni.getStorageSync('saveArr' + this.$Route.query.id);
					let { params } = res;
					let newParams = new Array;
					if(storageName){
						newParams = params.map(val => {
							let storageNameIndex = storageName.findIndex(e => e.key === val.key)
							if( storageNameIndex >= 0){
								val.value = storageName[storageNameIndex].value
							}
							return val
						})
					}
					
					this.backParams = newParams.length > 0 ? newParams : params
					
					this.userId = res.business_order_user_bank_id
					// 是否使用首次录入信息
					if(res.is_finish == 0 && res.user_bank) {
						this.popFirst = true
						this.baseId   = res.user_bank.user_bank_id
					}
					
				}).catch( err => {
					uni.showToast({
						title: err.message,
						icon: "none"
					})
				})
			},
			
			// 临时保存 - 缓存
			cacheSave() {
				let SaveArr = new Array;
				this.backParams.map(val => {
					SaveArr.push({
						key: val.key,
						value: val.value
					})
				})
				uni.setStorage({
					key	: "saveArr" + this.$Route.query.id,
					data: SaveArr
				})
				uni.showToast({
					title: '保存成功',
					icon: "none"
				})
			},
			
			// 下一步
			nextStep(){
				let newSaveArr = this.backParams.map(val => {
					return {
						key: val.key,
						value: val.value == null ? '' : val.value
					}
				})
				
				// 临时保存
				uni.setStorage({
					key	: "saveArr" + this.$Route.query.id,
					data: newSaveArr
				})
				
				// 跳转
				this.$router.push({
					name: 'ModifyOther',
					params: {
						data: newSaveArr,
						id: this.$Route.query.id
					}
				})
			},
			
			// 提示组件 -- 赋值
			seeTips(title, text) {
				this.seeData.seeShow = true
				this.seeData.seeTitle = title
				this.seeData.seeText = text
			},
			
			// 跳转新页面-首次录入信息
			goFirst() {
				this.popFirst = false
				this.$Router.replace({name: 'userBank', params: {userId: this.userId, id: this.baseId, type: 'first'}})
			},
		}
	}
</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: 20rpx 10rpx;
						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;
							margin-top: $margin - 10;
							&.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;
							.idcardAdd-aline-write {
								margin-right: $margin;
							}
						}
						&.baseAline {
							width: calc(100% - 20rpx);
						}
						&.radioAline {
							display: flex;
							.base-block-name {
								flex: 1;
							}
						}
					}
				}
			}
		}
	}
	
	.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;
			}
		}
	}
	
	.backFirst {
		position: fixed;
		width: 100%;
		height: 100vh;
		z-index: 99;
		background-color: rgba(0, 0, 0, .6);
		left: 0;
		top: 0;
	}
	
	.contFirst {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-box-pack: center;
		position: fixed;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		z-index: 100;
		padding: 0 10%;
		box-sizing: border-box;
		.tipsWhite {
			background-color: #ffffff;
			border-radius: 20rpx;
			overflow: hidden;
		}
		
		.tipsWhite-top {
			padding: 30rpx;
			box-sizing: border-box;
		}
		
		.tipsWhite-name {
			text-align: center;
			color: #111111;
			font-size: 34rpx;
			font-weight: 600;
			margin-bottom: 30rpx;
			padding-bottom: $padding;
			border-bottom: solid #F6F6F6 2rpx;
		}
		
		.tipsWhite-text {
			font-size: 30rpx;
			color: #666666;
			line-height: 48rpx;
			text-align: center;
			padding: $padding + 10 0;
		}
		
		.tipsWhite-btn {
			line-height: 90rpx;
			border-top: 2rpx solid #F6F6F6;
			display: flex;
			box-sizing: border-box;
			.idcardBtn-go {
				width: 50%;
				background-color: $mian-color;
				color: #ffffff;
				height: 90rpx;
				line-height: 90rpx;
				font-size: $title-size;
				text-align: center;
				&.active {
					background-color: #ffffff;
					color: $mian-color;
				}
			}
		}
	}
</style>