<template>
  <div class="app-container">
    <h4 class="form-header h4">老师信息</h4>
    <el-form :model="teacherInfo" ref="honorForm" size="small" :inline="true"
             label-width="100px">
      <el-row>
        <el-col :span="6">
          <el-form-item label="教师名称" clearable prop="teacherName">
            <el-input
              v-model="teacherInfo.name"
              disabled
            />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="性别" prop="sex">
            <el-input disabled :value="resolveSex"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="教师电话" clearable prop="teacherTel">
            <el-input
              disabled
              v-model="teacherInfo.phonenumber"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="工作编号" clearable prop="teacherCode">
            <el-input
              disabled
              v-model="teacherInfo.code"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <h4 class="form-header h4">荣誉信息</h4>
    <el-row class="mb8">
      <el-button
        type="primary"
        size="mini"
        plain
        class="el-icon-plus"
        @click="honorAdd">增加
      </el-button>
      <el-button
        type="success"
        size="mini"
        plain
        class="el-icon-edit"
        :disabled="!isSimple"
        @click="honorEdit">修改
      </el-button>
      <el-button
        type="danger"
        size="mini"
        plain
        class="el-icon-delete"
        :disabled="!isMultiple"
        @click="honorDelete">删除
      </el-button>
      <el-button
        size="mini"
        plain
        class="el-icon-close"
        @click="honorDelete">关闭
      </el-button>
    </el-row>
    <el-table
      v-loading="loading"
      width="100%"
      :data="honorList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" align="center" width="55"/>
      <el-table-column label="序号" type="index" align="center" width="55"/>
      <el-table-column label="获奖时间" align="center" prop="awardTime"/>
      <el-table-column label="获奖名称" align="center" prop="avardName"/>
      <el-table-column label="荣誉级别" align="center" prop="honor">
        <template slot-scope="scope">
          <!--<dict-tag :options="dict.type.honor" :value="scope.row.honor"/>-->
        </template>
      </el-table-column>
      <el-table-column label="备注" width="300px" align="center" prop="remark"/>
    </el-table>

  </div>
</template>

<script>
import { listTeacherAward } from "@/api/smartSchool/teacherManage/teacherAward";

export default {
  name: "AddAwared",
  dicts: ['sys_user_sex'],
  data() {
    return {
      id: undefined,
      teacherInfo: {},
      honorList: [],
      loading: false,
      isMultiple: false,
      isSimple: false
    }
  },
  computed: {
    resolveSex() {
      const item = this.dict.type.sys_user_sex.find(item => item.value === this.teacherInfo.sex);
      return item ? item.label : '';
    }
  },
  created() {
    this.init();

  },
  methods: {
    /** 初始化 */
    init() {
      const { name, sex, phonenumber, code } = this.$route.query;
      this.id = this.$route.params && this.$route.params.id;
      this.teacherInfo = { name, sex, phonenumber, code };
      this.getList();
    },

    /** 获取荣誉列表 */
    getList() {
      this.loading = true;
      listTeacherAward({ teacherId: this.id }).then(response => {
        this.honorList = response.rows;
        this.total = response.total;
        this.loading = false;
      }).catch(error => {
        this.loading = false;
      })
    },


    /** 新增 */
    honorAdd() {

    },

    /** 修改 */
    honorEdit() {
    },

    /** 删除 */
    honorDelete() {
    },

    /** 选中s数据发生变化 */
    handleSelectionChange(selections) {
      this.ids = selections.map(item => item.id);
      this.isSimple = this.ids.length == 1;
      this.isMultiple = this.ids.length > 0;

    }
  }

}
</script>

<style scoped>

</style>
