<template>
	<view class="teacher">
		<view class="one">
			<form @submit="formSubmit">
				<view class="value other" style="display: none;">
					<view class="title">id</view>
					<view class="label">
						<input name="_id" class="input" :value="form._id" placeholder="请输入id" />
					</view>
				</view>
				<view class="value icon">
					<view class="title">头像</view>
					<view class="label">
						<up-upload :fileList="form.icon" @afterRead="afterRead" @delete="deletePic" name="icon" multiple
							:maxCount="1"></up-upload>
					</view>
				</view>
				<view class="value other">
					<view class="title">昵称</view>
					<view class="label">
						<input name="nick_name" class="input" :value="form.nick_name" placeholder="请输入昵称" />
						<span v-if="errors.nick_name" class="error-message">{{ errors.nick_name }}</span>
					</view>
				</view>
				<view class="value other margin">
					<view class="title">性别</view>
					<view class="label">
						<up-radio-group v-model="form.gender" placement="row">
							<up-radio :customStyle="{marginRight: '16px'}" v-for="(item, index) in genderList"
								:key="index" :label="item.label" :name="item.value">
							</up-radio>
						</up-radio-group>
						<span v-if="errors.gender" class="error-message">{{ errors.gender }}</span>
					</view>
				</view>
				<view class="value other">
					<view class="title">年龄</view>
					<view class="label">
						<input name="age" class="input" :value="form.age" placeholder="请输入年龄" />
						<span v-if="errors.age" class="error-message">{{ errors.age }}</span>
					</view>
				</view>
				<view class="value other">
					<view class="title">身份证类型</view>
					<view class="label">
						<picker @change="cardChange" :range="cardTypeList" range-key='label'>
							<view class="picker">{{form.cardType_name||'请选择身份证类型'}}</view>
						</picker>
					</view>
				</view>
				<view class="value other">
					<view class="title">身份证号码</view>
					<view class="label">
						<input name="card" class="input" :value="form.card" placeholder="请输入身份证号码" />
						<span v-if="errors.card" class="error-message">{{ errors.card }}</span>
					</view>
				</view>
				<view class="value other">
					<view class="title">手机号</view>
					<view class="label">
						<input name="phone" class="input" :value="form.phone" placeholder="请输入手机号" />
						<span v-if="errors.phone" class="error-message">{{ errors.phone }}</span>
					</view>
				</view>
				<view class="value other">
					<view class="title">学历</view>
					<view class="label">
						<picker @change="educationChange" :range="educationList" range-key='label'>
							<view class="picker">{{form.education_name||'请选择学历'}}</view>
						</picker>
					</view>
				</view>
				<view class="value other">
					<view class="title">院校</view>
					<view class="label">
						<input name="college" class="input" :value="form.college" placeholder="请输入院校" />
					</view>
				</view>
				<view class="value other">
					<view class="title">学业状态</view>
					<view class="label">
						<picker @change="learnStatusChange" :range="learnStatusList" range-key='label'>
							<view class="picker">{{form.learnStatus_name||'请选择学业状态'}}</view>
						</picker>
					</view>
				</view>
				<view class="value other margin">
					<view class="title">所教年级</view>
					<view class="label">
						<picker @change="gradeChange" :range="gradeList" range-key='label'>
							<view class="picker">{{form.grade_name||'请选择所教年级'}}</view>
						</picker>
					</view>
				</view>
				<view class="value other">
					<view class="title">学科</view>
					<view class="label">
						<picker @change="subjectChange" :range="subjectList" range-key='label'>
							<view class="picker">{{form.subject_name||'请选择学科'}}</view>
						</picker>
					</view>
				</view>
				<view class="value other">
					<view class="title">是否公开</view>
					<view class="label">
						<up-radio-group v-model="form.is_show" placement="row">
							<up-radio :customStyle="{marginRight: '16px'}" v-for="(item, index) in showList"
								:key="index" :label="item.label" :name="item.value">
							</up-radio>
						</up-radio-group>
						<span v-if="errors.is_show" class="error-message">{{ errors.is_show }}</span>
					</view>
				</view>
				<view class="brief other margin">
					<view class="title">简介</view>
					<view class="label">
						<textarea name='brief' :value="form.brief" placeholder="请输入简介" auto-height />
					</view>
				</view>
				<view class="button">
					<button type="warn" size="mini" form-type="submit">保存</button>
				</view>
			</form>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { inject } from 'vue';
	const form = inject('form');
	const errors = inject('errors');
	// 字典表
	const genderList = inject('genderList')
	const gradeList = inject('gradeList')
	const cardTypeList = inject('cardTypeList')
	const educationList = inject('educationList')
	const learnStatusList = inject('learnStatusList')
	const subjectList = inject('subjectList')
	const showList = inject('showList')

	const deletePic = inject('deletePic');
	const afterRead = inject('afterRead');
	const formSubmit = inject('formSubmit');
	const cardChange = inject('cardChange');
	const educationChange = inject('educationChange');
	const learnStatusChange = inject('learnStatusChange');
	const gradeChange = inject('gradeChange');
	const subjectChange = inject('subjectChange');
</script>
<style lang="scss" scoped>
	.teacher {
		display: flex;
		flex-direction: column;
		background-color: var(--footColor);

		.one {
			.icon {
				padding: 2vw;
			}

			.margin {
				margin: 3vw 0 0 0;
			}

			.other {
				padding: 3vw 2vw;
				border-bottom: 1px solid var(--footColor);
			}

			.value {
				display: flex;
				justify-content: space-between;
				align-items: center;
				background-color: var(--mainColor);

				.label {
					text-align: right;

					.input {
						text-align: right;
					}

					.image {
						width: 15vw;
						height: 15vw;
						border-radius: 20vw;
					}

					.error-message {
						margin: 5px 0 0 0;
						color: var(--ff0Color);
						font-size: var(--font12Size);
					}
				}
			}

			.brief {
				background-color: var(--mainColor);

				.title {
					margin: 0 0 2vw 0;
				}
			}

			.button {
				margin: 2vw 0 0 0;
				text-align: center;

				button {
					color: var(--mainColor);
					background-color: var(--3c9Color);
					font-size: var(--font14Size);
					border-radius: 2vw;
				}
			}
		}
	}
</style>