<template>
  <div class="robotbar" @click="changeRobot">
    <div class="name">{{ deviceInfo.name }}</div>
    <div class="online-state">
      <div class="light" :style="{ backgroundColor: getOnlineColor }"></div>
      <div class="text">{{ getOnlineState }}</div>
    </div>
    <div class="alarm-state">
      <div class="light" :style="{ backgroundColor: getAlarmColor }"></div>
      <div class="text">{{ getAlarmState }}</div>
    </div>
    <div></div>
  </div>
</template>

<script>
import lodash from 'lodash'

export default {
  props: {
    deviceInfo: {
      type: Object,
      default: {
        id: '1',
        name: '机器人1#',
        onlineState: '1',
        alarmState: '0',
      },
    },
  },
  data() {
    return {
      onlineStateOptions: [
        { code: '0', text: '离线', color: '#526891' },
        { code: '1', text: '运行', color: '#28b973' },
        { code: '2', text: '急停', color: '#f32727' },
      ],
      alarmStateOptions: [
        { code: '0', text: '正常', color: '#28b973' },
        { code: '1', text: '故障', color: '#f32727' },
      ],
    }
  },
  computed: {
    getOnlineState() {
      return lodash.find(this.onlineStateOptions, (o) => {
        return o.code == this.deviceInfo.onlineState
      }).text
    },
    getAlarmState() {
      return lodash.find(this.alarmStateOptions, (o) => {
        return o.code == this.deviceInfo.alarmState
      }).text
    },
    getOnlineColor() {
      return lodash.find(this.onlineStateOptions, (o) => {
        return o.code == this.deviceInfo.onlineState
      }).color
    },
    getAlarmColor() {
      return lodash.find(this.alarmStateOptions, (o) => {
        return o.code == this.deviceInfo.alarmState
      }).color
    },
  },
  methods: {
    //回传选中设备
    changeRobot() {
      this.$emit('changeRobot', this.deviceInfo)
    },
  },
}
</script>

<style lang="scss" scoped>
.robotbar {
  background-color: #1278e1;
  color: white;
  height: 47px;
  display: flex;
  gap: 10px;
  width: 100%;
  border-radius: 5px !important;
  .name {
    margin-top: 10px;
    width: 150px;
    height: 27px;
    min-width: 80px;
    line-height: 27px;
    font-size: 16px;
    display: inline-block;
    vertical-align: middle;
    text-align: center;
  }
  .online-state {
    margin-top: 10px;
    width: 82px;
    min-width: 82px;
    height: 27px;
    display: inline-block;
    border-radius: 15px;
    background-color: #063e92;
    .light {
      width: 12px;
      height: 12px;
      display: inline-block;
      margin-left: 12px;
      margin-top: 8px;
      border-radius: 5px;
    }
    .text {
      display: inline-block;
      margin-left: 12px;
      font-size: 14px;
      height: 10px;
    }
  }
  .alarm-state {
    margin-top: 10px;
    width: 82px;
    min-width: 82px;
    height: 27px;
    display: inline-block;
    border-radius: 15px;
    background-color: #063e92;
    .light {
      width: 12px;
      height: 12px;
      display: inline-block;
      margin-left: 12px;
      margin-top: 8px;
      border-radius: 5px;
    }
    .text {
      display: inline-block;
      margin-left: 12px;
      font-size: 14px;
      height: 10px;
    }
  }
}
</style>
