<template>
  <el-dialog :title="$t('一人一档')" :visible.sync="visible" width="1200px" append-to-body>
    <el-card>
      <div slot="header" class="clearfix">
        <span>基本资料</span>
      </div>
      <div class="el-descriptions">
        <div class="el-descriptions__body">
          <table class="el-descriptions__table is-bordered el-descriptions--big" style="border: 1px solid #e6ebf5;">
            <tbody>
            <tr class="el-descriptions-row" rowspan="3">
              <th colspan="1" class="el-descriptions-item__cell el-descriptions-item__label is-bordered-label "> 姓名</th>
              <td colspan="1" class="el-descriptions-item__cell el-descriptions-item__content"> {{staff.name}}</td>
              <th colspan="1" class="el-descriptions-item__cell el-descriptions-item__label is-bordered-label "> 性别</th>
              <td colspan="1" class="el-descriptions-item__cell el-descriptions-item__content" > {{sexFormat(staff)}}</td>
              <th colspan="1" class="el-descriptions-item__cell el-descriptions-item__label is-bordered-label "> 年龄</th>
              <td colspan="1" class="el-descriptions-item__cell el-descriptions-item__content">{{staff.birthday}}</td>
              <td colspan="1" rowspan="3" class="el-descriptions-item__cell el-descriptions-item__content">
                <img :src="staff.photo"  />
              </td>
            </tr>
            </tbody>
            <tbody>
            <tr class="el-descriptions-row">
              <th colspan="1" class="el-descriptions-item__cell el-descriptions-item__label is-bordered-label "> 学历</th>
              <td colspan="1" class="el-descriptions-item__cell el-descriptions-item__content">{{educationFormat(staff)}}</td>
              <th colspan="1" class="el-descriptions-item__cell el-descriptions-item__label is-bordered-label "> 专业</th>
              <td colspan="1" class="el-descriptions-item__cell el-descriptions-item__content"></td>
              <th colspan="1" class="el-descriptions-item__cell el-descriptions-item__label is-bordered-label "> 工号</th>
              <td colspan="1" class="el-descriptions-item__cell el-descriptions-item__content">{{staff.staffid}}</td>
            </tr>
            </tbody>
            <tbody>
            <tr class="el-descriptions-row">
              <th colspan="1" class="el-descriptions-item__cell el-descriptions-item__label is-bordered-label "> 入职时间
              </th>
              <td colspan="1" class="el-descriptions-item__cell el-descriptions-item__content"></td>
              <th colspan="1" class="el-descriptions-item__cell el-descriptions-item__label is-bordered-label "> 当前岗位
              </th>
              <td colspan="3" class="el-descriptions-item__cell el-descriptions-item__content">{{actualpostFormat(staff)}}</td>
            </tr>
            </tbody>
          </table>
        </div>
      </div>
    </el-card>

    <el-card>
      <div slot="header" class="clearfix">
        <span>公司级培养</span>
      </div>
      <el-table v-loading="loading" :data="participantsList" border>
        <el-table-column :label="$t('课程代码')" align="center" prop="courseCode" width="120" :show-overflow-tooltip="true"/>
        <el-table-column :label="$t('公司级') + $t('空格') + $t('培训课程') + $t('空格') + $t('名称')" align="center" prop="companyItem" width="400" :show-overflow-tooltip="true"/>
        <el-table-column :label="$t('开始日期')" align="center" prop="startDate" width="200">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('结束日期')" align="center" prop="endDate" width="200">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('培训时长')" align="center" prop="trainingDuration" :show-overflow-tooltip="true"/>
      </el-table>
    </el-card>
    <el-card>
      <div slot="header" class="clearfix">
        <span>装置级培养</span>
      </div>
      <el-table v-loading="loading" :data="devicceList" border>
        <el-table-column :label="$t('课程代码')" align="center" prop="courseCode" width="200" :show-overflow-tooltip="true"/>
        <el-table-column :label="$t('课程名称')" align="center" prop="item" width="350" :show-overflow-tooltip="true"/>
        <el-table-column :label="$t('授课人')" align="center" prop="lecturerName" width="150" :show-overflow-tooltip="true" />
        <el-table-column :label="$t('课时')" align="center" prop="hour" :show-overflow-tooltip="true"/>
        <el-table-column :label="$t('开始日期')" align="center" prop="startDate" width="100">
          <template slot-scope="scope">
            <span v-if="scope.row.supplementary === '0' && scope.row.trainingType === '10'">{{ parseTime(scope.row.startDate, '{y}-{m}') }}</span>
            <span v-else>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <el-card>
      <div slot="header" class="clearfix">
        <span> 专项培养</span><div style="float: right;margin-bottom: -14px">
        <el-form :model="queryDeviceParams" ref="queryRegularForm" label-width="68px" :inline="true">
          <el-form-item :label="$t('年份')" prop="year">
            <el-date-picker clearable size="small" style="width: 200px"
                            v-model="queryDeviceParams.year"
                            type="year"
                            value-format="yyyy"
                            :placeholder="$t('请选择') + $t('年份')">
            </el-date-picker>
          </el-form-item>
          <el-button type="cyan" icon="el-icon-search" size="mini" @click="staffPlanQuery" style="margin-left: 20px;">
            {{ $t('搜索') }}</el-button>
        </el-form>
      </div>
      </div>

      <el-table :data="planList" v-loading="planLoading"  border>
        <el-table-column label="培养内容" align="center" prop="plantName" :show-overflow-tooltip="true"/>
        <el-table-column label="开始日期" align="center" prop="startDate" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="结束日期" align="center" prop="endDate" width="100">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.endDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
