<!--
 * @FilePath: \wwwd:\code\screenFront\src\views\Mechanics\content\bottom.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 :span="24" class="equipmentCol">
        <!-- <devList ref="devlist1" :title="'设备明细'"></devList> -->
        <equipment ref="equipment1" :title="t('messages.JingJiaDevStatus')"></equipment>
        <equipment ref="equipment2" :title="t('messages.JiJiaDevStatus')"></equipment>
        <equipment ref="equipment3" :title="t('messages.DaJianDevStatus')"></equipment>
        <equipment ref="equipment4" :title="t('messages.JingShiDevStatus')"></equipment>
        <equipment ref="equipment5" :title="t('messages.HanJieDevStatus')"></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 {useMechanicsStore} from "@/store/module/Mechanics"
import { useI18n } from 'vue-i18n'
let {t} = useI18n();
const store = useMechanicsStore()
let props = defineProps<{
  width: number;
  height: number;
}>();

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

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

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

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

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

const box = (width: any, height: any) => {
  console.log(width,height);
  
  let a = calcWH(height, width, 1, 5, 0);

  //   a.oHeight=a.oHeight
  //修改高度
  equipment1.value.setchartWH(a.oWidth, a.oHeight);
  equipment2.value.setchartWH(a.oWidth, a.oHeight);
  equipment3.value.setchartWH(a.oWidth, a.oHeight);
  equipment4.value.setchartWH(a.oWidth, a.oHeight);
  equipment5.value.setchartWH(a.oWidth, a.oHeight);
};
watch(()=>store.devstatus,(newVal, oldVal)=>{
  if(!oldVal){
    setdata(newVal,1)
  }else{
    setdata(newVal,2)
  }
  
  },{deep:true,flush:'post'})

onMounted(() => {
  // setdata()

});
function setdata(data:any,type:number) {
  data.forEach(res=>{
    if(res.name=='精加车间'){
      equipment1.value.setData(res.data,type);
    }else if(res.name=='机加车间'){
      equipment2.value.setData(res.data,type);
    }
    else if(res.name=='大件车间'){
      equipment3.value.setData(res.data,type);
    }
    else if(res.name=='精饰车间'){
      equipment4.value.setData(res.data,type);
    }
    else if(res.name=='焊接车间'){
      equipment5.value.setData(res.data,type);
    }
  })


}
</script>

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