<template>
	<view>
		<!-- <apply-template placeholder="请描述你遇到的法律问题" @submit="handel"></apply-template> -->
		<textarea :auto-height="true" style="padding: 20px;" v-model="inputValue" placeholder="请描述你遇到的法律问题" maxlength="200"  placeholder-class="textClass"/>
		<view class="errTips" v-if="errShow && btnShow">抱歉，您输入的内容已超出字数限制</view>
		<view class="" v-if="btnShow">
		<view class="submitBtn" v-if="validate"  @click="handleSubmit">提交</view>
		<view class="submitBtn" v-if="loading">提交中</view>
		<view class="submitBtn disabledBtn" v-if="!validate">提交</view>  
		</view>
	</view>
</template>

<script>
	
	import {
		labourUnionDetail
		
	} from '@/api/federation.js'
	import {mapGetters} from 'vuex'
	import {showUniModal} from '@/untils/uniModal.js'
	import {submitApplication} from '@/api/newIndex.js'
	export default {
		data() {
			return {
				inputValue:'',
				validate:false,
				applyType:1,
				btnShow:true,
				pageTitle:'',
				placeholder:'',
				loading:false,
				errShow:false,
				submitType:1,//申请类型：1 法律咨询 2技能提升
				
			}
		},
		onShow() {
			if (!this.$store.state.user.token){
				//modalTitle, content, whetherCancel, confirmText, pageUrl, cancelUrl
				showUniModal('提示','您还未登录，点击确认去登录',true,'确定','/pages/login/login','/pages/index/index')
			}else{
				if (!this.auth.realNameState) { //未实名需要提示
					showUniModal('提示', '检查到您还未实名认证，实名认证之后才可加入工会', true, '立即认证', '/pageMy/setUserBase/index','/pages/index/index')
				} else {
					labourUnionDetail(this.authInfo.idNumber).then(res => { //判断是否加入工会
						const data = res.data.data.records;
						if (data.length == 0) { //未查到数据，代表未加入工会
							showUniModal('提示', '加入工会后可使用此服务', true, '加入工会', '/pageMy/federation/forMembership/Notice','/pages/index/index')
						}
					})
				}
			}
		},
		watch: {
			inputValue(value) {
				if(value.length!=0){
					this.validate=true;
				}
				else{
					this.validate=false;
				}
				if(value.length>=200){
					this.errShow=true;
				}
				else{
					this.errShow=false;
				}
			},
		},
		
		onLoad(option) {
			this.applyType=option.type;
			
			if(option.data && option.type){
				this.inputValue=decodeURIComponent(option.data);
				this.btnShow=false;
			}
		},
		methods: {
			handleSubmit(){
				this.loading=true;
				uni.showLoading({
					title:'请求中'
				})
				let uid=this.authInfo.userId;
				let uname=this.authInfo.realName;
				let tel=this.authInfo.telphone;
				submitApplication(uid,uname,tel,this.submitType,this.inputValue).then(res=>{
							this.loading=false;
							uni.hideLoading()
							setTimeout(() => {
								uni.showToast({
									title: '提交成功',
									icon: 'none'
								});
							}, 1000)
							uni.switchTab({
								url:'/pages/index/index'
							})
				})
			},
		},
		computed:{
			...mapGetters(['authInfo','auth'])
		}
	}
</script>

<style>
.textClass{
	color: #cccccc;
}
.submitBtn{
	width: 60%;
	    height: 80rpx;
	    line-height: 80rpx;
	    border-radius: 10px;
	    text-align: center;
	    background-color: #1b66ff;
	    color: #f1f1f1;
	    position: absolute;
	    bottom: 100px;
	    left: 20%;
}
.disabledBtn{
	background-color: #7f7f7f;
}
.teset{
	width: 100px;
	height: 100px;
	border: 1px solid;
}
.errTips{
	color: red;
	padding-left: 40rpx;
	}
</style>
