<template>
  <!-- 漏缆实时状态 -->
  <div class="leakage-cable">
    <div class="leakage-top">
      <div style="color: #666666">
      </div>
      <div class="operate-btn">
        <el-button
          :type="multipleSelection.length ? 'primary' : 'info'"
          :disabled="!multipleSelection.length"
        >删除</el-button>
        <el-button type="primary">刷新</el-button>
        <el-button type="primary">查询</el-button>
        <el-button type="primary">导出</el-button>
        <el-button type="primary">图形报表</el-button>
      </div>
    </div>
    <el-table
      ref="multipleTable"
      :data="tableData2"
      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="name" label="基站名称" align="center" />
      <el-table-column prop="object" label="告警对象" align="center" />
      <el-table-column prop="message" label="告警信息" align="center">
        <template slot-scope="scope">
          <div v-for="(item, index) in scope.row.message.red" :key="index+'red'" class="red message">
            {{ item }}
          </div>
          <div v-for="(item, index) in scope.row.message.green" :key="index+'green'" class="green message">
            {{ item }}
          </div>
          <div v-for="(item, index) in scope.row.message.black" :key="index+'black'" class="black message">
            {{ item }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="uploadDate" label="上传日期" align="center" />
    </el-table>
    <pagination
      :limit="searchForm.pageSize"
      :page="searchForm.pageNum"
      :total="total"
      class="pagination"
      @pagination="handlePageChange"
    />
  </div>
</template>

<script>
import Pagination from '@/components/Pagination'

export default {
  components: { Pagination },
  data() {
    return {
      searchForm: {
        pageNum: 1,
        pageSize: 10
      },
      total: 10,
      tableData2:[],
      tableData: [
        {
          name: 'STATION2未开通',
          object: '漏缆FSU2_R1下行方向',
          level: '紧急',
          message: {
            red: ['距离：0米 驻波比：8.72'],
            green: ['距离：18米 驻波比：1.07', '距离：42米 驻波比：1.02'],
            black: ['漏缆百米损耗：2.8']
          },
          uploadDate: '2022/12/18 11:51:12'
        },
        {
          name: 'STATION2未开通',
          object: '漏缆FSU2_R1下行方向',
          level: '紧急',
          message: {
            red: ['距离：0米 驻波比：8.72'],
            green: ['距离：18米 驻波比：1.07', '距离：42米 驻波比：1.02'],
            black: ['漏缆百米损耗：2.8']
          },
          uploadDate: '2022/12/18 11:51:12'
        }, {
          name: 'STATION2未开通',
          object: '漏缆FSU2_R1下行方向',
          level: '紧急',
          message: {
            red: ['距离：0米 驻波比：8.72'],
            green: ['距离：18米 驻波比：1.07', '距离：42米 驻波比：1.02'],
            black: ['漏缆百米损耗：2.8']
          },
          uploadDate: '2022/12/18 11:51:12'
        }, {
          name: 'STATION2未开通',
          object: '漏缆FSU2_R1下行方向',
          level: '紧急',
          message: {
            red: ['距离：0米 驻波比：8.72'],
            green: ['距离：18米 驻波比：1.07', '距离：42米 驻波比：1.02'],
            black: ['漏缆百米损耗：2.8']
          },
          uploadDate: '2022/12/18 11:51:12'
        }, {
          name: 'STATION2未开通',
          object: '漏缆FSU2_R1下行方向',
          level: '紧急',
          message: {
            red: ['距离：0米 驻波比：8.72'],
            green: ['距离：18米 驻波比：1.07', '距离：42米 驻波比：1.02'],
            black: ['漏缆百米损耗：2.8']
          },
          uploadDate: '2022/12/18 11:51:12'
        }, {
          name: 'STATION2未开通',
          object: '漏缆FSU2_R1下行方向',
          level: '重要',
          message: {
            red: ['距离：0米 驻波比：8.72'],
            green: ['距离：18米 驻波比：1.07', '距离：42米 驻波比：1.02'],
            black: ['漏缆百米损耗：2.8']
          },
          uploadDate: '2022/12/18 11:51:12'
        }
      ],
      multipleSelection: []
    }
  },
  methods: {
    // 表格背景图颜色
    cellClassFn({ row, column, rowIndex, columnIndex }) {
      if (row.level === '紧急' && column.label === '告警级别') {
        return 'emergency'
      } else if (row.level === '重要' && column.label === '告警级别') {
        return 'important'
      }
      if (rowIndex % 2 === 1) {
        return 'stripe'
      }
    },
    handlePageChange(pageData) {
      this.searchForm.pageSize = pageData.size
      this.searchForm.pageNum = pageData.page
        this.getTableData()
    },
     getTableData() {
      this.tableData2 = this.tableData.slice(( this.searchForm.pageNum - 1) * this.searchForm.pageSize,
         this.searchForm.pageNum * this.searchForm.pageSize
      );
      this.total = this.tableData.length
  
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    }
  },
  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;
  }
  .message {
    line-height: 22px;
  }
  .red {
    color: red;
  }
  .green {
    color: green;
  }
  .black {
    color: black;
  }
  & ::v-deep .stripe {
    background-color: #EAF1FE;
  }
  & ::v-deep .emergency {
    background-color: #f00;
  }
  & ::v-deep .important {
    background-color: #f89850;
  }
  .page {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 20px 0;
    .pageNum {
      margin: 0 20px;
    }
  }
}
</style>
