<!--
 * @FilePath: \screenFront\src\views\electronicControl\childContent\center.vue
 * @Author: 王路平
 * @文件版本: V1.0.0
 * @Date: 2023-04-12 08:46:57
 * @Description: 
 * 
 * 版权信息         : 2023 by ${再登软件}, All Rights Reserved.
-->
<template>
  <div class="content-center">
    <el-row :gutter="20">
      <el-col>
        <!-- <offsitegateway
            ref="offsitegatewayref"
            :title="'东莞-物联网关状态'"
          ></offsitegateway> -->
        <div style="display: flex; align-items: center;
        justify-content: space-evenly;">
          <topTitle ref="topTitleRef" :title="t('messages.DevPreviewChart')"></topTitle>
          <topTitle ref="topTitleRef2" :title="t('messages.DevPreviewChart')"></topTitle>
          <topTitle ref="topTitleRef3" :title="t('messages.DevPreviewChart')"></topTitle>
        </div>
      </el-col>
      <el-col >
        <div style="display: flex; align-items: center;
        justify-content: space-evenly;">
          <devImage ref="devImageRef" :title="t('messages.DevPreviewChart')"></devImage>
        </div>


      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
import { onMounted, reactive, ref, watch } from "vue";
import { calcWH } from "@/components/ts/selfAdaption";
import offsitegateway from "./chart/offsitegateway.vue";
import topTitle from "./chart/topTitle.vue";
import {imgurlAddXhr} from "@/utils/devSever"
import devImage from "./chart/devImage.vue";
import table1 from "@/components/assembly/RotationTable.vue";
import { useI18n } from 'vue-i18n'
let {t} = useI18n();
let props = defineProps<{
  width: number;
  height: number;
}>();

let topTitleRef = ref();
let topTitleRef2 = ref();
let topTitleRef3 = ref();
let devImageRef = ref();
let offsitegatewayref = 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) => {
  let a = calcWH(height, width, 4, 3, 0);

  //   a.oHeight=a.oHeight
  //修改高度
  devImageRef.value.setchartWH(a.oWidth*3, a.oHeight*3);
  topTitleRef.value.setchartWH(a.oWidth-10, a.oHeight);
  topTitleRef2.value.setchartWH(a.oWidth-10, a.oHeight);
  topTitleRef3.value.setchartWH(a.oWidth-10, a.oHeight);


  // offsitegatewayref.value.setchartWH(a.oWidth, a.oHeight);
};

function setDataList(val: any) {

  let tipdata = val.devnum;
  //计算设备总量
  // val.devnum.forEach((res) => {
  //   tipdata.isall += res.counts;
  // });
  // //获取在线离线数量
  // val.statusnum.forEach((res) => {
  //   if (JSON.parse(res.name)) {
  //     tipdata.ison = res.counts;
  //   } else {
  //     tipdata.isoff = res.counts;
  //   }
  // });
  //设置页面数据
  topTitleRef.value.setData({ title: t('messages.OnlineNum'), num: tipdata.ison });
  topTitleRef2.value.setData({ title: t('messages.TOTAL'), num: tipdata.isall });
  topTitleRef3.value.setData({ title: t('messages.OffNum'), num: tipdata.isoff ,color:'rgb(228, 57, 97)'});

  let electronicControl1 = require("@/assets/img/electronicControl1.jpg");
  let electronicControl2 = require("@/assets/img/electronicControl2.png");
  let electronicControl3 = require("@/assets/img/electronicControl3.png");
let data2 = [
  { image: electronicControl1, id: 1 },
  { image: electronicControl2, id: 2 },
  { image: electronicControl3, id: 3 }
];
/* 确认有图片之后再打开 */
let arrImage = val.imgArr.filter((item:String)=>item.includes("."));
arrImage = arrImage.map((item:String,index:Number)=>{ return {image:imgurlAddXhr(item),id:index}});
data2 = arrImage.length>0?arrImage:data2;
devImageRef.value.setData(data2);
}
onMounted(() => {
  // offsitegatewayref.value.setData(data1);
  // devImageRef.value.setData(data2);
});
defineExpose({
  setDataList,
});
</script>

<style scoped>
.content-center {
  width: 100%;
}
.el-col{
  margin-bottom: 20px;
}
</style>
