<template>
	<view class="body">
		<view class="head">
			<image src="@/static/img/pic_logo.svg" class="logo" mode=""></image>
			<view class="headuser">
				<image src="@/static/img/head.svg" class="headuserImg" mode=""></image>
				<view v-if="auth.realNameState" class="name">
					<view class="userName">{{authInfo.realName}}</view>
					<view class="userInfo">{{idNumberFilter(authInfo.idNumber)}}</view>
				</view>
				<view v-else class="name">
					<view class="userName">姓名</view>
					<view class="userInfo">身份证号</view>
				</view>
				<image v-if="auth.realNameState" src="@/static/img/exp/stamp2.svg" class="stamp" mode=""></image>
				<image v-else src="@/static/img/exp/stamp1.svg" class="stamp" mode=""></image>
			</view>
			<view class="tx">
				<image src="@/static/img/bao.svg" mode=""></image>
				<view class="txText">个人隐私信息安全保障中</view>
			</view>
		</view>
		<view class="border"></view>
		<!--<picker @change="bindPickerChange" :value="index" :range="laborType">
			<view class="list">
				<view class="listLeft">
					<view class="listTitle">身份信息</view>
					<view class="listContent">选择个人身份，获得精准推荐</view>
				</view>
				<view class="listRight">
					<view class="rightContent nochoose">
						<view v-if="auth.laborState" class="uni-input">{{ laborType[0] }}</view>
						<view v-else class="uni-input">未选择</view>
					</view>
					<image src="@/static/img/right.svg" mode=""></image>
				</view>
			</view>
		</picker>-->
		<view class="border"></view>
		<!-- <view class="list" @click="goRealName">
			<view class="listLeft">
				<view class="listTitle">实名认证</view>
				<view class="listContent">完成实名认证，提高信息可信度</view>
			</view>
			<view class="listRight">
				<view v-if="auth.realNameState" class="rightContent nochoose">已认证</view>
				<view v-else class="rightContent nochoose">未认证</view>
				<image src="@/static/img/right.svg" mode=""></image>
			</view>
		</view>
		<view class="border"></view> -->
		<!-- <view class="list" @click="setIcCard">
			<view class="listLeft">
				<view class="listTitle">银行卡认证</view>
				<view class="listContent">完善银行卡信息，方便领工资</view>
			</view>
			<view class="listRight">
				<view v-if="auth.bankCardState" class="rightContent nochoose">已认证</view>
				<view v-else class="rightContent nochoose">未认证</view>
				<image src="@/static/img/right.svg" mode=""></image>
			</view>
		</view>
		<view class="border"></view> -->
		<!--<picker @change="bindPickerChangeBao" :value="indexbao" :range="insureType">
			<view class="list">
				<view class="listLeft">
					<view class="listTitle">社保信息</view>
					<view class="listContent">选择个人身份，获得精准推荐</view>
				</view>
				<view class="listRight">
					<view class="rightContent nochoose">
						<view v-if="auth.insureState" class="uni-input">{{ insureType[indexbao] }}</view>
						<view v-else class="uni-input">未选择</view>
					</view>
					<image src="@/static/img/right.svg" mode=""></image>
				</view>
			</view>
		</picker>-->
		<!-- <view class="border"></view>
		<view class="list" @click="setSeal">
			<view class="listLeft">
				<view class="listTitle">个人签名</view>
				<view class="listContent">采集手写签名，便于维护自身利益</view>
			</view>
			<view class="listRight">
				<view v-if="autograph.data && autograph.data.signSrcUrl" class="rightContent nochoose">已采集</view>
				<view v-else class="rightContent nochoose">未采集</view>
				<image src="@/static/img/right.svg" mode=""></image>
			</view>
		</view> -->
		
		<view class="list">
			<view class="name">
				姓名
			</view>
			<text v-if="auth.realNameState" style="color: #1b66ff;">{{auth.authInfo.realName}}</text>
			<input v-else type="text" value="" placeholder="请输入真实姓名" @input="setName" placeholder-style="color:#cccccc;" />
		</view>
		<view>
			<view class="list">
				<view class="name">
					身份证号
				</view>
				<text v-if="auth.realNameState" style="color: #1b66ff;">{{idNumberFilter(auth.authInfo.idNumber)}}</text>
				<input v-else type="idcard" value="" placeholder="请输入身份证号" @input="setCard" style="text-transform:uppercase"
				 placeholder-style="color:#cccccc;" />
			</view>
			<view v-if="error" class="error">身份证填写有误</view>
		</view>
		<picker :range="identityList" @change="identityChange" :value="index">
			<view class="list">
				<view class="listLeft">
					<view class="name">
						身份信息
					</view>
					<view class="listContent">完成实名认证，提高信息可信度</view>
				</view>
				<view class="listRight">
					<view class="listRightContent">
						<view class="" v-if="auth.laborState">已认证</view>
						<view class="" v-else>未认证</view>
					</view>
					<image src="@/static/img/right.svg" mode=""></image>
				</view>
			</view>
		</picker>
		<picker :range="insureList" @change="insureChange" :value="indexBao">
			<view class="list">
				<view class="listLeft">
					<view class="name">
						社保信息
					</view>
					<view class="listContent">选择个人身份，获得精准推荐</view>
				</view>
				<view class="listRight">
					<view class="listRightContent">
						<view class="" v-if="auth.insureState">{{insureList[indexBao]}}</view>
						<view class="" v-else>未选择</view>
					</view>
					<image src="@/static/img/right.svg" mode=""></image>
				</view>
			</view>
		</picker>
		<picker :range="insureList" @change="insureChange" :value="indexBao">
			<view class="list">
				<view class="listLeft">
					<view class="name">
						个人标签
					</view>
					<view class="listContent">选择个人标签，获得精准推荐</view>
				</view>
				<view class="listRight">
					<view class="listRightContent">
						<view class="" v-if="auth.insureState">{{insureList[indexBao]}}</view>
						<view class="" v-else>未选择</view>
					</view>
					<image src="@/static/img/right.svg" mode=""></image>
				</view>
			</view>
		</picker>
		<view v-if="auth.realNameState"></view>
		<view class="btn nocheck" v-else-if="loading">
			<view class="bottombtn">
				认证中
			</view>
		</view>
		<view class="btn" @click="goSet" v-else-if="check">
			<view class="bottombtn">
				认证
			</view>
		</view>
		<view class="btn nocheck" v-else>
			<view class="bottombtn">
				认证
			</view>
		</view>
	</view>
