<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
		<el-form-item label="期次" prop="qi">
			<el-cascader v-model="queryParams.qi" placeholder="请选择期次" :props="prop" :options="options" @change="handleChange">
					<template slot-scope="{ node, data }">
					    <span v-if="data.children != null">{{ data.year+'年' }}</span>
					    <span v-else> {{ '第 '+data.year+' 期' }} </span>
					</template>
				</el-cascader>
		</el-form-item>
      <el-form-item label-width="50px" label="姓名" prop="UserName">
        <el-input v-model="queryParams.UserName" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="身份证号" label-width="80px" prop="UserCord">
        <el-input v-model="queryParams.UserCord" placeholder="请输入身份证号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="是否及格" prop="PassState">
        <el-select v-model="queryParams.PassState" placeholder="请选择是否及格">
          <el-option value="0" label="否"></el-option>
          <el-option value="1" label="是"></el-option>
        </el-select>
      </el-form-item>
    
      <el-form-item>
        <el-button type="primary" @click="handleQuery">查询</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="RenCaiList">
      <el-table-column label="序号" align="center" type="index">
        <template slot-scope="scope">
          <span>{{ handleTableIndex(scope.$index, queryParams) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="期次" width="120" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.QiciYear }}年{{ scope.row.QiCi }}期次</span>
        </template>
      </el-table-column>
      <el-table-column label="培训类别" width="100" align="center" prop="ZcsZhuanYe">
        <!-- 监理工程师 -->
      </el-table-column>
      <el-table-column label="姓名" align="center" prop="UserName" />
      <el-table-column label="身份证号" align="center" width="170" prop="UserCord" />
      <el-table-column label="执业单位" align="center" width="280" prop="DeptName" />
      <el-table-column label="证书编号" width="120" align="center" prop="Undef1">
      </el-table-column>
      <el-table-column label="证书有效期至" width="100" align="center" prop="Yxqz">
      </el-table-column>
      <el-table-column label="应完成学时" width="100" align="center" prop="XueShi">
        <template slot-scope="scope">
          <span>{{ scope.row.XueShi }}学时</span>
        </template>
      </el-table-column>
      <el-table-column label="已完成时间" width="100" align="center" prop="WcXueshi">
        <template slot-scope="scope">
          <span v-if="scope.row.WcXueshi">{{ scope.row.WcXueshi }}分钟</span>
        </template>
      </el-table-column>
      <el-table-column label="及格分数" align="center" prop="jgfs">
        <template slot-scope="scope">
          <span v-if="scope.row.jgfs">{{ scope.row.jgfs }}分</span>
        </template>
      </el-table-column>
      <el-table-column label="考试分数" align="center" prop="TotalMark">
        <template slot-scope="scope">
          <span v-if="scope.row.TotalMark">{{
            scope.row.TotalMark - Math.trunc(scope.row.TotalMark) > 0
            ? scope.row.TotalMark
            : parseInt(scope.row.TotalMark)
          }}分</span>
        </template>
      </el-table-column>
      <el-table-column label="考试次数" align="center" prop="kscs">
        <template slot-scope="scope">
          <span v-if="scope.row.kscs">{{ scope.row.kscs }}次</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
	import { searchQici } from "@/api/xiehui/jxjy/Training"
import { listExam } from "@/api/xiehui/wljxjyxt/notExamPerson";
import { handleTableIndex } from "@/utils/index";

export default {
  name: "RenCai",
  dicts: ["jxjy_sfkyjxjy", "jxjy_jlgcszfbz", "jxjy_bljl", "jxjy_jlyzfbz"],
  data() {
    return {
      achievementTableData: [],
      viewDia: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      activeView: {},
      // 监理人才管理表格数据
      RenCaiList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        isks: 1,
        PassState: null,
        UserName: null,
        UserCord: null,
        QiciYear: null,
        QiCi: null,
		qi:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
	  options:[],
	  prop:{
	  	label:"year",
	  	value:"year"
	  }
    };
  },
  created() {
	  this.qiciSearch()
    this.getList();
  },
  methods: {
	  qiciSearch(){
	  	searchQici().then(res=>{
	  		this.options = res.data
	  	})
	  },
	  //选择期次
	  handleChange(e){ 
	  	this.queryParams.QiciYear = e[0]
	  	this.queryParams.QiCi = e[1]
	  },
    handleTableIndex,
    handleView(row) {
      getYeJi({
        XYusercord: row.ShenFenZheng,
      }).then((res) => {
        this.achievementTableData = res.rows;
      });
      this.viewDia = true;
    },
    /** 查询监理人才管理列表 */
    getList() {
      this.loading = true;
      listExam(this.queryParams).then((response) => {
        this.RenCaiList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
	  this.queryParams.QiciYear = null
	  this.queryParams.QiCi = null
      this.handleQuery();
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const ID = row.ID || this.ids;
      getRenCai(ID).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改监理人才管理";
      });
    },
    changeYear() {
      if (this.queryParams.QiciYear == null) {
        this.queryParams.QiCi = null
      }
    }
  },
};
</script>
<style scoped lang="scss">
.supervision {
  color: red;
}
</style>
