<template>
  <div class="train-image-wrapper">
    <div class="train-image-tools-wrapper">
      <el-input
        v-model="searchEntryName"
        style="width: 80%;"
        placeholder="请输入企业名称"
      ></el-input>
      <el-button type="primary" style="margin-left: 20px;" @click="searchEntry"
        >查找</el-button
      >
    </div>
    <div class="train-image-list-wrapper">
      <el-table :data="enterList" border v-loading="isLoadingData">
        <el-table-column
          prop="name"
          label="企业名称"
          width="480"
        ></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="enterDetail(scope.row)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="curPageSize"
        layout="total, prev, pager, next, jumper"
        :total="totalSize"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { searchEnterprise } from "@/api/trainimage.js";
export default {
  data() {
    return {
      searchEntryName: "",
      enterList: [
        {
          name: "威海晶合数字矿山有限公司",
          id: -1
        },
        {
          name: "威海港盛船务有限公司",
          id: -1
        },
        {
          name: "山东港口威海港有限公司",
          id: -1
        },
        {
          name: "山东威海港国际客运有限公司",
          id: -1
        },
        {
          name: "威海兴茂置业有限公司"
        }
      ],
      currentPage: 1,
      curPageSize: 10,
      totalSize: 100,
      isLoadingData: false
    };
  },
  mounted() {
    this.initData();
  },
  methods: {
    initData() {
      this.isLoadingData = true;
      const params = {
        page: this.currentPage - 1,
        size: this.curPageSize
      };
      if (this.searchEntryName) {
        params.name = this.searchEntryName;
      }
      searchEnterprise(params)
        .then(res => {
          this.enterList = [...res.content];
          this.totalSize = res.totalElements;
          this.isLoadingData = false;
        })
        .catch(() => {
          this.isLoadingData = false;
        });
    },
    enterDetail(row) {
      console.log(row, "enterDetail enterDetail enterDetail");
      this.$router.push("/train/trainimage/trainimg/" + row.id);
    },
    handleSizeChange(val) {
      this.curPageSize = val;
      this.initData();
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.initData();
    },
    searchEntry() {
      this.initData();
    }
  }
};
</script>

<style lang="scss" scoped>
.train-image-wrapper {
  margin: 10px 10px;
  padding: 10px;
  border-radius: 5px;
  .train-image-tools-wrapper {
    margin: 10px 10px;
    padding: 10px;
    border-radius: 5px;
    background: #fff;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
  }
  .train-image-list-wrapper {
    margin: 10px 10px;
    padding: 10px;
    border-radius: 5px;
    background: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
}
</style>
