<template>
  <div class="app-container">
    <!--    荣耀编辑-->
    <span>老师信息</span>
    <hr>
    <br>
    <el-form :model="techerInfoForm" ref="reftecherInfoForm" size="small" :inline="true" label-width="100px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="教师名称" clearable prop="teacherName">
            <el-input v-model="techerInfoForm.teacherName" disabled clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="性别" prop="sex">
            <el-select disabled v-model="techerInfoForm.sex" style="width: 100%" placeholder="请选择性别">
              <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label"
                         :value="dict.value"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="教师电话" clearable prop="teacherTel">
            <el-input disabled v-model="techerInfoForm.teacherTel" clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="工作编号" clearable prop="teacherCode">
            <el-input disabled v-model="techerInfoForm.teacherCode" clearable @keyup.enter.native="handleQuery"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span>荣誉信息</span>
    <hr>
    <br>
    <el-row>
      <el-button type="primary" icon="el-icon-plus" size="mini" @click="honorAdd">增加</el-button>
      <el-button type="success" icon="el-icon-edit" size="mini" :disabled="single" @click="honorEdit">修改</el-button>
      <el-button type="danger" icon="el-icon-delete" size="mini" :disabled="multiple" @click="honorDelete">删除
      </el-button>
      <el-button type="info" size="mini" plain icon="el-icon-close" @click="closePage">关闭</el-button>
    </el-row>
    <br>
    <el-table stripe v-loading="loading" :data="honorList" width="100%" @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="获奖时间" width="width" align="center" prop="awardTime"/>
      <el-table-column label="获奖名称" width="width" align="center" prop="awardName"/>
      <el-table-column label="荣耀级别" width="width" 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="width" align="center" prop="remark"/>
    </el-table>
    <ExPagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"/>
    <!--    荣耀编辑修改，新增弹窗-->
    <el-dialog :title="title" :visible.sync="openTeacherHonor" width="800px">
      <el-form :model="honorForm" ref="refhonorForm" :rules="honorRules" size="small" style="width: 90%;"
               label-width="100px">
        <el-form-item label="获奖时间" clearable prop="awardTime">
          <el-date-picker style="width: 100%;" v-model="honorForm.awardTime" type="date" placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="获奖名称" prop="awardName">
          <el-input v-model="honorForm.awardName" aria-placeholder="获奖名称"></el-input>
        </el-form-item>
        <el-form-item label="荣誉级别" clearable prop="honor">
          <el-select v-model="honorForm.honor" style="width: 100%" placeholder="请选择荣誉级别">
            <el-option v-for="dict in dict.type.honor" :key="dict.value" :label="dict.label" :value="dict.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" clearable prop="remark">
          <el-input type="textarea" :rows="3" v-model="honorForm.remark" clearable/>
        </el-form-item>
        <el-form-item>
          <div style=" width: 300px; margin:auto; ">
            <el-button type="primary" @click="honorAddButton">提交</el-button>
            <el-button @click="openTeacherHonor=false">取消</el-button>
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {getInform,} from "@/api/smartSchool/teacherManage/teacherInformation";
import {
  addTeacherAward,
  listTeacherAward,
  getTeacherAward,
  updateTeacherAward,
  delTeacherAward
} from "@/api/smartSchool/teacherManage/teacherAward";

export default {
  name: '',
  dicts: ['education', 'sys_user_sex', 'honor'],
  components: {},
  props: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      title: "",
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 教师个人信息表单
      techerInfoForm: {},
      //   教师个人获奖信息列表
      honorList: [],
      // 增加教师个人获奖对话框
      openTeacherHonor: false,
      // 新增教师个人获奖表单
      honorForm: {},
      // 荣誉校验规则
      honorRules: {
        awardTime: [
          {required: true, message: "获奖时间不能为空", trigger: "blur"}
        ],
        awardName: [
          {required: true, message: "获奖名称不能为空", trigger: "blur"}
        ],
        honor: [
          {required: true, message: "荣誉级别不能为空", trigger: "blur"}
        ]
      },

    }
  },
  watch: {},
  computed: {},
  methods: {
    // 清空表单
    reset() {
      this.honorQueryAdd = {
        teacherId: this.teacherId,
        awardTime: null,
        learnStart: null,
        honor: null,
        remark: null,
        id: null,
      }
      this.resetForm('refhonorForm')
    },
    // 获取教师个人信息
    getTeacherInfo() {
      const id = this.$route.query.teacherId;
      getInform(id).then(res => {
        this.techerInfoForm = res.data;
      })
    },
    // 获取老师荣誉信息列表
    getList() {
      this.loading = true;
      this.queryParams.teacherId = this.$route.query.teacherId;
      // listTeacherAward({ teacherId: this.teacherId }).then(res => {
      listTeacherAward(this.queryParams).then(res => {
        if (res.code == 200) {
          this.honorList = res.rows;
          this.total = res.total;
          this.loading = false;
        } else {
          this.$message.error("数据请求失败")
          this.loading = false
        }
      })
    },
    //新增操作
    honorAdd() {
      this.reset()
      this.title = "荣誉新增"
      this.openTeacherHonor = true;
    },
    //删除按钮的操作
    honorDelete() {
      const ids = this.ids;
      this.$modal.confirm('是否确认删除所选荣誉信息数据项？').then(function () {
        return delTeacherAward(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    //修改按钮的操作
    honorEdit() {
      this.title = "荣誉信息修改"
      this.openTeacherHonor = true;
      const id = this.ids[0];
      getTeacherAward(id).then(res => {
        this.honorForm = res.data
      })
    },
    /** 荣誉提交按钮 */
    honorAddButton() {
      this.honorForm.teacherId = this.$route.query.teacherId;
      this.$refs["refhonorForm"].validate(valid => {
        if (valid) {
          if (this.honorForm.id != null) {
            this.honorForm.teacherName = this.techerInfoForm.teacherName
            updateTeacherAward(this.honorForm).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openTeacherHonor = false;
              this.getList();
            });
          } else {
            this.honorForm.teacherName = this.techerInfoForm.teacherName
            addTeacherAward(this.honorForm).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openTeacherHonor = false;
              this.getList();
            });
          }
        }
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // 关闭页面
    closePage() {
      this.$tab.closeOpenPage({
        path: '/teachManage/teacherInformation'
      })
    },
  },
  created() {
    this.getList();
    this.getTeacherInfo();
  },
  mounted() {
  }
};
</script>
<style scoped>
</style>
