<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="status">
        <el-select
          v-model="queryParams.status"
          placeholder="审核状态"
          clearable
          size="small"
          style="width: 240px"
          @clear="delete queryParams.status"
        >
          <el-option label="已通过" :value="1" />
          <el-option label="未通过" :value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="所属站点" prop="tenant_id" v-if="is_super">
        <SiteOptions @handleChange="queryParams.tenant_id = $event" />
      </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="120" prop="id" />
      <el-table-column label="站点---需去除" align="center" prop="area" />
      <el-table-column label="专家姓名" align="center" prop="name" />
      <el-table-column label="研究领域" align="center" prop="name" />
      <el-table-column label="所属科研机构" align="center" prop="name" />
      <el-table-column label="所属实验室" align="center" prop="name" />
      <el-table-column label="成果数量" align="center" prop="name" />
      <el-table-column label="专利数量" align="center" prop="name" />
      <el-table-column label="站点" align="center" prop="name" />
      <el-table-column label="所在地" align="center" prop="name" />
      <el-table-column label="审核状态" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 1">已通过</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
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row.id)"
            >审核</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</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 { serviceList as listUser } from "@/api/website/solution";
import { delUser } from "@/api/system/user";

export default {
  data() {
    return {
      is_super: this.$store.getters.is_super,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 专家表格数据
      userList: null,
      // 查询参数
      queryParams: {
        page_num: 1,
        page_size: 10,
      },
    };
  },
  methods: {
    /** 查询专家列表 */
    getList() {
      this.loading = true;
      listUser(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 },
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const userIds = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除数据编号为"' + userIds + '"的数据项？')
        .then(function () {
          return delUser({ id: userIds });
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
  },
  created() {
    this.getList();
  },
};
</script>