<template>
  <div class="leakage-cable">
    <!-- 设备连接维修历史 -->
    <div class="leakage-top">
      <div style="color: #666666"></div>
      <div class="operate-btn">
        <delids :multipleSelection2="multipleSelection"  @del="toDelete"
          >删除</delids> 
        <el-button type="primary" @click="getTableData">刷新</el-button>
        <el-button type="primary"  @click="isQuery = !isQuery">查询</el-button>
        <el-button type="primary">导出</el-button>
        <el-button type="primary">清空数据</el-button>
      </div>
    </div>
    <div v-if="isQuery">
      <search @search="getTableData" />
    </div>
    <el-table
      :data="tableData"
      style="width: 100%"
      :cell-class-name="cellClassFn"
      :header-cell-style="{ background: '#EAF1FE', color: '#666666' }"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column prop="startPointDeviceName" label="网元设备" align="center" />
      <el-table-column
        prop="pointConnectStatus_text"
        label="连接状态"
        width="150"
        align="center"
      >
      </el-table-column>
      <el-table-column prop="endPointDeviceName" label="网元设备" align="center">
      </el-table-column>
      <el-table-column prop="userName" label="维修人员信息" align="center">
      </el-table-column>
      <el-table-column
        prop="connectAlarmMaintainTime"
        label="连接告警维修时间"
        align="center"
      />
    </el-table>
    <Pagination
      :limit="params.size"
      :page="params.current"
      :total="total"
      class="pagination"
      @pagination="handlePageChange"
    />
  </div>
</template>
<script>
import { ConnectMaintainList, ConnectMaintainDelete } from '../api'
import { ConnectStatusEnum } from '@/const/index'
import search from './components/search.vue'

export default {
  data() {
    return {
      multipleSelection: [],
      ConnectStatusEnum,
      params: {
        current: 1,
        size: 10,
      },
      total: 14,
      tableData: [],
      isQuery: false
    };
  },
  components: {
    search
  },
  methods: {
    handleSelectionChange(val) {
      let deleteIds = val.map(item => item.id)
      this.multipleSelection = deleteIds
    },
    handlePageChange(pageData) {
      this.params.size = pageData.size;
      this.params.current = pageData.page;
      this.getTableData()
    },
    getTableData(option) {
      let params = {
        ...this.params,
        ...option
      }
      ConnectMaintainList(params).then(res => {
        let list = res.records || []
        list.forEach(item => {
          item.pointConnectStatus_text = this.ConnectStatusEnum[item.pointConnectStatus]
        });
        this.tableData = list
        this.total = res.total
      })
    },
    toDelete() {
      ConnectMaintainDelete({ids: this.multipleSelection}).then(res => {
        this.$message.success('删除成功！')
        this.getTableData()
      })
    },
    cellClassFn({ row, column, rowIndex, columnIndex }) {
      if (row.pointConnectStatus_text == "连接异常" && column.label == "连接状态") {
        return "emergency";
      } else if (row.pointConnectStatus_text == "连接正常" && column.label == "连接状态") {
        return "normal";
      }
      if (rowIndex % 2 == 1) {
        return "stripe";
      }
    },
  },
  mounted() {
    this.getTableData()
  },
};
</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 .emergency {
    background-color: #f00;
  }
  & ::v-deep .important {
    background-color: #f89850;
  }
  & ::v-deep .normal {
    background-color: green;
  }

  .page {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 20px 0;
    .current {
      margin: 0 20px;
    }
  }
}
</style>