<!--
 * @FilePath: \wang-vue-worke:\demo\daping\src\views\Mechanics\child\son\components\progress.vue
 * @Author: 王路平
 * @文件版本: V1.0.0
 * @Date: 2023-02-14 13:24:12
 * @Description: 
 * 
 * 版权信息         : 2023 by ${再登软件}, All Rights Reserved.
-->

<template>
    <div class="waterborder">
  <border4 ref="refborder4">
      <template v-slot>
        <!-- <h1>{{props.title}}</h1> -->
        <div ref="progress"></div>
      </template>
  </border4>
  </div>
</template>

<script setup lang="ts">
import {getCurrentInstance, onMounted, reactive, ref} from "vue"
import {EDataPerson,EDataPersonItem} from '@/type/Mechanics'
import 'echarts-liquidfill'

import border4 from "@/components/borderBox/border4.vue"
const { proxy } = getCurrentInstance() as any;
let props=defineProps<{
      title:string,
      }>()
let progress=ref()

let refborder4=ref()

const echartsData = reactive<EDataPerson>({
  MTBF:{
      div:null,
      data:null,
      title:'',
      box:null
  },
})

const setData=()=>{

    echartsData.MTBF!.div=progress.value
  echartsData.MTBF!.title=props.title
  echartsData.MTBF!.data=({
          title: {
            // 标题
            text: echartsData.MTBF!.title,
            textStyle:{
          color:'#fff',
          fontSize:20
            }
          },
           series: [{
    type: 'liquidFill',
    radius: '80%', //水球大小
    center: ['50%', '50%'],
    waveAnimation: true,
    color: [
      {
        type: 'linear',
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [
          {
            offset: 0,
            color: '#138FE2',
          },
          {
            offset: 1,
            color: '#126ABC',
          },
        ],
        globalCoord: false,
      },
    ],
    data: [0.7,0.7], // data个数代表波浪数
    amplitude: 10, //振幅
    backgroundStyle: {
      borderWidth: 2, //边框大小
      borderColor:'rgba(17, 94, 176, 0.8)',//边框颜色
      color: 'rgba(17, 94, 176, 0.4)',
    },
    label: {
      normal: {
        textStyle: {
          fontSize: 24,
          fontWeight: 'bold',
          color: '#fff',
        },
        formatter:50+'%'
      },
      
    },
    outline: {
      borderDistance: 0,
      itemStyle: {
        borderWidth: 4,
        borderColor: 'transparent',
      },
    },
            }],
        })


change(echartsData.MTBF)
}

const change = (item:EDataPersonItem) => {
  let Ebox=proxy.$echarts.init(
  item.div,
  "dark"
);
Ebox.setOption(item.data);
item.box = Ebox
};

function setchartWH(width:any,height:any){
  console.log("??????????????????????????");
  
    echartsData.MTBF!.div=progress.value
    progress.value.style.height=height+'px'
    progress.value.style.width=width+'px'
  
  refborder4.value.resetWH()
if(echartsData.MTBF.box){
  echartsData.MTBF.box.resize()
}

}
onMounted(() => {
    setData()
})

// return{setchartWH}
defineExpose({
  setchartWH,
//   setData
})

</script>

<style scoped>
.waterBox{
    border-radius: 50%;
    background-color: #526DC1;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 20px;
    font-size: 20px;
}
.waterborder{
    position: relative;
}
.waterborder h1{
    position: absolute;
    top: 20px;
    left:20px;
    color: #fff;
}
</style>
