<template>
  <div>
    <div class="leakage-top">
      <div style="color: #666666"></div>

      <div class="operate-btn">
      <delids :multipleSelection2="multipleSelection"  @del="del()"
          >删除</delids>
        <el-button type="primary" @click="refresh">刷新</el-button>
        <el-button type="primary" @click="block = !block">查询</el-button>
        <el-button type="primary" @click="exportData">导出</el-button>
      </div>
    </div>
    <el-form
      class="search-div"
      v-if="block"
      :model="siteForm"
      :inline="true"
      size="mini"
    >
      <el-form-item label="站名：">
        <el-input
          placeholder="请输入站名"
          v-model="siteForm.siteName"
          clearable
        >
        </el-input>
      </el-form-item>
      <el-form-item label="站点编号：">
        <el-input
          placeholder="请输入起点编号"
          v-model="siteForm.siteCode"
          clearable
        >
        </el-input
      ></el-form-item>
      <el-form-item label="站点地址：">
        <el-input
          placeholder="请输入站点地址"
          v-model="siteForm.siteAddress"
          clearable
        >
        </el-input
      ></el-form-item>
      <el-form-item label="所在铁路线：">
        <el-select
          placeholder="请选择所在铁路线"
          v-model="siteForm.wayId"
          clearable
        >
          <el-option
            v-for="item in railWaySelect"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option> </el-select
      ></el-form-item>
      <el-form-item>
        <el-button class="seabtn" @click="searchQuery()">查询</el-button>
        <el-button class="seabtn" @click="reset()">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table
      ref="multipleTable"
      class="statistics-table"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      :row-class-name="tableRowClassName"
      :row-style="{ height: '50px' }"
      :header-cell-style="{
        background: '#eaf1fe',
        color: '#000',
        fontWeight: 700,
        height: '50px',
      }"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column prop="railWayName" label="站点所属铁路线" align="center" />
      <el-table-column prop="siteCode" label="站点编号" align="center" />
      <el-table-column prop="siteName" label="站名" align="center" />
      <el-table-column
        prop="siteAddress"
        label="站点地址"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="siteArea"
        label="站点所在局"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="siteSectionCode"
        label="站点所在段号"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="siteKmSign"
        label="站点所在公里标"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="siteLatitude"
        label="站点经度"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="siteLongitude"
        label="站点纬度"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="siteOtherMessage"
        label="站点其他信息"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="action"
        label="详细信息"
        show-overflow-tooltip
        align="center"
      >
        <template slot-scope="{ row }">
          <el-link type="primary" :underline="false" @click="handleView(row)"
            >查看</el-link
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :limit="siteForm.size"
      :page="siteForm.current"
      :total="total"
      class="pagination"
      @pagination="handlePageChange"
    />
  </div>
</template>
<script>

import { sitelist, sitebatchDelete, sitedetail } from "../../api";
import { successAlert, warningAlert } from "@/utils/alert";
import { mapGetters, mapActions } from "vuex";
export default {
  props: [],
  components: { },
  data() {
    return {
      siteForm: {
        wayId: "",
        siteCode: "",
        siteName: "",
        siteAddress: "",
        siteId: "",
        current: 1,
        size: 10,
      },
      railWaySelect: [],
      visible: false,
      Info: [],
      tableData: [],
      params: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 10,
      multipleSelection: [],
      ids: [],
      block: 0,
      istrue:0
    };
  },
  computed: {
    ...mapGetters({
      railWaylist: "railWay/list",
    }),
  },
  methods: {
    ...mapActions({
      asyncrailWayList: "railWay/asyncList",
      asyncstationList: "station/asyncList",
    }),
    tableRowClassName({ row, rowIndex }) {
      return rowIndex % 2 === 0 ? "" : "single-row";
    },
    changeType(item) {
      this.activeName = item.key;
    },
  del() {
      let ids = this.ids;
      sitebatchDelete({ ids }).then((res) => {
        if (res.code == 200) {
          successAlert("删除成功");
          this.asyncstationList();
          this.getTableData();
        } else {
          warningAlert("删除失败");
        }
      });
    },
    refresh() {
      this.reset()
      this.getTableData();
    },
    searchQuery() {
      this.istrue=1
      this.getTableData();
        
    },
    reset() {
        this.siteForm={
        wayId: "",
        siteCode: "",
        siteName: "",
        siteAddress: "",
        siteId: "",
        current: 1,
        size: 10,
      }
    },

    exportData() {},
    handleSelectionChange(val) {
      this.multipleSelection = val;

      this.ids = this.multipleSelection.map((i) => i.id);
    },

    handleView(row) {
      this.$router.push({
        path: "/detail",
        query: {
          id: row.id,
          type: 2,
        },
      });
      let id = row.id;
      sitedetail({ id }).then((res) => {});
    },
    handlePageChange(pageData) {
       this.siteForm.size = pageData.size;
      this.siteForm.current = pageData.page;
      this.getTableData();
    },
    getTableData() {
   
     let params = {
        current: this.params.pageNum,
        size: this.params.pageSize,
      };

      sitelist(this.siteForm).then((res) => {
        let list = res.records || [];
        this.tableData = list;
        this.total = res.total;
          if (this.istrue == 1) {
          if (this.tableData.length) {
            successAlert("查询成功");
          } else {
            warningAlert("查询结果为空");
          }
          this.istrue = 0;
        }
      });
    },
  },
   created() {
    var that = this;
    document.onkeydown = function (e) {
      var key = window.event.keyCode;
      if (key == 13) {
        that.searchQuery();
      }
    };
  },
  mounted() {
    this.getTableData();
    this.asyncrailWayList();

    this.railWaySelect = this.railWaylist;
  },
};
</script>
<style lang="scss" scoped>
.leakage-cable {
  .leakage-top {
    margin-bottom: 20px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
  }
  & ::v-deep .cell {
    color: #333333;
  }
  & ::v-deep .stripe {
    background-color: #eaf1fe;
  }
  & ::v-deep .red {
    background-color: #f00;
  }
  & ::v-deep .green {
    background-color: green;
  }
  .page {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 20px 0;
    .pageNum {
      margin: 0 20px;
    }
  }
}
</style>
<style lang="scss">
.statistics-table {
  .single-row {
    background: #f1f6ff;
  }
  td {
    padding: 5px !important;
  }
}
</style>