<template>
  <div class="smart-control">
    <div v-for="item in list" :key="item.name">
      <p>
        <img :src="require(`@/assets/images/${getStatus(item.status).icon}`)"/>
        设备名称：{{item.name}}
      </p>
      <p>
        <span :style="`background:${getStatus(item.status).color}`"></span>
        状态：{{getStatus(item.status).txt}}
      </p>
      <span :class="item.status === 1 ? 'on' : ''">禁用</span>
    </div>
  </div>
</template>

<script>
export default {
  name: 'SmartControl',
  data() {
    return {
      list: [
        {name: '1号塘', status: 0},
        {name: '2号塘', status: 1},
        {name: '3号塘', status: 0},
        {name: '4号塘', status: 2},
      ]
    }
  },
  methods: {
    getStatus(status) {
      switch (status) {
      case 0:
        return {
          icon: 'gray.png',
          color: '#a9a9ab',
          txt: '不在线'
        }
      case 1:
        return {
          icon: 'green.png',
          color: '#73fe3e',
          txt: '在线'
        }
      case 2:
        return {
          icon: 'red.png',
          color: '#fe2323',
          txt: '异常'
        }
      default:
        break
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
.smart-control
  width 100%
  height 100%
  overflow hidden
  >div
    display flex
    align-items center
    margin 1rem 0
    p
      display flex
      align-items center
      &:nth-child(2)
        margin-left 1rem
        flex 1
      img
        width 2rem
        height @width
        margin-right .5rem
      >span
        display inline-block
        width 1rem
        height @width
        border-radius 50%
        margin-right .5rem
    >span
      padding .1rem .5rem
      border-radius 1.2rem
      background #999
      font-weight bold
      cursor pointer
      align-self end
      border .1rem solid #999
      &.on,
      &:hover
        border .1rem solid $edgeColor
        color $edgeColor
        background $color-map()
</style>
