<template>
  <div class="prefabCabin">
    <div style="display: flex; flex-direction: row; flex-wrap: wrap;" >
      <div v-for="item in [...myItemsInfo, ...myItemsStats]" :key="item.key" :class="`item ${item.class}`">
        <div style="display: flex; flex-direction: column; justify-items: flex-start;">
          <span style="color: #e0e0e0;">{{ item.label }}</span>
          <div style="display: flex; justify-content: flex-end; line-height: 1;">
            <span class="v">{{ item.value ? item.value : 0 }}</span>
            <span class="d">{{ item.d }}</span>
          </div>
        </div>
      </div>
    </div>

    <!-- <div class="content-left">
      <div v-for="item in leftList" :key="item.key" :class="`item ${item.class}`">
        <div>
          <span>{{ item.value ? item.value : 0 }}</span
          ><span class="d">{{ item.d }}</span>
        </div>
        <span>{{ item.label }}</span>
      </div>
    </div> -->
    <!-- <div style="text-align: center; font-weight: 500">
      <div class="prefabCabin-icon"></div>
      <span>{{ curStatus }}</span>
    </div> -->

    <!-- <div class="content-right">
      <div v-for="item in rightList" :key="item.key" :class="`item ${item.class}`">
        <div>
          <span>{{ item.value ? item.value : 0 }}</span
          ><span class="d">{{ item.d }}</span>
        </div>
        <span>{{ item.label }}</span>
      </div>
    </div> -->
  </div>
</template>

<script>
export default {
  name: '',
  props: {
    propData: { type: Object, default: () => {} },
    propsTotal: {
      type: Object,
      default: () => {}
    },
    propsInfo: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      curStatus: '充电',
      myItemsInfo: [
        { key: 'capacity', value: '', label: '电池储能容量', d: 'kWh' },
        { key: 'voltage_rated', value: '', label: '电池额定总电压', d: 'V' },
        { key: 'cooling_type', value: '', label: '冷却方式', d: '' },
        { key: 'batttey_type', value: '', label: '电池类型', d: '' },
        { key: 'run_days', value: '', label: '场站运行天数', d: '天' },
      ],
      myItemsStats: [
        { key: 'storage_device_num', value: '', label: '储能设备数量', d: '个' },
        { key: 'solar_device_num', value: '', label: '光伏设备数量', d: '个' },
        { key: 'charge_device_num', value: '', label: '充电设备数量', d: '个' },
        { key: 'solar_elect_grid', value: '', label: '上网总电量', d: 'kWh' },
        { key: 'storage_elect_in', value: '', label: '储能充电总电量', d: 'kWh' },
        { key: 'solar_elect_gen', value: '', label: '光伏发电总电量', d: 'kWh' },
        { key: 'charge_elect', value: '', label: '充电桩充电总电量', d: 'kWh' },
        { key: 'income_elect', value: '', label: '收益总金额', d: '元' },
        { key: 'storage_elect_out', value: '', label: '储能放电总电量', d: 'kWh' },
      ],
      list: [
        {
          key: 'batttey_type',
          value: '磷酸铁锂电池',
          d: '',
          label: '电池类型',
          class: 'item-1'
        },
        {
          key: 'cooling_type',
          value: '风冷',
          d: '',
          label: '冷却方式',
          class: 'item-2'
        },
        {
          key: 'voltage_rated',
          value: 20,
          d: 'V',
          label: '电池额定总电压',
          class: 'item-3'
        },
        {
          key: 'work_mode',
          value: '最优经济化运行模式',
          d: '',
          label: '运行模式',
          class: 'item-4',
          list:[
            {
              label:'手动',
              value:0
            },
            {
              label:'峰谷套利',
              value:1
            },
            {
              label:'配网增容',
              value:2
            },
            {
              label:'应急供电',
              value:3
            },
            {
              label:'并网保电',
              value:4
            },
            {
              label:'运营支撑',
              value:5
            },
          ]
        },
        {
          key: 'capacity',
          value: 20,
          d: 'Wh',
          label: '电池储能容量',
          class: 'item-5'
        },
        {
          key: 'power_rated',
          value: 100,
          d: 'Kw',
          label: '额定功率',
          class: 'item-6'
        }
      ]
    }
  },
  computed: {
    leftList() {
      return this.list.filter((_, index) => index % 2 === 0).slice(0, 3) // 左列取前3个偶数索引
    },
    rightList() {
      return this.list.filter((_, index) => index % 2 !== 0).slice(0, 3) // 右列取前3个奇数索引
    }
  },
  watch: {
    propData: {
      handler(newVal, oldVal) {
        if (newVal !== oldVal) {
          if (this.propData.stats) {
            this.myItemsStats.forEach((item) => { 
              item.value = this.propData.stats[item.key] != undefined ? this.propData.stats[item.key] : '--'
            });
          }
          if (this.propData.info) {
            this.myItemsInfo.forEach((item) => { 
              item.value = this.propData.info[item.key] != undefined ? this.propData.info[item.key] : '--'
            });
          }
        }
      }
    },

    propsTotal: {
      handler(newVal, oldVal) {
        if (newVal !== oldVal) {

          


          // 0正常 1故障
          this.curStatus=['故障','正常'][this.propsTotal.status]
          // this.list.forEach((item) => {
          //   if(item.key=='work_mode'){
          //     item.value = ['手动','峰谷套利','配网增容','应急供电','并网保电','运营支撑'][this.propsTotal[item.key]]
          //     // console.log(item.list.map((item)=>this.propsTotal[item.key]==item.value)[0].label,"145",item.list.map((item)=>this.propsTotal[item.key]==item.value))
          //     // item.value =item.list.map((item)=>==item.value)[0].label
          //   }else {
          //     item.value = this.propsTotal[item.key]
          //   }
          // })
        }
      }
    }
  },
  mounted() {},
  methods: {}
}
</script>

<style lang="scss" scoped>
.prefabCabin {
  height: calc(100% - 45px);
  display: flex;
  justify-content: center;
  align-items: center;
  margin-left: 10px;
  margin-right: 10px;
}

.item {
  height: 40px;
  width: calc(25% - 5px);
  margin-right: 5px;
  margin-bottom: 5px;
  background: url('@/assets/home/onLineBg.png');
  background-size: contain;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  // background: linear-gradient(
  //   180deg,
  //   rgba(15, 227, 255, 0.3) 0%,
  //   rgba(15, 227, 255, 0.09) 45.6%,
  //   rgba(15, 227, 255, 0.3) 100%
  // );
  // padding: 10px 8px;
  min-width: 115px;
  display: flex;
  flex-direction: column;
  text-align: center;

  & > span:nth-child(1) {
    padding: 0;
    margin: 0;
    font-size: 12px;
    margin-bottom: 10px;
  }
  .v {
    color: #a0f0a0;
    line-height: 1;
  }
  .d {
    display: block; 
    text-align: left;
    margin-left: 5px;
    font-size: 12px;
    min-width: 40px;
    height: 16px;
  }
}

.content-left,
.content-right {
  width: calc((100% - 110px) / 2);
  // width: 40%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
  height: 100%;
}
// .content-left{
//  align-items: self-end;
// }
// .content-right{
//   align-items:flex-start;

// }
.content-middle {
  width: 120px;
}

.prefabCabin-icon {
  width: 110px;
  height: 130px;
  background-image: url('@/assets/home/perIcon.png');
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}

.item-3 {
  margin-right: auto;
}

.item-4 {
  margin-left: auto;
}
</style>
