<!-- 区块管理 -->
<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="qk">
        <el-select v-model="queryParams.qk" placeholder="请选择区块名称" clearable filterable>
          <el-option v-for="item in blockOptions" :key="item.qk" :label="item.qk" :value="item.qk"
            v-if="item && item.qk" />
        </el-select>
      </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-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" border :data="blockList" height="calc(100vh - 200px)">
      <el-table-column label="区块名称" align="center" prop="qk" />
      <el-table-column label="井数量" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="goToJsaaPage(scope.row)">{{ scope.row.jsl }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      :page-sizes="[10, 20, 30, 50, 100]" @pagination="getList" />
  </div>
</template>

<script>
import { getBlockName, getQkxl } from "@/api/system/jsaa";

export default {
  name: "BlockManagement",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 区块列表数据
      blockList: [],
      // 区块下拉选项
      blockOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        qk: null
      }
    };
  },
  created() {
    this.getList();
    this.getBlockOptions();
  },
  methods: {
    /** 查询区块列表 */
    getList() {
      this.loading = true;
      getBlockName(this.queryParams).then(response => {
        this.blockList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 获取区块下拉选项 */
    getBlockOptions() {
      getQkxl().then(response => {
        // 过滤掉无效的选项
        this.blockOptions = response.data.filter(item => item && item.qk);
      });
    },

    /** 跳转到jsaa页面 */
    goToJsaaPage(row) {
      this.$router.push({
        path: '/engineeringData/jsaa',
        query: {
          qk: row.qk
        }
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/system/jsaa/exportQk', {
        ...this.queryParams
      }, `区块管理${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style lang="scss" scoped>
.app-container {
  height: 100%;
  padding: 10px;
  box-sizing: border-box;
}

::v-deep .el-table__cell>.cell {
  font-weight: normal;
}

::v-deep .el-table--medium .el-table__cell {
  padding: 0px 0 !important;
}

::v-deep.pagination-container {
  padding: 5px !important;
  margin: 0;
}
</style>