</template>

<script>
	import textdata from '@/common/textdata.js'
	import {
		mapGetters
	} from 'vuex'
	import {
		idNumberFilter
	} from '@/untils/format.js'
	
	import {
		check18IdCardNo,
		validatenull
	} from '@/untils/validate.js'

	export default {
		data() {
			return {
				laborType: textdata.laborType,
				index: 0,
				insureType: textdata.insureType,
				
				name: '',
				card: '',
				loading: false,
				error: false,
				identityList: textdata.laborType,
				insureList: textdata.insureType,
				realIndex: 0,
			};
		},
		onLoad() {
			//  this.$store.dispatch('setAutograph')
		},
		computed: {
			...mapGetters(['auth', 'authInfo', 'autograph']),
			indexbao() {
				if (this.auth.insureState) {
					return this.authInfo.bakValue - 1
				} else {
					return 0
				}
			},
			...mapGetters(['auth', 'authInfo']),
			check() {
				return check18IdCardNo(this.card) && !validatenull(this.name)
			},
			indexBao() {
				if (this.auth.insureState) {
					return this.authInfo.bakValue - 1
				} else {
					return 0
				}
			}
		},
		methods: {
			setSeal(){
				if (this.auth.realNameState) {
					uni.navigateTo({
						url: '/pageMy/setUserBase/seal/index'
					})
				} else {
					uni.showToast({
						title: '请先完成实名认证',
						icon: 'none'
					})
				}
			},
			setIcCard: function() {
				if (this.auth.realNameState) {
					uni.navigateTo({
						url: '/pageMy/setUserBase/icCard/index'
					})
				} else {
					uni.showToast({
						title: '请先完成实名认证',
						icon: 'none'
					})
				}
			},
			goRealName: function() {
				uni.navigateTo({
					url: '/pageMy/setUserBase/realName'
				})
			},
			bindPickerChangeBao: function(e) {
				uni.showLoading()
				this.$store.dispatch('authInsure', e.target.value * 1 + 1).then(resp => {
					uni.hideLoading()
				}).catch(() => {
					uni.hideLoading()
				})
			},
			bindPickerChange: function(e) {
				uni.showLoading()
				this.$store.dispatch('authLabor').then(resp => {
					this.index = e.target.value;
					uni.hideLoading()
				}).catch(() => {
					uni.hideLoading()
				})
			},
			idNumberFilter,
			
			
			setName: function(e) {
				this.name = e.detail.value;
			},
			setCard: function(e) {
				this.card = e.detail.value.toUpperCase();
				this.error = !check18IdCardNo(this.card)
				return e.detail.value.toUpperCase()
			},
			goSet: function() {
				this.loading = true
				this.$store.dispatch('authRealName', {
						name: this.name,
						idNumber: this.card
					})
					.then(() => {
						this.loading = false
						uni.navigateBack()
					}).catch(() => {
						this.loading = false
					})
			},
			idNumberFilter,
			identityChange(val) {
				uni.showLoading();
				this.$store.dispatch('authLabor').then(() => {
					this.realIndex = val.detail.value;
					uni.hideLoading();
				}).catch(() => {
					uni.hideLoading();
				})
			},
			insureChange(val) {
				uni.showLoading();
				this.$store.dispatch('authInsure', val.detail.value * 1 + 1).then(() => {
					uni.hideLoading();
				}).catch(()=>{
					uni.hideLoading();
				})
			},
		}
	};
