<template>
	<view class='r-page'>
		<view class='r-box'>
			<view class='box-contain'>
				<view class='r-line'>
					<label class='line-text'>姓名</label>
					<input class='line-input' maxlength="4" type="text" :value="nameVal" @input="changeName($event)" placeholder="请输入姓名" />
				</view>
				<view class='r-line'>
					<label class='line-text'>联系方式</label>
					<input class='line-input' :value="mobileVal"  @input="changeMoblie($event)" maxlength="11" type="number" placeholder="请输入手机号" />
				</view>
				<view class='r-line'>
					<label class='line-text'>擅长鉴定</label>
					<input class='line-inputs' :value="desVal" maxlength="10" @input="changeDes($event)" placeholder="请输入您擅长鉴定的种类" />
				</view>
			</view>
			
		</view>
		<view class='footer-btn' @click="goSubmit">提交</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nameVal:'',
				mobileVal:'',
				desVal:''
			}
		},
		onLoad() {
			console.log('onLoad')
			this.buryingPoint('app:recruit_pageView')
		},
		methods: {
			goSubmit(){
				const self =this
				const {nameVal,mobileVal,desVal }=self
				if(nameVal==''){
					self.toast('姓名不能为空')
					return false
				}
				if(mobileVal==''){
					self.toast('请输入正确的手机号')
					return false
				}
				if(desVal==''){
					self.toast('擅长的鉴定不能为空')
					return false
				}
				const params={
					"gemName": nameVal,
					"gemPhone": mobileVal,
					"goodGem":desVal
				}
				console.log(params,'params')
				self.$request('/pawn/recruit/add','POST',params).then(res => {
					console.log(res,'add');
					self.Go('uni:/pages/recruitResult/index','redirect')
				}).catch(err=>{
				  console.log(err,'请求出错')
				})
				
			},
			changeName(e){
				console.log(e.detail.value.length,e.detail.value,'add');
				if(e.detail.value.length>4){
					
					this.toast('不可超过4个字')
					return false
					
				}else{
					this.nameVal= e.detail.value
				}
				
			},	
			changeMoblie(e){
				const regex = /^1[3456789]\d{9}$/;
				console.log(!regex.test(e.detail.value),'086')
				if(!regex.test(e.detail.value)){
					this.toast('请输入正确的手机号')
					return false
				}else{
					this.mobileVal= e.detail.value
				}
				
			},
			changeDes(e){
				if(e.detail.value.length>10){
					
					this.toast('不可超过10个字')
					return false
					
				}else{
					this.desVal= e.detail.value
				}
				
			}
		},
		onShow() {
			console.log('onshow')
			
		}
	}
</script>

<style src='./index.less' lang="less" scoped></style>