<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="专家姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入专家姓名"
          clearable
          size="small"
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="examine_status">
        <el-select
          v-model="queryParams.examine_status"
          placeholder="请选择审核状态"
          clearable
          size="small"
          style="width: 240px"
          @clear="delete queryParams.examine_status"
        >
          <el-option label="审核中" :value="1" />
          <el-option label="审核通过" :value="2" />
          <el-option label="审核拒绝" :value="3" />
        </el-select>
      </el-form-item>
      <el-form-item label="所属站点" prop="tenant_id" v-if="is_super">
        <SiteOptions v-model="queryParams" />
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="userList">
      <el-table-column label="数据编号" align="center" width="150" prop="id" />
      <el-table-column label="专家姓名" align="center" prop="name" />
      <el-table-column
        label="研究领域"
        align="center"
        prop="industrys"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <div>{{ scope.row.industrys[scope.row.industrys.length - 1] }}</div>
          <!-- <div v-for="item in scope.row.industrys" :key="item">{{ item }}</div> -->
        </template>
      </el-table-column>
      <el-table-column
        label="所属科研机构"
        align="center"
        prop="research_name"
      />
      <el-table-column
        label="所属实验室"
        align="center"
        prop="laboratory_name"
      />
      <el-table-column label="站点" align="center" prop="area" />
      <el-table-column label="所在地" align="center" prop="address" />
      <el-table-column label="审核状态" align="center" prop="examine_status">
        <template slot-scope="scope">
          <span v-if="scope.row.examine_status == 1">审核中</span>
          <span v-else-if="scope.row.examine_status == 2">审核通过</span>
          <span v-else>审核拒绝</span>
        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" prop="created_at">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.created_at) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            :disabled="scope.row.examine_status != 1"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row.id)"
            >审核</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.page_num"
      :limit.sync="queryParams.page_size"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { expertList } from "@/api/dataList/expert";

export default {
  data() {
    return {
      is_super: this.$store.getters.is_super,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 专家表格数据
      userList: null,
      // 查询参数
      queryParams: {
        page_num: 1,
        page_size: 10,
        name: undefined,
        examine_status: undefined,
        tenant_id: undefined,
      },
    };
  },
  methods: {
    /** 查询专家列表 */
    getList() {
      this.loading = true;
      expertList(this.queryParams).then((response) => {
        this.userList = response.data.data;
        this.total = response.data.count;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page_num = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleDetail(id) {
      console.log(id);
      this.$router.push({
        path: "/examine/expertDetail",
        query: { id },
      });
    },
  },
  created() {
    this.getList();
  },
};
</script>