<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      v-show="showSearch"
      :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-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="数据编号" align="center" prop="id" />
      <el-table-column label="机构名称" align="center" prop="name" />
      <el-table-column label="统一社会信用代码" align="center" prop="code" />
      <el-table-column
        label="研究方向"
        align="center"
        prop="researchs"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <div>{{ scope.row.researchs.join(";") }}</div>
        </template>
      </el-table-column>
      <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>
        </template>
      </el-table-column>
      <el-table-column
        label="所在地"
        align="center"
        prop="address"
        show-overflow-tooltip
      />
      <el-table-column label="站点" align="center" prop="area" />
      <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="handleEdit(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 { researchList } from "@/api/dataList/research";

export default {
  data() {
    return {
      is_super: this.$store.getters.is_super,
      showSearch: true,
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 机构表格数据
      dataList: null,
      // 查询参数
      queryParams: {
        page_num: 1,
        page_size: 10,
        name: undefined,
        examine_status: undefined,
        tenant_id: undefined,
      },
    };
  },
  methods: {
    /** 查询机构列表 */
    getList() {
      this.loading = true;
      researchList(this.queryParams).then((response) => {
        this.dataList = 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();
    },
    handleAdd() {
      this.$router.push({
        path: "/dataList/researchAdd",
      });
    },
    handleEdit(id) {
      this.$router.push({
        path: "/dataList/researchAdd",
        query: {
          id,
        },
      });
    },
  },
  created() {
    this.getList();
  },
};
</script>