<template>
	<view class="container">
		 <view class="title">
		    <view>
				<text class="line"></text>
				基本资料
			</view>
		    <text class="page_mark">1/8</text>
		  </view>
		   <view class="content">
		      <view class="contentDetail employ">
		        <view class="contentItem">
		          <text>邀请码</text>
		          <input type="text" class="form-control" placeholder="非必填" v-model="applyParam.inviterInvitationCode"/>
		        </view>
		        <view class="contentItem">
					<text>申请身份</text>
					<picker @change="changeIdentity" :value="name" :range="identityArr"
					range-key="name">
						<view class="uni-input">{{identityArr[identityIdx]['name']}}
							<text class="iconfont icon-youjiantou"></text>
						</view>
					</picker>
		        </view>
		        <view class="contentItem">
		          <text>所属组织</text>
		          <view class="">
		          	银盾工作室
		          </view>
		        </view>
		        <view class="contentItem">
		          <text>姓名</text>
		          <input type="text" class="form-control" v-model="applyParam.name" placeholder="请输入姓名" />
		        </view>
		        <view class="contentItem">
		          <text>证件类型</text>
		          <picker @change="changeIdType" :value="name" :range="idTypesList"
		          range-key="name">
		          	<view class="uni-input">{{idTypesList[idTypeIdx]['name']}}
		          		<text class="iconfont icon-youjiantou"></text>
		          	</view>
		          </picker>
		        </view>
		        <view class="contentItem">
		          <text>证件号码</text>
		          <view>
		            <input type="text" class="form-control" v-model="applyParam.idNo" placeholder="请输入证件号码" />
		          </view>
		        </view>
		        <view class="contentItem">
					<text>出生日期</text>
					<picker mode="date" :value="applyParam.birthday" @change="bindBirthday"
					:end="maxDate">
						<view v-if="!applyParam.birthday">请选择 <text class="iconfont icon-youjiantou"></text> </view>
						<view class="uni-input" v-if="applyParam.birthday">{{this.applyParam.birthday}} <text class="iconfont icon-youjiantou"></text></view>
					</picker>
		        </view>
				<view class="contentItem">
					<text>居住地址</text>
					<view><input type="text" class="form-control" placeholder="请选择"/></view>
				</view>
		      </view>
		    </view>
		    <view class="fixed" @click="saveInfo()">
		      保存并下一步
		    </view>
	</view>
</template>

<script>
	import api from "@/api/api";
	export default{
		data(){
			return {
				identityIdx:0,
				identityArr:[{partnerLevel:null,name:'请选择'},{partnerLevel:'A',name:'事业伙伴'},{partnerLevel:'B1',name:'工作室'}],
				applyParam:{
					inviterInvitationCode:'',
					name:'',
					partnerLevel:'',
					idType:'',
					idNo:'',
					birthday:'',
					areaId:'',
					// birthday:`${new Date().getFullYear()}-${new Date().getMonth() + 1} -${new Date().getDate()}`,
				},
				idTypesList:[{id:null,name:'请选择'}],
				idTypeIdx:0,
				maxDate:`${new Date().getFullYear()}-${new Date().getMonth() + 1}`,
			}
		},
		components:{},
		onLoad(){
			this.erpInitialize();
		},
		methods:{
			erpInitialize(){
				api.erpInitialize({}).then((res)=>{
					if(res['success']){
					    this.idTypesList = this.idTypesList.concat(res['data']['idTypes']);
						console.log(this.idTypesList)
					}
				})
			},
			changeIdentity: function(e) {
				this.identityIdx = e.detail.value;
				this.applyParam.partnerLevel = this.identityArr[this.identityIdx]['partnerLevel'];
				console.log(this.partnerLevel)
			},
			changeIdType:function(e){
				this.idTypeIdx = e.detail.value;
				this.applyParam.idType = this.idTypesList[this.idTypeIdx]['name'];
				console.log(this.applyParam.idType)
			},
			bindBirthday: function(e) {
			    this.applyParam.birthday = e.detail.value;
			},
			saveInfo(){
				if(!this.applyParam.name){
					uni.showToast({
						title: '请输入姓名',
						duration: 2000,
						icon: 'none'
					})
					return;
				}
				if(!this.applyParam.idType){
					uni.showToast({
						title: '请选择证件类型',
						duration: 2000,
						icon: 'none'
					})
					return;
				}
				if(!this.applyParam.idNo){
					uni.showToast({
						title: '请输入证件号',
						duration: 2000,
						icon: 'none'
					})
					return;
				}
				uni.setStorageSync('applyParam',JSON.stringify(this.applyParam))
				uni.navigateTo({
					url:'work-experience'
				})
			}
		}
	}
</script>

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