<template>
  <!-- 历史数据 -->
  <div class="fullHeight">
    <!-- <vue-scroll> -->
    <div class="searchBox whiteBlock">
      <el-form
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
        size="medium"
      >
        <!-- <el-form-item :label="$t('message.deviceManage.date')">
          <el-date-picker
            v-model="time"
            type="daterange"
            :range-separator="$t('message.deviceManage.to')"
            :start-placeholder="$t('message.deviceManage.startDate')"
            value-format="yyyy-MM-dd"
            :end-placeholder="$t('message.deviceManage.endDate')"
          >
          </el-date-picker>
        </el-form-item> -->

        <!-- 培训类型 -->
        <el-form-item :label="$t('message.safetyEducation.trainingType')">
          <el-select
            v-model="formInline.eduType"
            :placeholder="$t('message.carManage.placeholder_select')"
          >
            <el-option
              v-for="(item, index) in educateTypeList"
              :key="index"
              :label="item"
              :value="index + 1"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <!-- 人员姓名 -->
        <el-form-item :label="$t('message.safetyEducation.personnelName')">
          <el-input
            v-model="formInline.workerName"
            :placeholder="$t('message.deviceManage.placeholder')"
          ></el-input>
        </el-form-item>
        <!-- 课程名称 -->
        <el-form-item :label="$t('message.safetyEducation.courseName')">
          <el-input
            v-model="formInline.eduCourseName"
            :placeholder="$t('message.deviceManage.placeholder')"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" plain @click="onSubmit">{{
            $t("message.deviceManage.query")
          }}</el-button>
          <el-button type="warning" size="medium" plain @click="refresh">{{$t('message.deviceManage.refresh')}}</el-button>
          <!-- 目前广西联通需要安全教育导出功能 20220706-->
          <el-button type="primary" size="medium" plain @click="exportBtn">
            <a :href="printUrl" class="printUrl">导出</a>
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="table_wrap whiteBlock">
      <el-table :data="tableData" class="tables">
        <!-- 人员姓名 -->
        <el-table-column prop="workerName" :label="$t('message.safetyEducation.personnelName')"> </el-table-column>
        <!-- 培训日期 -->
        <el-table-column prop="studyTime" :label="$t('message.safetyEducation.trainingDate')"> </el-table-column>
        <!-- 培训类型 -->
        <el-table-column prop="eduType" :label="$t('message.safetyEducation.trainingType')"> 
          <template slot-scope="scope">
            {{educateTypeList[scope.row.eduType-1]}}
          </template>
        </el-table-column>
        <!-- 培训主题 -->
        <el-table-column prop="eduCourseName" :label="$t('message.safetyEducation.trainingTopics')"> </el-table-column>
        <!-- 考试分数 -->
        <el-table-column prop="score" :label="$t('message.safetyEducation.testScore')"> </el-table-column>
        <!-- 是否及格 -->
        <el-table-column prop="isQualified" :label="$t('message.safetyEducation.passOrNot')"> 
          <template slot-scope="scope">
            <!-- '合格':'不合格' -->
            {{scope.row.isQualified==1? $t('message.safetyEducation.qualified') : $t('message.safetyEducation.unqualified') }}
          </template>
        </el-table-column>
       
      </el-table>
      <el-pagination
        class="pagerBox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNo"
        :page-sizes="$store.state.PAGESIZRS"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next"
        :total="total"
        background
      ></el-pagination>
    </div>
    <!-- </vue-scroll> -->
    <!-- 媒体播放 -->
    <el-dialog :modal-append-to-body="false" :title="$t('message.safetyEducation.mediaPlay')" :visible.sync="dialogVisible" width="667px">
        <div class="dialog_content">
            <video v-if="mediaType=='video'" :src="mediaUrl" autoplay controls></video>
            <audio v-else :src="mediaUrl" autoplay controls></audio>
        </div>
    </el-dialog>
  </div>
</template>
<script>
import { selectWorkerEducationPageApi,exportExcelWorkerEducationApi } from "@/assets/js/api/laborPerson";

export default {
  name: "historyData",
  data() {
    return {
      printUrl:'',
      projectSn: "",
      time: [],
      formInline: {
        // endTime: "",
        // startTime: "",
        // devSn: "",
        workerName: "",
        eduType: "",
        eduCourseName:''
      },
      tableData: [],
      pageNo: 1,
      pageSize: 10,
      total: 0,
      time: [],
      educateTypeList: this.$t("message.laborDev.educateTypeList"),
      dialogVisible:false,
      mediaUrl:'',
      mediaType:''
    };
  },
  created() {
    this.projectSn = this.$store.state.projectSn;
    this.onSubmit();
  },
  methods: {
    playVideo(src,type){
      this.mediaUrl=src;
      this.mediaType=type;
      this.dialogVisible=true
    },
    refresh(){
      this.time=[]
      this.formInline.eduCourseName=''
      this.formInline.endTime = "";
      this.formInline.startTime = "";
      this.formInline.eduType = "";
      this.formInline.workerName = "";
      this.pageNo = 1;//页数
      this.pageSize = 10;//条数
      this.onSubmit();
    },
    // 导出
    exportBtn(){
      console.log('导出')
      this.printUrl = this.$http.defaults.baseURL + 'xmgl/safeEducationQuestion/exportExcelWorkerEducation?projectSn=' +
         this.projectSn + '&eduType=' + this.formInline.eduType + '&eduCourseName=' + this.formInline.eduCourseName 
         + '&workerName=' + this.formInline.workerName
         console.log(this.printUrl)
    }, 
    //查询列表
    onSubmit() {
      if (this.time.length == 0 || this.time == null) {
        this.formInline.endTime = "";
        this.formInline.startTime = "";
      } else {
        this.formInline.startTime = this.time[0];
        this.formInline.endTime = this.time[1];
      }
      let data = this.formInline;
      data.projectSn = this.projectSn;
      data.pageNo = this.pageNo;
      data.pageSize = this.pageSize;

      selectWorkerEducationPageApi(data).then((res) => {
        if (res.code == 200) {
          this.total = res.result.total;
          this.tableData = res.result.records;
          setTimeout(() => {
            this.$previewRefresh();
          }, 100);
        }
      });
    },
    handleSizeChange(value) {
      this.pageSize = value;
      this.onSubmit();
    },
    handleCurrentChange(value) {
      this.pageNo = value;
      this.onSubmit();
    },
  },
};
</script>
<style lang="less" scoped>
.printUrl{
  text-decoration: none;
}
</style>