<template>
  <div class="common-wrap" v-if="mapValues.length > 0">
    <div class="row-item" v-for="item in mapValues">
      <div class="basic-item">
        <div class="icon">
          <img src="/static/images/icon_guide@2x.png">
        </div>
        <div class="txt">
          {{ item.name }}
        </div>
        <div class="value">{{ item.value }}{{ item.unit }}</div>
      </div>
      <div class="child-item" v-if="item.children && item.children.length >0 ">
        <Zydbsx :data="item.children" :fetchData="fetchData"/>
      </div>
    </div>
  </div>
</template>

<script>

import {chartTodoList} from '@/api/dashboard-json'

export default {
  name: 'Zydbsx',
  props: {
    data: {
      type: Array,
      default: null
    },
    fetchData: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      mapValues: []
    }
  },
  watch: {
    data: {
      immediate: true,
      handler(newVal) {
        if (Array.isArray(newVal) && !this.fetchData) {
          this.mapValues = newVal
        }
      }
    }
  },
  created() {
    if (this.fetchData) {
      this.mapValues = [
        {value: 0, name: '远动调试本月还有', unit: '个特检'},
        {value: 0, name: '电力受电线路', unit: '条'},
        {value: 0, name: '电力变配电所', unit: '座'},
        {value: 0, name: '电力设备巡检待检', unit: '个'},
        {value: 0, name: '变电所待实验', unit: '个'}
      ]
      this.getData()
    }
  },
  methods: {
    getData() {
      chartTodoList().then(res => {
        const mapArr = ['ydts', 'dlsdxl', 'dlbpds', 'dlsbxj', 'bdsdsy']
        debugger
        this.mapValues.forEach((item, index) => {
          item.value = res.info?.[mapArr[index]]
        })
      })
    }
  }
}
</script>


<style scoped lang="scss">

.common-wrap {
  width: 100%;
  height: 100%;
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
  /*控制整个滚动条*/

  .row-item {
    flex: 1;
    width: 100%;

    font-size: 0.8vw;
    padding: 8px 28px;
    display: flex;
    flex-direction: column ;
    align-items: flex-start;
    justify-content: center;

    .basic-item {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .icon {
        flex-shrink: 0;
        margin-right: 14px;
        display: flex;
        align-items: center;
        justify-content: center;

        img {
          width: 0.8vw;
          height: 0.8vw;
        }
      }

      .txt {
        flex-grow: 1;
        height: fit-content;
        width: 100%;
        display: flex;
        flex-direction: column;
      }

      .value {
        font: normal 18px hxb;
        color: #25e3fa;
        margin-left: auto;
        width: 5vw;
        text-align: right;
      }
    }

    .child-item {
      ::v-deep {
        .common-wrap {
          height: auto !important;

          .row-item {
            padding-right: 0 !important;

          }
        }

      }
    }

  }

}

</style>
