<template>
  <div id="teacher">
    <el-col :span="24">
      <el-form size="mini" ref="formUpdate" :model="formUpdate" label-width="120px">
        <el-form-item label="姓名："> {{ formUpdate.name }}</el-form-item>
        <el-form-item label="身份证号："> {{ formUpdate.idnumber }} </el-form-item>
        <el-form-item label="手机号："> {{ formUpdate.phone }} </el-form-item>
        <el-form-item label="性别：">
          <el-radio-group disabled v-model="formUpdate.gender">
            <el-radio label="男">男</el-radio>
            <el-radio label="女">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="年龄："> {{ formUpdate.age }} </el-form-item>
        <el-form-item label="出生年月："> {{ formUpdate.birthday }} </el-form-item>
        <el-form-item label="政治面貌：">{{ formUpdate.politics }} </el-form-item>
        <el-form-item label="邮箱：">{{ formUpdate.email }} </el-form-item>
        <el-form-item label="学校：">{{ schname }}</el-form-item>
        <el-form-item label="入职时间：">{{ formUpdate.entrydate }} </el-form-item>
        <el-form-item label="所在部门：">{{ formUpdate.department }} </el-form-item>
        <el-form-item label="职务：">{{ formUpdate.job }} </el-form-item>
        <el-form-item label="职称：">{{ formUpdate.protitle }} </el-form-item>
        <el-form-item label="最后学历：">{{ formUpdate.education }} </el-form-item>
        <el-form-item label="最后学位：">{{ formUpdate.degree }} </el-form-item>
        <el-form-item label="教师所学专业：">{{ formUpdate.major }} </el-form-item>
        <el-form-item label="教师在校所教课程：">{{ formUpdate.schlesson }} </el-form-item>
        <el-form-item label="教育培训经历（从大学开始）：">{{ formUpdate.experience }} </el-form-item>
        <el-form-item label="主讲课程：">{{ formUpdate.courses }} </el-form-item>
        <el-form-item label="主要学术成果及获奖情况：">{{ formUpdate.academic }} </el-form-item>
        <el-form-item label="从事就业创业教学工作年限：">{{ formUpdate.jobyear }} </el-form-item>
        <el-form-item label="科目：">{{ subname }}</el-form-item>
        <el-form-item label="是否可讲礼仪课：">
          <el-radio disabled v-model="formUpdate.islyteacher" label="0">否</el-radio>
          <el-radio disabled v-model="formUpdate.islyteacher" label="1">是</el-radio>
        </el-form-item>
      </el-form>
    </el-col>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: teacher } = createNamespacedHelpers('teacher');
const { mapActions: mapSchool } = createNamespacedHelpers('school');
const { mapActions: mapSubject } = createNamespacedHelpers('subject');
export default {
  name: 'teacher',
  props: {
    teacherId: {},
  },
  components: {},
  data: () => ({
    formUpdate: {},
    schname: {},
    subname: {},
    schList: [],
    subList: [],
    politicsList: [],
    educationList: [],
    degreeList: [{ name: '博士学位' }, { name: '硕士学位' }, { name: '学士学位' }],
  }),
  created() {},
  computed: {},
  methods: {
    ...teacher(['fetch']),
    ...mapSchool(['query']),
    ...mapSubject({ subFetch: 'fetch', subQuery: 'query' }),
    async search() {
      const teacherInfo = await this.fetch(this.teacherId);
      this.$set(this, `formUpdate`, teacherInfo.data);
      this.teaSchool();
      this.teaSubject();
    },
    async teaSchool() {
      const school = await this.query({ code: this.formUpdate.schid });
      if (school.errcode == 0 && school.data.length > 0) {
        this.schname = school.data[0].name;
      }
    },
    async teaSubject() {
      const subject = await this.subFetch(this.formUpdate.subid);
      if (subject.errcode == 0) {
        this.subname = subject.data.name;
      }
    },
  },
  watch: {
    teacherId: {
      handler(val) {
        if (val) {
          this.search();
        }
      },
      immediate: true,
    },
  },
};
</script>

<style lang="less" scoped></style>
