<template>
  <view class="mind">
	  <picker range-key="dictLabel" :disabled="daflag||studentlist.length<1" :range="studentlist"  :value="nameidx"  @change="bindDateChangea">
	  		<view class="flexc mibox mb20">
	  			<view class="tit" style="margin-bottom: 0;">人员</view>
	  			<view class="f15 flex1 txr co16" v-if="name" >{{name}}</view>
	  			<view class="f15 flex1 txr coa" v-else >请选择人员</view>
	  			<image :src="rimg" class="rimg"></image>
	  		</view>
	  </picker>
	  <view class='mibox flexc'>
			<view class="tit">身高</view>
			<input placeholder="请输入身高" v-model="height" type="number"/>
	  		<view class="f16 co16 ml6">cm</view>
		</view>
		<view class='mibox flexc'>
				<view class="tit">体重</view>
				<input placeholder="请输入身高" v-model="weight" type="number"/>
			<view class="f16 co16 ml6">kg</view>
		</view>
	  <view class="rebtn mt30" @click="getSubmit">确认</view>
  </view>
</template>

<script>
	// import tabSearch from "@/components/toptab/search.vue"
	import {getDictionaryFn} from '@/api/mine/register.js'
	import {getliveAddFn} from "@/api/mine/files.js"
  export default {
	data(){
		return{
			rimg:require("@/mine/static/score/rimg.png"),
			autoHeight:true,
			height:'',
			weight:'',
			datainfo:{
				
			},
			roles:'',
			studentlist:[],
			name:'',
			nameidx:0,
			studentId:'',
			daflag:false,//档案修改
		}
	},
	onLoad: function(e) {
		if(e.type&&e.type=='daup'){
			this.name=e.name;
			this.studentId=e.id;
			this.daflag=true;
		}else{
			//家长
			var roles=this.$store.state.user.choseroles;
			var newArr=this.$store.state.user.student;
			if(newArr&&newArr.length){
				if(newArr&&newArr.length>1){
					this.studentlist = newArr.map(v => {
						return {
							dictLabel:v.studentName,
							dictValue: v.id,
						}
					})
				}else{
					// 一个娃
					this.name=newArr[0].studentName
					this.studentId=newArr[0].id
				}
			}
			
		}
		
		
	},
	methods:{
		bindDateChangea(e){
			var idx=e.detail.value
			this.name=this.studentlist[idx].dictLabel
			this.studentId=this.studentlist[idx].dictValue
		},
		getSubmit(){
			// 学生 id
			var that=this;
			var roles=this.$store.state.user.choseroles;
			if(!this.studentId){
				this.$toast('请选择人员')
				return
			}
			if(!this.height&&!this.weight){
				this.$toast('请至少输入身高或体重')
				return
			}
			// 走修改
			var params={
				studentId:this.studentId,
			}
			if(this.height){
				params.height=this.height
			}
			if(this.weight){
				params.weight=this.weight
			}
			if(roles=='teacher'){
				params.createType='2'
			}else if(roles=='parents'){
				params.createType='1'
			}
			getliveAddFn(params).then(res => {
				if (res.code == 200) {
					that.$toast('新增成功')
					setTimeout(function() {
						if(that.daflag){
							uni.$emit('refreshdalist');
							uni.redirectTo({
								url:'/mine/pages/files/heightlist?type=da&id='+that.studentId+'&name='+that.name
							})
						}else{
							uni.$emit('refreshlivelist');
							uni.navigateBack({
								delta:1
							})
						}
						
					}, 1500)
				} else {
					this.$toast(res.msg)
				}
			})
		},
	},
	
  }
</script>

<style lang="scss" scoped>
.mind{
	min-height: 100vh;background: #ffffff;padding: 80rpx 60rpx;
	.mibox{
		.tit{font-size: 32rpx;font-weight: 500;color: #161616;margin-bottom: 40rpx;}
		textarea{border: 2rpx solid #FFB132;border-radius: 20rpx;width: 100%;min-height: 230rpx;padding:32rpx;box-sizing: border-box;}
		.rimg{width: 14rpx;height: 24rpx;flex: 0 0 auto;margin-left: 12rpx;}
		input{flex: 1;text-align: right;}
	}
}
</style>