</script>

<style>
	.nochoose {
		color: #1b66ff;
	}

	.listRight {
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-family: PingFangSC-Regular;
		font-size: 28rpx;
		color: #999999;
	}

	.listRight image {
		width: 40rpx;
		height: 40rpx;
		margin-left: 15rpx;
	}

	.listContent {
		font-family: PingFangSC-Regular;
		font-size: 28rpx;
		color: #666666;
	}

	.list {
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-family: PingFangSC-Regular;
		font-size: 32rpx;
		color: #333333;
		padding: 30rpx;
		line-height: 50rpx;
	}

	.border {
		margin-left: 30rpx;
		width: 720rpx;
		height: 2rpx;
		background-color: #f2f2f2;
		/* border-bottom: 1rpx solid #dddddd; */
	}

	.tx image {
		width: 32rpx;
		height: 32rpx;
		margin-right: 10rpx;
	}

	.tx {
		font-family: PingFangSC-Regular;
		font-size: 24rpx;
		color: #ffffff;
		padding: 30rpx;
		padding-top: 0;
		display: flex;
		align-items: center;
		justify-content: flex-start;
	}

	.userInfo {
		font-family: PingFangSC-Regular;
		font-size: 26rpx;
		color: #ffffff;
		font-weight: normal;
	}

	.name {
		margin-left: 20rpx;
		font-family: PingFangSC-Medium;
		font-size: 36rpx;
		color: #ffffff;
		font-weight: bold;
		line-height: 50rpx;
	}

	.headuserImg {
		width: 100rpx;
		height: 100rpx;
	}

	.headuser {
		padding: 30rpx;
		display: flex;
		align-items: center;
		justify-content: flex-start;
	}

	.stamp {
		position: absolute;
		top: 30rpx;
		right: 30rpx;
		/* opacity: 0.6; */
		width: 200rpx;
		height: 200rpx;
	}

	.logo {
		position: absolute;
		bottom: 0;
		left: 0;
		opacity: 0.1;
		width: 200rpx;
		height: 200rpx;
	}

	.head {
		width: 690rpx;
		height: 250rpx;
		padding-top: 30rpx;
		margin: 30rpx;
		margin-top: 0;
		border-radius: 15rpx;
		position: relative;
		background: #1b66ff;
		box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.3);
	}

	.body {
		background-color: #fefefe;
		padding-top: 30rpx;
	}

	page {
		background-color: #f6f6f6;
	}
	
	.bottombtn {
		background-color: #1B66FF;
		color: #fff;
		text-align: center;
		border-radius: 10rpx;
		font-family: PingFangSC-Medium;
		font-size: 32rpx;
		height: 90rpx;
		line-height: 90rpx;
	}
	
	.btn {
		background-color: #fefefe;
		width: 690rpx;
		padding: 30rpx;
		padding-bottom: 80rpx;
		position: fixed;
		bottom: 0;
		left: 0;
	}
	
	.name {
		font-family: PingFangSC-Regular;
		font-size: 32rpx;
		color: #333333;
		width: 200rpx;
	}
	
	.error {
		font-family: PingFangSC-Regular;
		font-size: 26rpx;
		color: red;
		margin: 5px 0 0 200rpx;
		padding-bottom: 5px;
	}
	
	.list {
		padding: 20rpx;
		padding-left: 0;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-bottom: 1rpx solid #f2f2f2;
		font-size: 28rpx;
	}
	
	.pickerList {
		padding: 20rpx;
		padding-left: 0;
	
		border-bottom: 1rpx solid #f2f2f2;
	}
	
	.listRight {
		display: flex;
		align-items: center;
		justify-content: space-between;
		font-family: PingFangSC-Regular;
		font-size: 28rpx;
		color: #999999;
	}
	
	.listRightContent {
		color: #1b66ff;
	}
	
	.listRight image {
		width: 40rpx;
		height: 40rpx;
		margin-left: 15rpx;
	}
	
	.listContent {
		color: #999;
		font-size: 28rpx;
	}
	
	.body {
		background-color: #fefefe;
		padding-left: 20rpx;
		margin-top: 20rpx;
	}
	
	.nocheck {
		opacity: 0.3;
	}
	
	page {
		background-color: #f6f6f6;
	}
</style>
