<template>
	<view class="default_page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title='填写所在团队信息'></cus-header>
		<cus-team-info-fill @handleConfirm="handleConfirm" :confirmText="confirmText"></cus-team-info-fill>
	</view>
</template>

<script>
	import CusTeamInfoFill from '@/components/CusTeamInfoFill/index.vue'
	export default {
		components:{ CusTeamInfoFill },
		data(){
			return {
				type:'',
				questionnaireId:'',
				confirmText:'下一步'
			}
		},
		onLoad(options) {
			this.type = options.type||''
			this.questionnaireId = options.questionnaireId||''
			this.confirmText = options.type?'确定':'下一步'
		},
		methods:{
			handleConfirm(team){
				if(!this.type){
					team.questionnaireId = this.questionnaireId;
					team.coachId = JSON.parse(uni.getStorageSync('userInfo')).id;
					this.$api.post('/core/user/team',team).then(({data:res})=>{
						if(res.code!==0) return this.$showToast(res.msg)
						this.$showToast('保存成功，即将填写问卷')
						setTimeout(()=>{
							uni.removeStorageSync('newUser')
							uni.navigateTo({
								url:'/pagesPublish/questionnaireFill?questionnaireId='+this.questionnaireId
							})	
						},1500)
					})			
				}else{
					this.getOpenerEventChannel().emit('saveTeamInfo',111)
					uni.navigateBack()
				} 
			}
		}
	}
</script>

<style scoped lang="scss">
	.default_page{
		box-sizing: border-box;
	}
</style>