<template>
	<view class="container">
		<view class="info">
			<view class="info_title">完善信息</view>
			<view class="info_con">
				<view class="info_con_item">
					<view class="info_con_item_title">姓名*</view>
					<view class="info_con_item_con">
						<input class="uni-mt-5" trim="all" maxlength="30" v-model="form.name" placeholder="输入姓名" @input="formatterInput($event , 'name')"></input>
					</view>
				</view>
				<view class="info_con_item">
					<view class="info_con_item_title">医院/公司</view>
					<view class="info_con_item_con">
						<input class="uni-mt-5" trim="all" maxlength="30" v-model="form.company" placeholder="输入您所在的单位" @input="formatterInput($event , 'company')"></input>
					</view>
				</view>
			</view>
			<view class="info_btn bg-custom" @click="submit">完成</view>
		</view>
	</view>
</template>

<script>
	import { setUser } from "@/api/system/user"
	export default {
		data() {
			return {
				form: {
					name: '',
					company: '',
					loginIdentity: '',
				},
				isReady: false,
			}
		},
		onLoad(options) {
			this.form.loginIdentity = options.loginIdentity || ''
		},
		methods:{
			formatterInput(e,name){
				let temp = e.target.value.replace(/[^a-zA-Z0-9\u4E00-\u9FA5\,\.\-]/g, '')
				this.$nextTick(()=>{
					this.form[name] = temp
				})
				
				if(this.form.name){
					if(this.form.company){
						this.isReady = true
					}else{
						this.isReady = false
					}
				}else{
					this.isReady = false
				}
			},
			// 完成
			submit(){
				let that = this
				if(!that.form.name){
					uni.$u.toast("请输入姓名！")
					return false
				}
				
				let userId = that.$store.state.user.userInfo.userId
				let params = {
					"userId": userId, //用户ID
					"nickName": that.form.name, //用户昵称
					"organizationName": that.form.company, //单位名称
					"loginIdentity": this.form.loginIdentity //身份
				}
				setUser(params).then(res => {
					that.$tab.reLaunch('/pages/pc/index/index')
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		background-color: #FFF;
		position: fixed;
		width: 100%;
		height: 100%;
		left: 0;
		top: 0;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.info{
		width: 195.31rpx;
		&_title{
			color: #1D2129;
			text-align: center;
			font-size: 12.5rpx;
			font-weight: 500;
			line-height: 16.67rpx; /* 133.333% */
		}
		&_con{
			margin-top: 9.38rpx;
			margin-bottom: 41.67rpx;
			width: 195.31rpx;
			&_item{
				padding: 4.17rpx 8.33rpx;
				&_title{
					color: #86909C;
					font-size: 6.77rpx;
					font-weight: 400;
					line-height: 11.46rpx; /* 169.231% */
					margin-bottom: 2.08rpx;
				}
				&_con{
					padding: 2.6rpx 6.25rpx;
					border-radius: 2.08rpx;
					background: #F7F8FA;
				}
			}
		}
		&_btn{
			color: #FFF;
			text-align: center;
			font-size: 8.33rpx;
			font-weight: 400;
			width: 100%;
			border-radius: 2.08rpx;
			width: 178.65rpx;
			height: 22.92rpx;
			line-height: 22.92rpx;
			margin: 0 auto;
			cursor: pointer;
		}
	}
	.disabled_btn{
		opacity: .4;
	}
	/deep/ .is-input-border{
		border: none;
		height: 17.71rpx;
		line-height: 17.71rpx;
		background-color: #F7F8FA!important;
	}
	/deep/ .uni-easyinput__content-input{
		padding: 0!important;
		height: 22.92rpx;
		line-height: 22.92rpx;
		
		color: #C9CDD4;
		text-overflow: ellipsis;
		white-space: nowrap;
		font-size: 7.29rpx;
		font-weight: 400;
	}
</style>