<!--        <el-table-column label="学时" align="center" prop="classHour" :show-overflow-tooltip="true"/>-->
        <el-table-column label="具体内容" align="center" prop="classContent" :show-overflow-tooltip="true"/>
        <el-table-column label="评分" align="center" prop="classContent" :show-overflow-tooltip="true"/>
      </el-table>
    </el-card>
  </el-dialog>
</template>

<script>
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {listPlan} from "@/api/training/spec/plan";
import {listParticipants} from "@/api/training/participants";
import {listDevice} from "@/api/training/device";

export default {
  name: "Resume",
  components: {Treeselect},
  data() {
    return {
      // 遮罩层
      loading: false,
      planLoading: false,
      visible: false,
      // 选中数组
      ids: [],
      staff: null,
      dataListSelections: [],
      // 装置名称字典
      plantCodeOptions: [],
      // 性别字典
      sexOptions: [],
      // 部门字典
      unitOptions: [],
      // 班值字典
      teamOptions: [],
      // 实际岗位字典
      actualpostOptions: [],
      // 学历字典
      educationOptions: [],
      // 英语能力字典
      enAbilityOptions: [],
      // 特殊职能字典
      specialDutyOptions: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 培养计划表格数据
      planList: [],
      // 人员-公司级培训关系表格数据
      participantsList: [],
      // 人员-装置级培训关系表格数据
      devicceList: [],
      // 弹出层标题
      title: "",
      // 操作
      operation: "",
      // 部门树选项
      deptOptions: undefined,
      clientHeight: 300,
      // 是否显示弹出层
      open: false,
      // 学习状态字典
      studyStateOptions: [],
      // 学员列表
      successorOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        staffId: null,
        plantName: null,
        startDate: null,
        endDate: null,
        classHour: null,
        studyState: null
      },
      queryCompanyParams: {
        staffId: null,
        companyId: null,
      },
      queryDeviceParams: {
        staffId: null,
        regularId: null,
        year: this.getNowTime(),
        trainingType: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  watch: {},
  created() {
    this.getDicts("PLANT_DIVIDE").then(response => {
      this.plantCodeOptions = response.data;
    });
    this.getDicts("sys_user_sex").then(response => {
      this.sexOptions = response.data;
    });
    this.getDicts("STAFF_UNIT").then(response => {
      this.unitOptions = response.data;
    });
    this.getDicts("TEAM_DIVIDE").then(response => {
      this.teamOptions = response.data;
    });
    this.getDicts("ACTUALPOST").then(response => {
      this.actualpostOptions = response.data;
    });
    this.getDicts("EDUCATION").then(response => {
      this.educationOptions = response.data;
    });
    this.getDicts("ENGLISHABILITY").then(response => {
      this.enAbilityOptions = response.data;
    });
    this.getDicts("SPECIAL_DUTY").then(response => {
      this.specialDutyOptions = response.data;
    });
  },
  methods: {
    init(row) {
      this.visible = true
      this.staff = row.staff
      this.queryParams.staffId = row.staff.staffid
      this.getNowTime()
      this.getPlanList()
      this.getParticipants()
      this.getDevice()
    },
    /** 获取当前年份 */
    getNowTime() {
      var now = new Date();
      var year = now.getFullYear(); //得到年份
      var defaultDate = `${year}`;
      defaultDate = `${year}`
      return defaultDate;
    },
    /** 查询培养计划列表 */
    getPlanList() {
      this.planLoading = true;
      this.queryParams.year = this.queryDeviceParams.year
      listPlan(this.queryParams).then(response => {
        this.planList = response.rows;
        this.total = response.total;
        this.planLoading = false;
      });
    },
    getParticipants() {
      this.queryCompanyParams.staffId = this.staff.staffid
      // this.queryCompanyParams.year = this.queryDeviceParams.year
      listParticipants(this.queryCompanyParams).then(response => {
        this.participantsList = response.rows;
      });
    },
    getDevice() {
      this.queryDeviceParams.staffId = this.staff.staffid
      listDevice(this.queryDeviceParams).then(response => {
        this.devicceList = response.rows;
      });
    },
    staffPlanQuery (){
      this.getPlanList()
    },
    // 装置名称字典翻译
    plantCodeFormat(row, column) {
      return this.selectDictLabel(this.plantCodeOptions, row.plantCode);
    },
    // 性别字典翻译
    sexFormat(row, column) {
      return this.selectDictLabel(this.sexOptions, row.sex);
    },
    // 部门字典翻译
    unitFormat(row, column) {
      return this.selectDictLabel(this.unitOptions, row.unit);
    },
    // 班值字典翻译
    teamFormat(row, column) {
      return this.selectDictLabel(this.teamOptions, row.team);
    },
    // 实际岗位字典翻译
    actualpostFormat(row, column) {
      return this.selectDictLabel(this.actualpostOptions, row.actualpost);
    },
    // 学历字典翻译
    educationFormat(row, column) {
      return this.selectDictLabel(this.educationOptions, row.education);
    },
    // 英语能力字典翻译
    enAbilityFormat(row, column) {
      return this.selectDictLabel(this.enAbilityOptions, row.enAbility);
    },
    // 特殊职能字典翻译
    specialDutyFormat(row, column) {
      return this.selectDictLabel(this.specialDutyOptions, row.specialDuty);
    },
  }
};
</script>
