<!--
 * @Author: your name
 * @Date: 2022-03-25 17:15:31
 * @LastEditTime: 2022-03-26 15:33:25
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /gassafety-progress/gassafetyprogress-web/src/views/operationMonitor/monitorData/component/charsData/CzCard.vue
-->

<template>
  <div class="czcard">
    <div
      class="card"
      :style="{ height: transitionHeight }"
      :class="{ hide: carHide }"
    >
      <div class="title flex">
        <div class="left">
          <div class="device">{{title}}</div>
          <slot name="chackbox" />
        </div>
        <div class="right">
          <i
            class="iconfont icon-jt"
            @click="hide"
            :class="{ active: !carHide }"
          ></i>
        </div>
      </div>
      <div ref="container">
        <slot name="container" />
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";

export default {
  props:{
    title:String,
  },
  data() {
    return {
      carHide: true,
      transitionHeight: "60px",
    };
  },
 
  computed: {
    ...mapGetters(["sidebar"]),
  },
  watch: {
    ["sidebar.opened"](val) {
      setTimeout(this.getHeight, 200);
      // this.getHeight();
    },
  },
  mounted() {
    this.getHeight();
  },

  methods: {
    hide() {
      this.carHide = !this.carHide;
    },
    getHeight() {
      const { height } = this.$refs?.container?.getBoundingClientRect();
      if(!height){
        return;
      }
      // 高度必须是一个指定的值才能过渡变化，这样就计算出了整个元素的指定高度，然后赋值
      if (height > 0) {
        this.transitionHeight = height + 60 + 18 + "px";
      }else{
        this.transitionHeight="60px";
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.card {
  transition: all 0.5s;
  // height: 212px;
  background: #ffffff;
  box-shadow: 2px 0px 12px 1px rgba(0, 0, 0, 0.1);
  border-radius: 4px 4px 4px 4px;
  border: 1px solid #e6ebf5;
  box-sizing: border-box;
  padding: 15px 22px 18px 22px;
  overflow: hidden;
  margin-bottom:20px;
  &.hide {
    height: 60px !important;
  }
  .title {
    margin-bottom: 12px;
    margin-left: 40px;
    .left {
      display: flex;
      .device {
        font-size: 18px;
        color: #666666;
        font-weight: 500;
        margin-right: 62px;
      }
    }
    .right {
      i {
        transition: all 0.5s;
        display: inline-block;
        font-size: 30px;
        color: #c4c4c4;
        cursor: pointer;
        &.active {
          transform: rotate(90deg);
        }
      }
    }
  }
}
.flex {
  display: flex;
  justify-content: space-between;
}
</style>