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

      <div class="operate-btn">
        <el-button
          :type="multipleSelection.length ? 'primary' : 'info'"
          :disabled="!multipleSelection.length"
          @click="delData"
          >删除</el-button
        >
        <el-button type="primary" @click="refresh">刷新</el-button>
        <el-button type="primary" @click="query">查询</el-button>
        <el-button type="primary" @click="exportData">导出</el-button>
      </div>
    </div>
     <div :class="block==0?'search-div' : 'none'">
      <div class="search-input-box">
        <label>设备名称：</label>
        <el-input
          size="small"
          placeholder="请输入设备名称"
          style="width: 180px"
          v-model="FSUForm.equipName"
          clearable
        >
        </el-input>
      </div>
      <div class="search-input-box">
        <label>FSU身份编号：</label>
        <el-input
          size="small"
          placeholder="请输入FSU身份编号"
          style="width: 180px"
          v-model="FSUForm.fsuCode"
          clearable
        >
        </el-input>
      </div>
      <div class="search-input-box">
        <label>IP地址：</label>
        <el-input
          size="small"
          placeholder="请输入IP地址"
          style="width: 180px"
          v-model="FSUForm.ip"
          clearable
        >
        </el-input>
      </div>
      <div class="search-input-box">
        <label>所在铁路线：</label>
        <el-select
          size="small"
          placeholder="请选择所在铁路线"
          style="width: 180px"
          v-model="FSUForm.wayId"
          clearable
          @change="changerailWay()"
        >
          <el-option
            v-for="item in railWaySelect"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </div>
      <div class="search-input-box">
        <label>所在站点：</label>
        <el-select
          size="small"
          placeholder="请选择所在站点"
          style="width: 180px"
          v-model="FSUForm.siteId"
          clearable
        >
          <el-option
            v-for="item in stationSelect2"
            :key="item.id"
            :label="item.siteName"
            :value="item.id"
          ></el-option>
        </el-select>
      </div>
       <div class="search-input-box">
         <el-button class="seabtn" @click="searchQuery()">查询</el-button>
         <el-button class="seabtn" @click="reset()">重置</el-button>
       </div>
    </div>
    <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="equipName" label="设备名称" align="center" />
      <el-table-column prop="wayId" label="所在铁路线" align="center" />
      <el-table-column
        prop="siteId"
        label="所在站点"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="fsuCode"
        label="FSU身份编号"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="fsuPort"
        label="FSU端口数"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="ip"
        label="IP地址"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="equipFactory"
        label="设备厂商"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="backupMode"
        label="设备备用方式"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="connectMode"
        label="通信方式"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="equipType"
        label="设备类型"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="equipSubType"
        label="设备子类型"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="softVersion"
        label="软件版本号"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="equipSerialNumber"
        label="设备生产序列号"
        show-overflow-tooltip
        align="center"
      />
      <el-table-column
        prop="kmSign"
        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="params.pageSize"
      :page="params.pageNum"
      :total="total"
      class="pagination"
      @pagination="handlePageChange"
    />
  </div>
</template>
<script>
import Pagination from "@/components/Pagination";
import { fsulist, fsubatchDelete, fsudetail } from "../../api";
import { successAlert, warningAlert } from "@/utils/alert";
import { mapGetters, mapActions } from "vuex";
export default {
  props: [],
  components: { Pagination },
  data() {
    return {
      railWaySelect: [],
      stationSelect: [],
      stationSelect2: [],
      FSUForm: {
        fsuCode: "",
        equipName: "阿达21",
        equipSerialNumber: "4651",
        ip: "192.168.0.3",
        parentId: "",
        siteId: "",
        siteName: "asd",
        wayId: "",
      },
      Info: [],
      visible: false,
      tableData: [],
      params: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 10,
      multipleSelection: [],
      ids: [],
       block: 1,
    };
  },
  computed: {
    ...mapGetters({
      railWaylist: "railWay/list",
      stationlist: "station/list",
    }),
  },
  methods: {
    ...mapActions({
      asyncrailWayList: "railWay/asyncList",
      asyncstationList: "station/asyncList",
      asyncfsuList: "FSU/asyncList",
    }),
    changerailWay() {
      this.stationSelect2 = this.stationlist.filter(
        (item) => item.wayId === this.FSUForm.wayId
      );
    },
    tableRowClassName({ row, rowIndex }) {
      return rowIndex % 2 === 0 ? "" : "single-row";
    },
    changeType(item) {
      this.activeName = item.key;
    },
    delData() {
      let ids = this.ids;
      fsubatchDelete({ ids }).then((res) => {
        if (res.code == 200) {
          successAlert("删除成功");
          this.asyncfsuList();
          this.getTableData();
        } else {
          warningAlert("删除失败");
        }
      });
    },
    refresh() {
      this.getTableData();
    },
    searchQuery() {},
    reset() {
      
    },
    query() {
       if (this.block == 1) {
        this.block = 0;
      } else {
        this.block = 1;
      }
    },
    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: 3,
        },
      });
    },
    handlePageChange(pageData) {
      this.params.pageSize = pageData.size;
      this.params.pageNum = pageData.page;
      this.getTableData();
    },
    getTableData() {
      let params = {
        current: this.params.pageNum,
        size: this.params.pageSize,
      };
      fsulist(params).then((res) => {
        let list = res.records || [];
        this.tableData = list;
        this.total = res.total;
      });
    },
  },
  mounted() {
    this.getTableData();
    this.asyncrailWayList();
    this.asyncstationList();
    this.railWaySelect = this.railWaylist;
    // this.stationSelect = this.stationlist;
  },
};
</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>