<!--
 * @FilePath: \wwwd:\code\screenFront\src\views\Offsite\content\right.vue
 * @Author: 王路平
 * @文件版本: V1.0.0
 * @Date: 2023-02-16 11:30:31
 * @Description: 
 * 
 * 版权信息         : 2023 by ${再登软件}, All Rights Reserved.
-->

<template>
  <div class="content-left">
    <el-row>
      <el-col>
        <equipment ref="equipment1" :title="t('messages.DevType')"></equipment>
        <equipment ref="equipment2" :title="t('messages.DevStatus')"></equipment>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
import { onBeforeMount, onMounted, reactive, ref, watch } from "vue";
import { calcWH } from "@/components/ts/selfAdaption";
import equipment from "./chart/equipment.vue";
import { Offsite } from "@/store/module/offsite";
import { useI18n } from 'vue-i18n'
let {t} = useI18n();
const store = Offsite();
let props = defineProps<{
  width: number;
  height: number;
}>();

//内容dom-------------------------
let equipment1 = ref();
let equipment2 = ref();

//---------------------------

watch(
  () => props,
  (newVal, oldVal) => {
    //监听父组件宽高变化，随时重置本组件尺寸
    reset(newVal);
  },
  { immediate: true, deep: true, flush: "post" }
);

//---------------------------

function reset(val: any) {
  //宽高为0时跳出该方法
  if (!val.width && !val.height) return;
  Pie(val.width, val.height);
}

const Pie = (width: any, height: any) => {
  let a = calcWH(height, width, 2, 1, 0);

  //   a.oHeight=a.oHeight
  //修改高度
  equipment1.value.setchartWH(a.oWidth, a.oHeight - 30);
  equipment2.value.setchartWH(a.oWidth, a.oHeight - 30);
};

onMounted(() => {});
watch(
  () => store.devtype,
  (newVal, oldVal) => {
    let arr = [];
    newVal.forEach((res) => {
      arr.push({ name: res.name, value: res.counts });
    });
    equipment1.value.setData(arr);
  },
  { deep: true, flush: "post" }
);
watch(
  () => store.itemDevNum,
  (newVal, oldVal) => {
    let arr = [];
    newVal.forEach((res) => {
      if (res.type == t('messages.OnProduct') || res.type == t('messages.OffProduct')) {
        arr.push({ name: res.title, value: res.num });
      }
    });
    equipment2.value.setData(arr);
  },
  { deep: true, flush: "post" }
);
</script>

<style scope>
.content-left {
  width: 100%;
}
</style>
