<template>
  <div class="operationlInfo">
    <div class="content">
      <div v-for="item in list" :key="item.key" :class="`item ${item.class}`">
        <a-image :preview="false" :src="item.iconPath" :width="50" class="left"> </a-image>
        <div class="right">
          <span class="k">{{ item.label }}</span>
          <div>
            <span class="v">{{ item.value }}</span>
            <span class="d">{{ item.d }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: '',
  props: {
    propKey: { type: String, default: '' },
    propData: { type: Object, default: () => { } },
  },
  data() {
    return {
      itemDef: {
        U: { key: 'U', value: '--', d: 'V', label: '电压', class: 'item-3', iconPath: require('@/assets/home/dianya.png') },
        I: { key: 'I', value: '--', d: 'A', label: '电流', class: 'item-4', iconPath: require('@/assets/home/dianliu.png') },
        P: { key: 'P', value: '--', d: 'kW', label: '功率', class: 'item-5', iconPath: require('@/assets/home/gonglv.png') },
        // PF: { key: 'PF', value: '--', d: '', label: '功率因数', class: 'item-6', iconPath: require('@/assets/home/gonglv.png') }
      },
    }
  },
  computed: {

  },
  watch: {
    propKey: {
      handler(newVal, oldVal) {
        if (this.propKey === 'grid') {
          this.list = [this.itemDef.P]
        }
        else if (this.propKey === 'pv') {
          this.list = [this.itemDef.P]
        }
        else {
          this.list = [this.itemDef.U, this.itemDef.I, this.itemDef.P]
        }
      },
      immediate: true,
    },
    propData: {
      handler(newVal, oldVal) {
        if (newVal !== oldVal) {
          this.list.forEach((item) => {
            item.value = this.propData[item.key] || 0
          })
        }
      }
    }
  },
  mounted() { },
  methods: {}
}
</script>

<style lang="scss" scoped>
.operationlInfo {
  height: calc(100% - 45px);
  display: flex;
  // justify-content: center;
  align-items: center;
  width: 95%;
  margin: auto;
}

.content {

  flex-wrap: wrap;
  width: 100%;
  display: flex;
  // align-items: center;
  // justify-content: space-around;
  height: 100%;
  padding-left: calc(10%);

  .item {
    width: 30%;
    height: 50px;
    box-sizing: border-box;
    display: flex;
    // align-items: center;
    // justify-content: center;
    // text-align: center;
  }

  .right {
    display: flex;
    flex-direction: column;
    margin-left: 10px;

    .k {
      color: #e0e0e0;
      font-size: 12px;
    }

    .v {
      color: #a0f0a0;
      font-size: 16px;
    }

    .d {
      margin-left: 8px;
      font-size: 14px;
    }
  }
}
</style>