<template>
  <el-table-column label="设备状态">
    <template #default="{ row }">
      <div style="display: flex;align-items: center;justify-content: space-between;">
        <div
          v-if="!row.alertVariables || row.alertVariables.length == 0"
          class="state"
          :class="[`${eqStateClass[row.state]}`]"
        >
          <div class="point"></div>
          <div>{{ equipmentType[row.state] }}</div>
        </div>
        <el-carousel
          v-else
          class="state carousel"
          :class="[`${eqStateClass[row.state]}`]"
          :style="{ width: row.alertVariables.length != 0 ? '150px' : '90px' }"
          direction="vertical"
          :autoplay="true"
          :pause-on-hover="false"
        >
          <el-carousel-item :key="item.name" v-for="item in row.alertVariables">
            <el-tooltip :key="item.name" effect="dark" :content="item.name" placement="top">
              <div class="carousel-item g-ellipsis">
                {{ item.name }}
                <div class="point"></div>
              </div>
            </el-tooltip>
          </el-carousel-item>
        </el-carousel>
        <div class="big_screen_display"  @click.native.stop="bigScreen(row)">
          <img src="../../assets/img/device_list_screen_icon.png" />
          <div class="big_screen_text">大屏显示</div>
        </div>
      </div>

    </template>
  </el-table-column>
</template>

<script setup lang="ts">
  import router from '@/router'
  const eqStateClass: any = {
    0: 'info',
    1: 'success',
    2: 'warning',
    4: 'error'
  }
  const equipmentType: any = {
    0: '设备离线',
    1: '运行正常',
    2: '预警',
    4: '报警'
  }

  const bigScreen = async (item: any) => {
    router.push(`/big-screen/single?id=${item.id}&code=${item.code}`)
  }
</script>

<style lang="less" scoped>
  ::v-deep(.el-carousel__indicators) {
    display: none;
  }
  .state {
    width: 90px;
    height: 26px;
    line-height: 26px;
    border-radius: 7px;
    position: relative;
    padding-left: 10px;
    padding-right: 15px;
    text-align: left;
    font-weight: 400;
    background: rgba(236, 97, 90, 0.2);
    background: rgba(236, 97, 90, 0.2);
    color: #ec615a;
  }

  .point {
    width: 8px;
    height: 8px;
    background: #ec615a;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 5px;
  }
  .carousel-item {
    position: relative;
    width: 100%;
    padding-right: 15px;

    .point {
      width: 8px;
      height: 8px;
      background: #ec615a;
      border-radius: 50%;
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      right: px;
    }
  }
  .info {
    background: rgba(165, 168, 175, 0.2);
    color: #a5a8b0;
    .point {
      background: rgba(165, 168, 175, 1);
    }
  }
  .warning {
    background: #fcdcca;
    color: #d5a17d;
    .point {
      background: #d5a17d;
    }
  }
  .success {
    background: rgba(104, 200, 107, 0.2);
    color: #55b758 !important;
    .point {
      background: rgba(104, 200, 107, 1);
    }
  }
  .error {
    min-width: 150px;
    overflow: hidden;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 5px;
    background: rgba(236, 97, 90, 0.2);
    color: #ec615a;
  }
  .carousel {
    text-align: center;
    padding-right: 1px;
  }
  .big_screen_text {
    color: #407b51;
    font-size: 14px;
    margin-left: 4px
  }
  .big_screen_display {
    display: flex;
    align-items: center;
    padding: 10px 0;
    cursor: pointer;
  }
</style>
