<template>
  <div class="device">
    <div class="device-item" v-for="item in deviceList" :key="item">
      <div class="item-header">
        <div style="display: flex; width: 50%">
          <div class="icon-bg"></div>
          <div class="title">
            <span class="number">521245786665412</span>
            <span class="name">逆变器1</span>
            <span class="number type">逆变器</span>
          </div>
        </div>

        <div class="status">
          <div class="status-item">
            <span>在线</span>
            <span class="text">在线状态</span>
          </div>
          <div class="status-item">
            <span>在线</span>
            <span class="text">故障状态</span>
          </div>
          <div class="status-item">
            <span>在线</span>
            <span class="text">工作状态</span>
          </div>
        </div>
      </div>
      <div class="item-content">
        <div v-for="info in chunengInfo" :key="info.key">
          <span class="text">{{ info.label }}：</span>
          <a-button
            v-if="info.key === 'realTimeData'"
            type="primary"
            size="small"
            @click="openModal"
            >查看</a-button
          >
          <span v-else class="value">{{ info.value }}</span>
        </div>
      </div>
    </div>
    <a-modal v-model:open="modalOpen" @ok="handleOk" width="800px">
      <!-- <p>Some contents...</p>
      <p>Some contents...</p>
      <p>Some contents...</p> -->
    </a-modal>
  </div>
</template>

<script>
import { postReq, getReq } from '@/request/api'
export default {
  name: '',
  components: {},
  props: {
    stationId: {
      type: String,
      default: ''
    },
    systemType: {
      type: Number,
      default: 1
    }
  },
  data() {
    return {
      modalOpen: false,
      deviceList: [],
      chunengInfo: [
        { label: '运行模式', key: 'operationMode', value: '并网运行' },
        { label: '电池储能容量', key: 'batteryCapacity', value: '100kWh' },
        { label: '实时电压', key: 'voltage', value: '232.5V' },
        { label: '功率因数', key: 'powerFactor', value: '0.95' },
        { label: '实时电流', key: 'current', value: '0.01A' },
        { label: '额定电压', key: 'ratedVoltage', value: '232.5V' },
        { label: '实时功率', key: 'power', value: '0.01kW' },
        { label: '额定电流', key: 'ratedCurrent', value: '0.01A' },
        { label: '实时数据', key: 'realTimeData', value: '0.01kWh' },
        { label: '额定功率', key: 'ratedPower', value: '0.01kW' },
        { label: '冷却方式', key: 'coolingMethod', value: '风冷' }
      ]
    }
  },
  watch: {
    // 监听父组件数据变化
    stationId(newVal) {
      if (newVal) {
        this.getDeviceList()
      }
    },
    systemType(newVal, oldVal) {
      if (newVal !== oldVal) {
        this.getDeviceList()
      }
    }
  },
  mounted() {
    this.getDeviceList()
  },
  methods: {
    async getDeviceList() {
      const data = {
        category: this.systemType,
        'station_id': this.stationId,
        page: 0,
        'page_size': 1000
      }
      try {
        const res = await getReq('/queryDeviceList', data)

        console.log(res)
        this.deviceList = res.data
        // this.selectStation=this.stations[0]['station_id']
      } catch (error) {
        console.log(error)
      }
    },
    openModal() {
      this.modalOpen = true
    },
    handleOk() {
      this.modalOpen = false
    }
  }
}
</script>

<style lang="scss" scoped>
.device {
  width: 100%;
  height: 100%;
  margin-left: 20px;
  display: grid;
  grid-gap: 20px;
  grid-template-columns: 1fr 1fr 1fr;
  overflow-y: auto;
  .device-item {
    // width: 410px;
    // height: 340px;
    border-radius: 15px;

    background: $bg2-color;
    padding: 15px;
    .item-header {
      display: flex;
      align-items: center;
      height: 70px;
      color: #fff;
      justify-content: space-between;
      .icon-bg {
        width: 76px;
        height: 72px;
        border-radius: 6px;
        background: linear-gradient(90deg, #3dfefa 0%, #2a82e4 2.96%, #27a188 100%),
          linear-gradient(90deg, #3dfefa 0%, #01dfef 2.96%, #08a5ff 100%);
      }
      .title {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        margin-left: 15px;
      }
      .number {
        font-size: 12px;
      }
      .name {
        font-size: 14px;
      }
      .type {
        color: #08a5ff;
      }
      .status {
        display: flex;
        font-size: 14px;
        height: 100%;
        width: 50%;
        justify-content: space-between;
        &-item {
          display: flex;
          flex-direction: column;
          text-align: center;
          justify-content: space-evenly;
          span:first-child {
            font-weight: 700;
          }
          .text {
            color: $text-color;
          }
        }
      }
    }
    .item-content {
      grid-template-columns: 1fr 1fr;
      color: #fff;
      display: grid;
      line-height: 45px;
      margin-top: 15px;
      padding: 0 10px;
      .value {
        font-weight: 700;
      }
    }
    .text {
      color: $text-color;
    }
    .video {
      margin-top: 10px;
    }
  }
}
.environment {
  width: 200px;
}
</style>
