<template>
  <div class="container" :style="{ width: `${style.width}px`, height: `${style.height}px`, transform: `${style.transform}` }">
    <div class="content">
      <div class="c-left">
        <div class="left-header">
          <div>
            <img src="@/assets/logo2.png" alt="logo" />
          </div>
        </div>
        <div class="left-content">
          <div class="main">
            <dv-border-box-12 style="padding: 10px; width: 95%; height: 95%">
              <div style="margin: 5px 0 5px 10px">
                <span style="
                    width: 20px;
                    height: 10px;
                    background: #016ce9;
                    display: inline-block;
                  "></span>
                <span style="color: #fff">日产量</span>
              </div>
              <div id="leftTopColumnar" style="width: 105%; height: 300px;margin-top: 20px"></div>
            </dv-border-box-12>
          </div>
          <div class="main2">
            <dv-border-box-12
              style="padding: 5px 10px; width: 95%; height: 95%"
            >
              <div style="margin: 5px 0 5px 10px">
                <span
                  style="
                    width: 20px;
                    height: 10px;
                    background: #016ce9;
                    display: inline-block;
                  "
                ></span>
                <span style="color: #fff"> 稼动率</span>
              </div>
              <div style="position: relative; top: -10px">
                <div style="background-color:#fff;height: 170px;
                width: 170px;border-radius: 85px;position: absolute;top: 10px;left: 145px"></div>
                <div id="leftMiddlePie" style="z-index: 100;width: 100%; height: 200px;margin-top: 0px"></div>
              </div>
            </dv-border-box-12>
          </div>
          <div class="main3">
            <dv-border-box-12
              style="padding: 5px 10px; width: 95%; height: 95%"
            >
              <div style="margin: 5px 0 5px 10px">
                <span
                  style="
                    width: 20px;
                    height: 10px;
                    background: #016ce9;
                    display: inline-block;
                  "
                ></span>
                <span style="color: #fff"> 机器人信息</span>
              </div>
              <div>
                <div class="table-title">
                  六轴装配机器人
                </div>
                <table class="robot-table">
                  <tr>
                    <th v-for="(item,index) in deviceList[0].Axis" :key="index">{{item.AxisName}}</th>
                  </tr>
                  <tr>
                    <th v-for="(item,index) in deviceList[0].Axis" :key="index">{{item.AxisValue}}</th>
                  </tr>
                </table>
              </div>
              <div style="margin-top: 30px">
                <div class="table-title">
                  四轴搬运机器人
                </div>
                <table class="robot-table">
                  <tr>
                    <th v-for="(item,index) in deviceList[1].Axis" :key="index">{{item.AxisName}}</th>
                  </tr>
                  <tr>
                    <th v-for="(item,index) in deviceList[1].Axis" :key="index">{{item.AxisValue}}</th>
                  </tr>
                </table>
              </div>
            </dv-border-box-12>
          </div>
        </div>
      </div>

      <div class="c-center">
        <div class="center-header">徽章智能产线数字监控系统</div>
        <div class="center-content" v-if="refreshTab">
          <dv-border-box-12 class="items">
            <div style="width: 96%;margin: 20px 2%;z-index: 999;">
              <d-m-t
                ref="dmtCom"
                containerHeight="500px"
                containerWidth="100%"
              />
            </div>
<!--            <img src="@/assets/中心图.png" style="width: 96%;margin: 30px 2%" />-->
            <div class="item-content">
              <dv-border-box-12 class="middle-bottom">
                <div style="margin: 5px 0 5px 10px">
                <span
                  style="
                    width: 20px;
                    height: 10px;
                    background: #016ce9;
                    display: inline-block;
                  "
                ></span>
                  <span style="color: #fff"> 设备运行履历</span>
                </div>
                <div id="middleButton" style="width: 100%; height: 250px;margin-top: 20px"></div>
              </dv-border-box-12>
            </div>
          </dv-border-box-12>
        </div>
      </div>
      <div class="c-right">
        <div class="right">
          <div class="right-head">
            <span>{{ time }}</span>
          </div>
          <div class="main">
            <div class="top">
              <dv-border-box-12 style="padding: 5px 10px 14px 10px; width: 95%; height: 95%">
                <div style="margin: 5px 0 5px 10px">
                  <span
                    style="
                      width: 20px;
                      height: 10px;
                      background: #016ce9;
                      display: inline-block;
                    "
                  ></span>
                  <span style="color: #fff">月度生产数据统计</span>
                </div>
                <div id="rightTopColumnar" style="width: 100%; height: 300px;margin-top: 20px"></div>
              </dv-border-box-12>
            </div>
            <div class="center">
              <dv-border-box-12 style="padding: 5px 10px; width: 95%; height: 95%">
                <div style="margin: 5px 0 5px 10px">
                  <span
                    style="
                      width: 20px;
                      height: 10px;
                      background: #016ce9;
                      display: inline-block;
                    "
                  ></span>
                  <span style="color: #fff"> 故障统计</span>
                </div>
                  <div id="rightMiddlePie" style="width: 100%; height: 200px"></div>
              </dv-border-box-12>
            </div>
            <div class="bottom">
              <dv-border-box-12 style="padding: 5px 10px; width: 95%; height: 95%">
                <div style="margin: 5px 0 5px 10px">
                  <span
                    style="
                      width: 20px;
                      height: 10px;
                      background: #016ce9;
                      display: inline-block;
                    "
                  ></span>
                  <span style="color: #fff"> 工位状态</span>
                </div>
                <table class="robot-table" style="margin-top: 40px">
                  <tr>
                    <th>ST10工站</th>
                    <th>ST20工站</th>
                    <th>ST30工站</th>
                    <th>ST40工站</th>
                  </tr>
                  <tr v-for="index in 4" :key="index">
                    <td>{{deviceList[0].Status[index-1].StatusName}} <span class="status" :style="{ backgroundColor:deviceList[0].Status[index-1].StatusValue == '1' ? '#98d87d' : '#f3857c'}"></span> </td>
                    <td>{{deviceList[1].Status[index-1].StatusName}} <span class="status" :style="{ backgroundColor:deviceList[1].Status[index-1].StatusValue == '1' ? '#98d87d' : '#f3857c'}"></span> </td>
                    <td>{{deviceList[2].Status[index-1].StatusName}} <span class="status" :style="{ backgroundColor:deviceList[2].Status[index-1].StatusValue == '1' ? '#98d87d' : '#f3857c'}"></span> </td>
                    <td>{{deviceList[3].Status[index-1].StatusName}} <span class="status" :style="{ backgroundColor:deviceList[3].Status[index-1].StatusValue == '1' ? '#98d87d' : '#f3857c'}"></span> </td>
                  </tr>
                </table>
              </dv-border-box-12>
            </div>
          </div>
        </div>
        <!--<index />-->
      </div>
    </div>
  </div>
</template>
<script>

import { opname, mqttIp, mqttPort } from '@/utils/request'
import mqtt from 'mqtt';
import DMT from '@/components/DMT/index'
import * as echarts from 'echarts'

export default {
  components: {
    DMT
  },
  data () {
    return {
      mqttClient: null,
      dt_IframeUrl: '',
      timer1: null,
      refreshTab: true,
      planCountInfo: [4624, 2696, 58.3, 1252, 50, 96],
      config: {},
      config2: {},
      config3: {},
      data: [],
      data2: [],
      data3: [],
      energyAll: [0, 0, 0],
      OpStatusList:[
        [{name:'自动运行',value:true},{name:'自动运行','value':true},{name:'自动运行','value':true},{name:'自动运行','value':true},],
        [{name:'手动暂停',value:true},{name:'手动暂停','value':true},{name:'手动暂停','value':true},{name:'手动暂停','value':true},],
        [{name:'报警待机',value:false},{name:'报警待机','value':false},{name:'报警待机','value':false},{name:'报警待机','value':false},],
        [{name:'初始化',value:true},{name:'初始化','value':true},{name:'初始化','value':true},{name:'初始化','value':true},],
      ],
      mainShowIndex: 'jd',
      开始日期: '',
      leftTopColumnar: null, // 左上曲线
      leftMiddlePie: null, // 左中饼图
      rightTopColumnar: null, // 右上柱状
      rightMiddlePie: null, // 右中饼图
      middleButton:null, // 中间不知道啥图

      leftTopColumnarOption: null, // 左上曲线配置
      leftMiddlePieOption: null, // 左中饼图配置
      rightTopColumnarOption: null, // 右上柱状配置
      rightMiddlePieOption: null, // 右中饼图配置
      middleButtonOption:null, // 中间不知道啥图配置

      leftTopCurveX: [],
      leftTopCurveXData1: [],
      leftTopCurveXData2: [],
      leftTopCurveXData3: [],
      leftTopCurveXData4: [],
      leftBottomPieData: {
        外派: '0',
        采购: '0',
        自制: '0'
      },
      leftBottomColumnarX: [],
      leftBottomColumnarXData1: [],
      leftBottomColumnarXData2: [],
      leftBottomColumnarXData3: [],
      rightMiddleCurveX: [],
      rightMiddleCurveXData1: [],
      rightMiddleCurveXData2: [],
      rightMiddleCurveXData3: [],
      rightBottomPieDataColor: ['#49a9ee', '#98d87d', '#ffd86e', '#f3857b', '#8996e6'],
      rightBottomPieData: [
        { value: 70, name: '设备问题', itemStyle: { color: '#49a9ee' }},
        { value: 56, name: '物料问题', itemStyle: { color: '#98d87d' }},
        { value: 40, name: '工艺问题', itemStyle: { color: '#ffd86e' }},
        { value: 20, name: '加工问题', itemStyle: { color: '#f3857b' }},
        { value: 12, name: '人员问题', itemStyle: { color: '#8996e6' }}
      ],
      style: {
        width: '1920',
        height: '1080',
        transform: 'scaleY(1) scaleX(1) translate(-50%, -50%)'
      },
      timer: '',
      time: 'time',
      deviceStatus_colors: ['grey', 'orange', 'green', 'green', 'blue'],
      deviceStatus_state: ['关机', '待机', '运行', '报警', '暂停'],
      deviceStatus_table: [],
      leftTopColumnarX:[],
      leftTopColumnarXData:[],
      rightTopColumnarX:[],
      rightTopColumnarXData:[],
      leftMiddlePieData:0,
      leftMiddlePiePlanData:0,
      leftMiddlePiePlanText:'比目标值高 40%',
      rightMiddlePieData:[],
      rightMiddlePieColorList:['#e2ae03','#aa493c','#459763','#49a9ee'],
      deviceList: [
        // ST10
        {
          'Name': window.dt_Config.OpName1, // 设备名称
          'Id': '1', // 设备ID
          'Status': [{StatusName:'自动运行',StatusValue:'1'},{StatusName:'手动暂停',StatusValue:'1'},{StatusName:'报警待机',StatusValue:'0'},{StatusName:'初始化',StatusValue:'1'}], // [{StatusName:'自动运行','StatusValue':'1'},{StatusName:'手动暂停','StatusValue':'0'}] 设备运行状态 需要明确有几个状态，具体的值
          'Program': '', // 设备运行的程序名称
          'ProgramStatus': '', // 设备运行的程序状态 需要明确有几个状态，具体的值
          'Feed': '0', // 设备进给速度 确认下单位
          'Speed': '', // 设备主轴转速  确认下单位
          'Rapid': '0', // 设备移动速度 确认下单位  应该是  和高明确认下这个的含义
          'Axis': [{ AxisName: '轴1', AxisValue: '-20.04' },{ AxisName: '轴2', AxisValue: '-82.69' },{ AxisName: '轴3', AxisValue: '145.36' },{ AxisName: '轴4', AxisValue: '75.95' },{ AxisName: '轴5', AxisValue: '79.78' },{ AxisName: '轴6', AxisValue: '-29.78' }], // [{ AxisName: 'X', AxisValue: '100' }, { AxisName: 'Y', AxisValue: '100' }, { AxisName: 'Z', AxisValue: '100' }, { AxisName: 'U', AxisValue: '100' }, { AxisName: 'V', AxisValue: '100' }, { AxisName: 'W', AxisValue: '100' }],
          'Tool': {},
          'OtherParameter': [],
          'Alarm': [], // [{ AlarmCode: 'xxx4', Alarm: 'xxx4', AlarmTime: 'xxx4' }],
          'Tip': [], // [{ TipCode: 'xxx4', Tip: 'xxx4', TipTime: 'xxx4' }], // 提示
          'robotDataList': [],
          'servoLoadData': [],
          'order': '21314',
          'Voltage': '0', // 电压
          'Current': '0' // 电流
        },
        // ST20
        {
          'Name': window.dt_Config.OpName2, // 设备名称
          'Id': '2', // 设备ID
          'Status': [{StatusName:'自动运行',StatusValue:'1'},{StatusName:'手动暂停',StatusValue:'1'},{StatusName:'报警待机',StatusValue:'0'},{StatusName:'初始化',StatusValue:'0'}], // [{StatusName:'自动运行','StatusValue':'1'},{StatusName:'手动暂停','StatusValue':'0'}] 设备运行状态 需要明确有几个状态，具体的值
          'Program': '', // 设备运行的程序名称
          'ProgramStatus': '', // 设备运行的程序状态 需要明确有几个状态，具体的值
          'Feed': '0', // 设备进给速度 确认下单位
          'Speed': '', // 设备主轴转速  确认下单位
          'Rapid': '0', // 设备移动速度 确认下单位  应该是  和高明确认下这个的含义
          'Axis': [{ AxisName: '轴1', AxisValue: '-20.04' },{ AxisName: '轴2', AxisValue: '-20.04' },{ AxisName: '轴3', AxisValue: '-20.04' },{ AxisName: '轴4', AxisValue: '-20.04' }], // [{ AxisName: 'X', AxisValue: '100' }, { AxisName: 'Y', AxisValue: '100' }, { AxisName: 'Z', AxisValue: '100' }, { AxisName: 'U', AxisValue: '100' }, { AxisName: 'V', AxisValue: '100' }, { AxisName: 'W', AxisValue: '100' }],
          'Tool': {},
          'OtherParameter': [],
          'Alarm': [], // [{ AlarmCode: 'xxx4', Alarm: 'xxx4', AlarmTime: 'xxx4' }],
          'Tip': [], // [{ TipCode: 'xxx4', Tip: 'xxx4', TipTime: 'xxx4' }], // 提示
          'robotDataList': [],
          'servoLoadData': [],
          'order': '21314',
          'Voltage': '0', // 电压
          'Current': '0' // 电流
        },
        // ST30
        {
          'Name': window.dt_Config.OpName3, // 设备名称
          'Id': '1', // 设备ID
          'Status': [{StatusName:'自动运行',StatusValue:'1'},{StatusName:'手动暂停',StatusValue:'1'},{StatusName:'报警待机',StatusValue:'0'},{StatusName:'初始化',StatusValue:'0'}], // [{StatusName:'自动运行','StatusValue':'1'},{StatusName:'手动暂停','StatusValue':'0'}] 设备运行状态 需要明确有几个状态，具体的值
          'Program': '', // 设备运行的程序名称
          'ProgramStatus': '', // 设备运行的程序状态 需要明确有几个状态，具体的值
          'Feed': '', // 设备进给速度 确认下单位
          'Speed': '', // 设备主轴转速  确认下单位
          'Rapid': '', // 设备移动速度 确认下单位  应该是  和高明确认下这个的含义
          'Axis': [], // [{ AxisName: 'X', AxisValue: '100' }, { AxisName: 'Y', AxisValue: '100' }, { AxisName: 'Z', AxisValue: '100' }, { AxisName: 'U', AxisValue: '100' }, { AxisName: 'V', AxisValue: '100' }, { AxisName: 'W', AxisValue: '100' }],
          'Tool': {},
          'OtherParameter': [],
          'Alarm': [], // [{ AlarmCode: 'xxx4', Alarm: 'xxx4', AlarmTime: 'xxx4' }],
          'Tip': [], // [{ TipCode: 'xxx4', Tip: 'xxx4', TipTime: 'xxx4' }], // 提示
          'robotDataList': [],
          'servoLoadData': [],
          'order': '21314',
          'Voltage': '0', // 电压
          'Current': '0' // 电流
        },
        // ST40
        {
          'Name': window.dt_Config.OpName4, // 设备名称
          'Id': '1', // 设备ID
          'Status': [{StatusName:'自动运行',StatusValue:'1'},{StatusName:'手动暂停',StatusValue:'1'},{StatusName:'报警待机',StatusValue:'0'},{StatusName:'初始化',StatusValue:'0'}], // [{StatusName:'自动运行','StatusValue':'1'},{StatusName:'手动暂停','StatusValue':'0'}] 设备运行状态 需要明确有几个状态，具体的值
          'Program': '', // 设备运行的程序名称
          'ProgramStatus': '', // 设备运行的程序状态 需要明确有几个状态，具体的值
          'Feed': '', // 设备进给速度 确认下单位
          'Speed': '', // 设备主轴转速  确认下单位
          'Rapid': '', // 设备移动速度 确认下单位  应该是  和高明确认下这个的含义
          'Axis': [], // [{ AxisName: 'X', AxisValue: '100' }, { AxisName: 'Y', AxisValue: '100' }, { AxisName: 'Z', AxisValue: '100' }, { AxisName: 'U', AxisValue: '100' }, { AxisName: 'V', AxisValue: '100' }, { AxisName: 'W', AxisValue: '100' }],
          'Tool': {},
          'OtherParameter': [],
          'Alarm': [], // [{ AlarmCode: 'xxx4', Alarm: 'xxx4', AlarmTime: 'xxx4' }],
          'Tip': [], // [{ TipCode: 'xxx4', Tip: 'xxx4', TipTime: 'xxx4' }], // 提示
          'robotDataList': [],
          'servoLoadData': [],
          'order': '21314',
          'Voltage': '0', // 电压
          'Current': '0' // 电流
        }
      ],
    }
  },
  created () {
    // this.dt_IframeUrl = window.ConnectConfig.dt_IframeUrl
  },
  mounted () {
    const that = this

    // 页面自适应大小部分
    that.setScale()
    window.addEventListener('resize', () => {
      that.setScale()
    })

    this.initMqtt()

    // 数据库读取部分
    // this.getMainPlanCountInfoData()
    // this.getmidddlelist()
    // this.getOrderDataInfo()
    // this.getWorkDataInfo()
    // this.getUnfinishedDataInfo()
    // this.getContract2DataInfo()
    // this.getLackDataInfo()
    // this.getQualityDataInfo()
    // this.getContractMainDataInfo()

    // echarts图表绘制部分
    this.initEchartDom()
    this.setEchartData()

    // 定时器部分
    this.timer = setInterval(() => {
      this.time = this.getNowTime()
    }, 1000)
    this.timer = setInterval(() => {
      this.setEchartData()
    }, 10000)
  },
  beforeDestroy () {
    clearInterval(this.timer)
  },
  methods: {
    getMainPlanCountInfoData () {
      let data = this.CreateData1('11', '主页六个关键数据_查询')
      this.ExecDatabase(data).then((res) => {
        this.planCountInfo = []
        this.planCountInfo.push(this.num(res.data[0].当前计划))
        this.planCountInfo.push(this.num(res.data[0].当前产量))
        this.planCountInfo.push(this.num(res.data[0].计划完成))
        this.planCountInfo.push(this.num(res.data[0].工时消耗))
        this.planCountInfo.push(this.num(res.data[0].当前齐套率))
        this.planCountInfo.push(this.num(res.data[0].当前合格率))
      })
    },
    getOrderDataInfo () {
      let data = this.CreateData1('11', '左上订单看板_表格_查询')
      this.ExecDatabase(data).then((res) => {
        res.data.forEach((ele) => {
          ele.工艺部 = this.num(ele.工艺部)
          ele.采购部 = this.num(ele.采购部)
          ele.生产部 = this.num(ele.生产部)
          ele.装配部 = this.num(ele.装配部)
        })
        this.orderDataInfo = res.data
      })
    },
    getWorkDataInfo () {
      let data = this.CreateData1('11', '左中装配看板_表格_查询')
      this.ExecDatabase(data).then((res) => {
        this.workDataInfo = res.data
      })
    },
    getUnfinishedDataInfo () {
      let data = this.CreateData1('11', '左下未完成看板_表格_查询')
      this.ExecDatabase(data).then((res) => {
        this.unfinishedDataInfo = res.data
      })
    },
    getContract2DataInfo () {
      let data = this.CreateData1('11', '右上合同看板_表格_查询')
      this.ExecDatabase(data).then((res) => {
        this.contract2DataInfo = res.data
      })
    },
    getLackDataInfo () {
      let data = this.CreateData1('11', '右中缺件看板_表格_查询')
      this.ExecDatabase(data).then((res) => {
        this.lackDataInfo = res.data
      })
    },
    getQualityDataInfo () {
      let data = this.CreateData1('11', '右下质量看板_表格_查询')
      this.ExecDatabase(data).then((res) => {
        this.qualityDataInfo = res.data
      })
    },
    getContractMainDataInfo () {
      let data = this.CreateData1('11', '中间主体订单_表格_查询')
      this.ExecDatabase(data).then((res) => {
        res.data.forEach((ele) => {
          ele.工艺部 = this.num(ele.工艺部)
          ele.采购部 = this.num(ele.采购部)
          ele.生产部 = this.num(ele.生产部)
          ele.装配部 = this.num(ele.装配部)
        })
        this.contractMainDataInfo = res.data
      })
    },
    getContractMainDataInfoDetail (row) {
      let param = []
      param[0] = ['合同号', row.内部合同号]
      let data = this.CreateData1('11', '中间主体订单详情_表格_查询', param)
      this.ExecDatabase(data).then((res) => {
        if (res.data.length > 0) {
          // res.data.forEach((ele) => {
          //   ele.工艺部 = this.num(ele.工艺部)
          //   ele.采购部 = this.num(ele.采购部)
          //   ele.生产部 = this.num(ele.生产部)
          //   ele.装配部 = this.num(ele.装配部)
          // })
          this.contractMainDataInfoDetail = res.data
          this.mainShowIndex = 'jd-detail'
        }
      })
    },
    getScale () {
      const w = window.innerWidth / this.style.width
      const h = window.innerHeight / this.style.height
      return { x: w, y: h }
    },
    setScale () {
      const scale = this.getScale()
      this.style.transform = 'scaleY(' + scale.y + ') scaleX(' + scale.x + ') translate(-50%, -50%)'
    },
    initEchartDom () {
      this.leftTopColumnar = echarts.init(document.getElementById('leftTopColumnar'))
      this.leftMiddlePie = echarts.init(document.getElementById('leftMiddlePie'))
      this.rightTopColumnar = echarts.init(document.getElementById('rightTopColumnar'))
      this.rightMiddlePie = echarts.init(document.getElementById('rightMiddlePie'))
      this.middleButton = echarts.init(document.getElementById('middleButton'))
    },
    setEchartData () {
      this.getLeftTopColumnarData()
      this.getLeftMiddlePieData()
      this.getRightTopColumnarData()
      this.getRightMiddlePieData()
      this.searchChartData44() // middleButtonOptionSet
      // this.middleButtonOptionSet()
    },
    initMqtt() {
      const scope = this
      const connection = {
        host: mqttIp,
        port: mqttPort,
        endpoint: '/mqtt',
        clean: true, // 保留会话
        connectTimeout: 4000, // 超时时间
        reconnectPeriod: 4000, // 重连时间间隔
        // 认证信息
        clientId: 'mqttjs_3be2c321' + new Date().getTime(), // 同一个ID 无法二次连接
        username: 'DT_WEB1',
        password: ''
      }
      const subscription = {
        topic: opname,
        qos: 0
      }
      const { host, port, endpoint, ...options } = connection
      const connectUrl = `ws://${host}:${port}${endpoint}`
      try {
        console.log(mqtt)
        this.mqttClient = mqtt.connect(connectUrl, options)
      } catch (error) {
        console.log('MQTT connect error', error)
      }

      this.mqttClient.on('connect', () => {
        this.$message.success('加载完成，连接MQTT服务器成功！')
        console.log('MQTT Connection succeeded!')
        const { topic, qos } = subscription
        this.mqttClient.subscribe(topic, { qos }, (error, res) => {
          if (error) {
            console.log('Subscribe to topics error', error)
          }
        })
      })
      this.mqttClient.on('error', error => {
        console.log('MQTT Connection failed', error)
        try {
          // scope.$message.error('MQTT服务器连接失败')
          if (scope.IsAllowConnect) {
            // 显示一下
            scope.$message.warning('重新连接MQTT服务器')
            console.log('重新连接MQTT服务器')
            // 重新连接,打开计时器
            setTimeout(function() {
              scope.initMqtt()
            }, 5000)
          }
        } catch (exception) {
          const error = exception.toString()
          scope.$message.error('MQTT服务器出现错误,关闭连接' + error)
        }
      })
      // 接收消息
      this.mqttClient.on('message', (topic, message) => {
        try {
          scope.websocketonmessage({ data: message.toString() })
        } catch (exception) {
          console.log(exception.toString())
        }
      })
      // 模拟接收消息
      // setInterval(() => {
      //   // this.websocketonmessage({ data: 'DT|C_B_DeviceInfo|[{"Name":"CUT","Id":"cfc74901-f68e-45e2-8735-8c07b5fd8a3f","Status":"中断","Program":"D:\\\\USER\\\\18126-P03-P10.MJB","Feed":null,"Speed":null,"Rapid":null,"ProgramStatus":null,"Tool":null,"Axis":[{"AxisName":"X","AxisValue":"0"},{"AxisName":"Y","AxisValue":"0"},{"AxisName":"Z","AxisValue":"60.7"},{"AxisName":"U","AxisValue":"0"},{"AxisName":"V","AxisValue":"0"}],"OtherParameter":[{"ParameterName":"当前钢丝架文件的名称","ParameterValue":"AC BRASS 900 0.250"},{"ParameterName":"当前选择的线径","ParameterValue":"0.25"},{"ParameterName":"电极丝特性","ParameterValue":"-841100"},{"ParameterName":"电极丝速度","ParameterValue":"8.2"},{"ParameterName":"发电机接通时间","ParameterValue":"697"},{"ParameterName":"总执行时间","ParameterValue":"817"},{"ParameterName":"机床接通的总时间","ParameterValue":"30704238"},{"ParameterName":"加工时电极丝速度","ParameterValue":"0"},{"ParameterName":"上喷射压力","ParameterValue":"0.2"},{"ParameterName":"下喷射压力","ParameterValue":"0.1"},{"ParameterName":"过滤器中的压力","ParameterValue":"1.1"}],"Alarm":[{"Alarm":"?????","AlarmTime":"2023-06-08 09:12:39 851"}]}]' })
      //   // this.websocketonmessage({ data: 'DT|C_B_DeviceInfo|[{"Name":"FORM","Id":"cfc74901-f68e-45e2-8735-8c07b5fd8a3f","Status":"ACTIVE","Program":"wdawda46d65a","Feed":"22","Speed":"33","Rapid":"44","ProgramStatus":null,"Tool":null,"Axis":[{"AxisName":"Xact","AxisValue":"10.5231"},{"AxisName":"Yact","AxisValue":"12.1368"},{"AxisName":"Zact","AxisValue":"35.8"},{"AxisName":"Uact","AxisValue":"0"},{"AxisName":"Vact","AxisValue":"0.0008"}],"OtherParameter":[{"ParameterName":"programnumber","ParameterValue":"SHAPE_SKIMMINGUNTILREMNANT2_CUT2"},{"ParameterName":"wirename","ParameterValue":"AC BRASS 900 0.250"},{"ParameterName":"wirediam","ParameterValue":"0.25"},{"ParameterName":"wireleftlength","ParameterValue":"-824956"},{"ParameterName":"wirespeed","ParameterValue":"8"},{"ParameterName":"sequence","ParameterValue":"GEO 8"},{"ParameterName":"sequencepass","ParameterValue":"3"},{"ParameterName":"genontime","ParameterValue":"4095"},{"ParameterName":"executiontime","ParameterValue":"4313"},{"ParameterName":"machinecounter","ParameterValue":"30503331"},{"ParameterName":"machineerosioncounter","ParameterValue":"12426498"},{"ParameterName":"machiningspeedmax","ParameterValue":"2.99"},{"ParameterName":"machiningspeedmin","ParameterValue":"2.32"},{"ParameterName":"machiningspeed","ParameterValue":"2.62"},{"ParameterName":"deio","ParameterValue":"9.7"},{"ParameterName":"temperature","ParameterValue":"21.9"},{"ParameterName":"pressureupper","ParameterValue":"0.3"},{"ParameterName":"pressurelower","ParameterValue":"0.1"},{"ParameterName":"pressurefilter","ParameterValue":"1.3"},{"ParameterName":"cuttinglength","ParameterValue":"24.2675"},{"ParameterName":"meanmachvoltage","ParameterValue":"30.0"},{"ParameterName":"wiretension","ParameterValue":"4.9"},{"ParameterName":"good","ParameterValue":"0.831"},{"ParameterName":"shortcircuit","ParameterValue":"0.150"},{"ParameterName":"arckill","ParameterValue":"0.019"},{"ParameterName":"cold","ParameterValue":"0.000"},{"ParameterName":"frequency","ParameterValue":"34990"},{"ParameterName":"timeTD","ParameterValue":"0.014"},{"ParameterName":"shc_warningnumber","ParameterValue":"56"},{"ParameterName":"shc_warningtime","ParameterValue":"45592"},{"ParameterName":"shc_longnumber","ParameterValue":"52"},{"ParameterName":"shc_longtime","ParameterValue":"45316"},{"ParameterName":"shc_time","ParameterValue":"45528"}]}]' })
      //   // this.websocketonmessage({ data: 'DT|C_B_DeviceInfo|[{"Name":"98","Id":"cfc74901-f68e-45e2-8735-8c07b5fd8a3f","Status":"ACTIVE","Program":null,"Feed":"22","Speed":"33","Rapid":"44","ProgramStatus":null,"Tool":null,"Axis":[{"AxisName":"Xact","AxisValue":"10.5231"},{"AxisName":"Yact","AxisValue":"12.1368"},{"AxisName":"Zact","AxisValue":"35.8"},{"AxisName":"Uact","AxisValue":"0"},{"AxisName":"Vact","AxisValue":"0.0008"}],"OtherParameter":[{"ParameterName":"programnumber","ParameterValue":"SHAPE_SKIMMINGUNTILREMNANT2_CUT2"},{"ParameterName":"wirename","ParameterValue":"AC BRASS 900 0.250"},{"ParameterName":"wirediam","ParameterValue":"0.25"},{"ParameterName":"wireleftlength","ParameterValue":"-824956"},{"ParameterName":"wirespeed","ParameterValue":"8"},{"ParameterName":"sequence","ParameterValue":"GEO 8"},{"ParameterName":"sequencepass","ParameterValue":"3"},{"ParameterName":"genontime","ParameterValue":"4095"},{"ParameterName":"executiontime","ParameterValue":"4313"},{"ParameterName":"machinecounter","ParameterValue":"30503331"},{"ParameterName":"machineerosioncounter","ParameterValue":"12426498"},{"ParameterName":"machiningspeedmax","ParameterValue":"2.99"},{"ParameterName":"machiningspeedmin","ParameterValue":"2.32"},{"ParameterName":"machiningspeed","ParameterValue":"2.62"},{"ParameterName":"deio","ParameterValue":"9.7"},{"ParameterName":"temperature","ParameterValue":"21.9"},{"ParameterName":"pressureupper","ParameterValue":"0.3"},{"ParameterName":"pressurelower","ParameterValue":"0.1"},{"ParameterName":"pressurefilter","ParameterValue":"1.3"},{"ParameterName":"cuttinglength","ParameterValue":"24.2675"},{"ParameterName":"meanmachvoltage","ParameterValue":"30.0"},{"ParameterName":"wiretension","ParameterValue":"4.9"},{"ParameterName":"good","ParameterValue":"0.831"},{"ParameterName":"shortcircuit","ParameterValue":"0.150"},{"ParameterName":"arckill","ParameterValue":"0.019"},{"ParameterName":"cold","ParameterValue":"0.000"},{"ParameterName":"frequency","ParameterValue":"34990"},{"ParameterName":"timeTD","ParameterValue":"0.014"},{"ParameterName":"shc_warningnumber","ParameterValue":"56"},{"ParameterName":"shc_warningtime","ParameterValue":"45592"},{"ParameterName":"shc_longnumber","ParameterValue":"52"},{"ParameterName":"shc_longtime","ParameterValue":"45316"},{"ParameterName":"shc_time","ParameterValue":"45528"}]}]' })
      //   this.websocketonmessage({ data: 'DT|C_B_DeviceInfo|[{"Name":"ST10","Id":"72e95caa-d510-4090-9dfa-9c55b8220999","Status":[{"StatusName":"自动运行","StatusValue":"0"},{"StatusName":"自动运行","StatusValue":"0"},{"StatusName":"自动运行","StatusValue":"0"},{"StatusName":"自动运行","StatusValue":"0"}],"Program":"TNC:\\\\CNC\\\\_model1-2.H","Feed":"18","Speed":"120","Rapid":"18","ProgramStatus":"闲置","Tool":null,"Axis":[{"AxisName":"X","AxisValue":"-279.766"},{"AxisName":"Y","AxisValue":"224.906"},{"AxisName":"Z","AxisValue":"231.568"},{"AxisName":"C","AxisValue":"333.580"},{"AxisName":"B","AxisValue":"0.000"}],"OtherParameter":[{"ParameterName":"NC启动时间","ParameterValue":"4192:47"},{"ParameterName":"MACHINE启动时间","ParameterValue":"3015:41"},{"ParameterName":"MACHINE运行时间","ParameterValue":"428:58"},{"ParameterName":"SPINDLE运行时间","ParameterValue":"0:00"}],"Alarm":null}]' })
      //   // this.websocketonmessage({ data: 'DT|C_B_DeviceInfo|[{"Name":"FANUC","Id":"cfc74901-f68e-45e2-8735-8c07b5fd8a3f","Status":"ACTIVE","Program":null,"Feed":"22","Speed":"33","Rapid":"44","ProgramStatus":null,"Tool":null,"Axis":[{"AxisName":"Xact","AxisValue":"10.5231"},{"AxisName":"Yact","AxisValue":"12.1368"},{"AxisName":"Zact","AxisValue":"35.8"},{"AxisName":"Uact","AxisValue":"0"},{"AxisName":"Vact","AxisValue":"0.0008"}],"OtherParameter":[{"ParameterName":"programnumber","ParameterValue":"SHAPE_SKIMMINGUNTILREMNANT2_CUT2"},{"ParameterName":"wirename","ParameterValue":"AC BRASS 900 0.250"},{"ParameterName":"wirediam","ParameterValue":"0.25"},{"ParameterName":"wireleftlength","ParameterValue":"-824956"},{"ParameterName":"wirespeed","ParameterValue":"8"},{"ParameterName":"sequence","ParameterValue":"GEO 8"},{"ParameterName":"sequencepass","ParameterValue":"3"},{"ParameterName":"genontime","ParameterValue":"4095"},{"ParameterName":"executiontime","ParameterValue":"4313"},{"ParameterName":"machinecounter","ParameterValue":"30503331"},{"ParameterName":"machineerosioncounter","ParameterValue":"12426498"},{"ParameterName":"machiningspeedmax","ParameterValue":"2.99"},{"ParameterName":"machiningspeedmin","ParameterValue":"2.32"},{"ParameterName":"machiningspeed","ParameterValue":"2.62"},{"ParameterName":"deio","ParameterValue":"9.7"},{"ParameterName":"temperature","ParameterValue":"21.9"},{"ParameterName":"pressureupper","ParameterValue":"0.3"},{"ParameterName":"pressurelower","ParameterValue":"0.1"},{"ParameterName":"pressurefilter","ParameterValue":"1.3"},{"ParameterName":"cuttinglength","ParameterValue":"24.2675"},{"ParameterName":"meanmachvoltage","ParameterValue":"30.0"},{"ParameterName":"wiretension","ParameterValue":"4.9"},{"ParameterName":"good","ParameterValue":"0.831"},{"ParameterName":"shortcircuit","ParameterValue":"0.150"},{"ParameterName":"arckill","ParameterValue":"0.019"},{"ParameterName":"cold","ParameterValue":"0.000"},{"ParameterName":"frequency","ParameterValue":"34990"},{"ParameterName":"timeTD","ParameterValue":"0.014"},{"ParameterName":"shc_warningnumber","ParameterValue":"56"},{"ParameterName":"shc_warningtime","ParameterValue":"45592"},{"ParameterName":"shc_longnumber","ParameterValue":"52"},{"ParameterName":"shc_longtime","ParameterValue":"45316"},{"ParameterName":"shc_time","ParameterValue":"45528"}]}]' })
      //   console.log('mqtt发送了一条数据')
      // }, 5000)
    },
    websocketonmessage(msg) { // 数据接收
      console.log("接收到了一条数据",msg)
      this.msg = msg
      // 返回的数据msg.data，包含了协议中的4部分9
      // TOBS??SCADADetailed?MES|Current|opName|电流^电压
      var arrays_signal = msg.data.split('|')
      var interFaceType = arrays_signal[0]
      var dataType = arrays_signal[1]
      var m_data = arrays_signal[2]
      switch (interFaceType) {
        case 'DT':
          switch (dataType) {
            case 'C_B_DeviceInfo': {
              {
                // console.log('S_data0', m_data)
                const S_data = JSON.parse(m_data)[0]
                // console.log('S_data', S_data)
                for (let i = 0; i < this.deviceList.length; i++) {
                  let item = this.deviceList[i]
                  // console.log('item.name', item.Name, 'S_data.Name', S_data.Name)
                  if (S_data.Name === item.Name) {
                    // console.log('有匹配上的数据')

                    // 2.对对象进行拷贝覆盖
                    item = { ...item, ...S_data }
                    if (item.hasOwnProperty('Alarm')) {
                      if (item.Alarm === null) item.Alarm = []
                      // 遍历报警信息 去除所有问号
                      if (item.Alarm !== null) {
                        if (item.Alarm.length > 0) {
                          for (const item of item.Alarm) {
                            item.Alarm = item.Alarm.replaceAll('?', '')
                            item.Alarm = item.Alarm.replaceAll('？', '')
                          }
                        }
                      }
                    }
                    if (item.hasOwnProperty('Status')) {
                      if (item.Status === null) item.Status = []
                    }
                    if (item.hasOwnProperty('Axis')) {
                      if (item.Axis === null) item.Axis = []
                    }
                    if (item.hasOwnProperty('OtherParameter')) {
                      if (item.OtherParameter === null) item.OtherParameter = []
                    }
                    if (item.hasOwnProperty('Program')) {
                      // 将设备程序只使用最后一个文件名 \ 分割
                      if (item.Program !== null) {
                        item.Program = item.Program.split('\\')[item.Program.split('\\').length - 1]
                      } else {
                        item.Program = ''
                      }
                    }
                    if (item.hasOwnProperty('Tool')) {
                      if (item.Tool === null) item.Tool = {}
                    }

                    // 4.重新赋值给原对象
                    this.deviceList[i] = item
                    // console.log('覆盖后的对象', this.deviceList[i])
                    // console.log('此时数组对象', this.deviceList)
                    break
                  }
                }
              }
              break
            }
            case 'C_B_TagIDTrigger':
            {
              const tag = JSON.parse(m_data)
              switch (tag.TagID){
                case 'CB614A60-D0D2-4D76-96AA-FF433CAC0076':{
                  // 红
                  this.lightForm.red = tag.TagValue
                  break
                }
                case 'CB614A60-D0D2-4D76-96AA-FF433CAC0077':{
                  // 黄
                  this.lightForm.yellow = tag.TagValue
                  break
                }
                case 'CB614A60-D0D2-4D76-96AA-FF433CAC0078':{
                  this.lightForm.green = tag.TagValue
                  // 绿
                  break
                }
              }
            }
              break
          }
          break
      }
    },
    getRightMiddlePieData () {
      let data = this.CreateData1('11', '设备管理_设备报警_查询')
      this.ExecDatabase(data).then((res) => {
        if(res.data.length <= 0) { return }
        this.rightMiddlePieData = []
        for (let i = 0; i < res.data.length; i++) {
          let ele = res.data[i]
          this.rightMiddlePieData.push({ value: ele.value, name: ele.name, itemStyle: { color: this.rightMiddlePieColorList[i] }})
        }
        console.log(this.rightMiddlePieData)
      }).then(() => {
        this.rightMiddlePieOptionSet()
      })
    },
    getLeftMiddlePieData () {
      let data = this.CreateData1('11', '产量管理_稼动率查询')
      this.ExecDatabase(data).then((res) => {
        if(res.data.length <= 0) { return }
        this.leftMiddlePieData = 0
        this.leftMiddlePiePlanData = 0
        this.leftMiddlePiePlanText = ''
        this.leftMiddlePieData = res.data[0].稼动率
        this.leftMiddlePiePlanData = res.data[0].目标稼动率
        let difference = Number(this.leftMiddlePieData) - Number(this.leftMiddlePiePlanData)
        if(difference > 0){
          this.leftMiddlePiePlanText = '比目标值高 ' +  Math.abs(difference) + '%'
        }else {
          this.leftMiddlePiePlanText = '比目标值低 ' +  Math.abs(difference) + '%'
        }
      }).then(() => {
        this.leftMiddlePieOptionSet()
      })
    },
    getRightTopColumnarData () {
      let data = this.CreateData1('11', '产量管理_JPH_查询')
      this.ExecDatabase(data).then((res) => {
        if(res.data.length <= 0) { return }
        this.rightTopColumnarX = []
        this.rightTopColumnarXData = []
        for (let i = 0; i < res.data.length; i++) {
          let ele = res.data[i]
          this.rightTopColumnarX.push(ele.HH)
          this.rightTopColumnarXData.push(Number(ele.DataCountOK) + Number(ele.DataCountNG))
        }
      }).then(() => {
        this.rightTopColumnarOptionSet()
      })
    },
    getLeftTopColumnarData () {
      let data = this.CreateData1('11', '产量管理_7日产出曲线')
      this.ExecDatabase(data).then((res) => {
        if(res.data.length <= 0) { return }
        this.rightBottomPieData = []
        this.leftTopColumnarX = []
        this.leftTopColumnarY = []
        for (let i = 0; i < res.data.length; i++) {
          let ele = res.data[i]
          this.leftTopColumnarX.push(ele.date.slice(-5))
          this.leftTopColumnarXData.push(ele.num1)
        }
      }).then(() => {
        this.leftTopColumnarOptionSet()
      })
    },
    // 查询设备运行履历
    searchChartData44() {
      this.deviceStatus_table = []
      var param = []
      let data = this.CreateData1('11', '设备管理_设备每分钟状态_查询', param)
      this.ExecDatabase(data).then((response) => {
        this.deviceStatus_table = response.data
      }).then(() => {
        this.drawDashboard44()
      })
    },
    // 设备运行履历
    drawDashboard44() {
      let scope = this
      const deviceStatus_data = []
      const deviceStatus_yAxisValue = []
      let deviceStatus_index = 0
      if (this.deviceStatus_table.length === 1) {
        deviceStatus_data.push({
          itemStyle: { normal: { color: this.deviceStatus_table[0].颜色 }}, // 条形颜色
          name: this.deviceStatus_table[0].设备状态名称,
          value: [0, this.deviceStatus_table[0].开始时间, this.deviceStatus_table[0].结束时间]
        })
      } else {
        for (let i = 0; i < this.deviceStatus_table.length; i++) {
          if (i < this.deviceStatus_table.length) {
            if (i === 0) {
              deviceStatus_index = 0
              deviceStatus_yAxisValue.push(this.deviceStatus_table[i].工位号)
            } else if (this.deviceStatus_table[i].工位号 !== this.deviceStatus_table[i - 1].工位号) {
              deviceStatus_index++ // y轴索引
              deviceStatus_yAxisValue.push(this.deviceStatus_table[i].工位号)
            }
          }
          deviceStatus_data.push({
            itemStyle: { normal: { color: this.deviceStatus_table[i].颜色 }}, // 条形颜色
            name: this.deviceStatus_table[i].设备状态名称,
            value: [parseInt(deviceStatus_index), this.deviceStatus_table[i].开始时间, this.deviceStatus_table[i].结束时间]
          })
        }
      }
      // const myChart = echarts.init(document.getElementById('myChart4'))
      this.middleButton.clear()
      this.middleButtonOption = {
        // title: {
        //   left: 'center',
        //   text: '设备状态分布图(分钟)',
        //   textStyle: {
        //     color: '#ffffff'
        //   }
        // },
        color: this.deviceStatus_colors,
        tooltip: { // 提示框
          formatter(params) {
            return params.value[1].substr(11, 5) + '~' + params.value[2].substr(11, 5)
          } // 数据的值
        },
        grid: { // 绘图网格
          left: '10px',
          right: '4%',
          top: '10%',
          bottom: '2%',
          containLabel: true
        },
        legend: { // 图例
          data: ['关机', '待机', '运行', '暂停', '报警'],
          selectedMode: false,
          textStyle: {
            color: '#ffffff'
          }
        },
        xAxis: {
          type: 'time',
          axisLine: {
            lineStyle: {
              color: '#ffffff'
            },
            show: true
          },
          axisTick: {
            show: true
          },
          interval: 1000 * 60 * 60 * 2,
          axisLabel: {
            formatter(value) {
              var date = new Date(value)
              return getzf(date.getHours()) + ':' + getzf(date.getMinutes())
              function getzf(num) {
                if (parseInt(num) < 10) {
                  num = '0' + num
                }
                return num
              }
            }
          }
        },
        yAxis: {
          axisLine: {
            lineStyle: {
              color: '#ffffff'
            }
          },
          data: deviceStatus_yAxisValue
        },
        series: [
          // 用空bar来显示几个图例
          { name: this.deviceStatus_state[0], type: 'bar', data: [] },
          { name: this.deviceStatus_state[1], type: 'bar', data: [] },
          { name: this.deviceStatus_state[2], type: 'bar', data: [] },
          { name: this.deviceStatus_state[3], type: 'bar', data: [] },
          { name: this.deviceStatus_state[4], type: 'bar', data: [] },
          {
            type: 'custom',
            renderItem(params, api) { // 开发者自定义的图形元素渲染逻辑，是通过书写 renderItem 函数实现的
              var categoryIndex = api.value(0) // 这里使用 api.value(0) 取出当前 dataItem 中第一个维度的数值。
              var start = api.coord([api.value(1), categoryIndex]) // 这里使用 api.coord(...) 将数值在当前坐标系中转换成为屏幕上的点的像素值。
              var end = api.coord([api.value(2), categoryIndex])
              var height = 18 // 柱体宽度
              return {
                type: 'rect', // 表示这个图形元素是矩形。还可以是 'circle', 'sector', 'polygon' 等等。
                shape: echarts.graphic.clipRectByRect({ // 矩形的位置和大小。
                  x: start[0],
                  y: start[1] - height,
                  width: end[0] - start[0],
                  height: height * 1.2
                }, { // 当前坐标系的包围盒。
                  x: params.coordSys.x,
                  y: params.coordSys.y,
                  width: params.coordSys.width,
                  height: params.coordSys.height
                }),
                style: api.style()
              }
            },
            encode: {
              x: [1, 2], // data 中『维度1』和『维度2』对应到 X 轴
              y: 0 // data 中『维度0』对应到 Y 轴
            },
            data: deviceStatus_data
          }
        ]
      }
      this.middleButton.setOption(this.middleButtonOption)
    },
    middleButtonOptionSet () {
      this.middleButtonOption = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        legend: {
          right: 10, // 将图例放置在右侧
          icon: 'circle', // 设置图例的标识样式为实心圆点
          itemWidth: 10, // 设置图例标记的宽度
          itemHeight: 10, // 设置图例标记的高度
          textStyle: {
            color: '#a2a7b3',
            fontSize: 12
          }
        },
        grid: {
          left: '2%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'value',
          boundaryGap: [0, 0.01],
          axisLine: {
            show: true
          },
          axisLabel: {
            show: true,
            color: '#747c8c',
            formatter: function(value) {
              const hours = Math.floor(value / 60);
              const mins = value % 60;
              return `${String(hours).padStart(2, '0')}:${String(mins).padStart(2, '0')}`;
            },
            interval: 0,
          },
          max: 1440,
          splitLine: {
            show: false
          }
        },
        yAxis: {
          type: 'category',
          data: ['ST10工站', 'ST20工站', 'ST30工站', 'ST40工站'],
          axisLine: {
            show: true
          },
          axisLabel: {
            show: true,
            color: '#747c8c'
          }
        },
        series:[
          {
            data: [300, 300, 300, 300],
            type: 'bar',
            stack: 'a',
            name: '正常待机',
            color:'#eff2f8',
            itemStyle: {
              borderRadius: 15,
            },
            barMaxWidth: 15
          },
          {
            data: [240,200,200,200],
            type: 'bar',
            stack: 'a',
            name: '初始化',
            color:'#409eff',
            itemStyle: {
              borderRadius: 15,
            },
          },
          {
            data: [200,100,300,200],
            type: 'bar',
            stack: 'a',
            name: '自动运行',
            color:'#67c23a',
            itemStyle: {
              borderRadius: 15,
            },
          },
          {
            data: [200,200,200,200],
            type: 'bar',
            stack: 'a',
            name: '报警暂停',
            color:'#f56c6c',
            itemStyle: {
              borderRadius: 15,
            },
          },
          {
            data: [60,200,100,100],
            type: 'bar',
            stack: 'a',
            name: '服务暂停',
            color:'#fff476',
            itemStyle: {
              borderRadius: 15,
            },
          },
          {
            data: [440,440,340,440],
            type: 'bar',
            stack: 'a',
            name: '正常待机',
            color:'#eff2f8',
            itemStyle: {
              borderRadius: 15,
            },
          }
        ]
      }
      this.middleButton.setOption(this.middleButtonOption)
    },
    rightMiddlePieOptionSet () {
      this.rightMiddlePieOption = {
        tooltip: {
          trigger: 'item'
        },
        legend: {
          top: '0%',
          orient: 'vertical',
          right: 40, // 将图例放置在右侧
          icon: 'circle', // 设置图例的标识样式为实心圆点
          itemGap: 10,
          itemWidth: 14, // 设置图例标记的宽度
          itemHeight: 14, // 设置图例标记的高度
          textStyle: {
            fontSize: 14,
            color: function (params) {
              // 获取对应的系列项
              var series = option.series[0].data
              for (var i = 0; i < series.length; i++) {
                if (series[i].name === params) {
                  // 返回对应系列项的颜色
                  return series[i].itemStyle.color
                }
              }
              return '#000' // 默认颜色，如果没有匹配到
            }
          }
        },
        series: [
          {
            name: 'Access From',
            type: 'pie',
            radius: ['50%', '90%'],
            center: ['45%', '50%'],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: 'rgba(9, 26, 54,1)',
              borderWidth: 5
            },
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 40,
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data:this.rightMiddlePieData// [
              //{ value: 10, name: 'ST10工站', itemStyle: { color: '#e2ae03' }},
              //{ value: 30, name: 'ST20工站', itemStyle: { color: '#aa493c' }},
             // { value: 50, name: 'ST30工站', itemStyle: { color: '#459763' }},
              //{ value: 5, name: 'ST40工站', itemStyle: { color: '#49a9ee' }}
            //]
          }
        ]
      }
      this.rightMiddlePie.setOption(this.rightMiddlePieOption)
    },
    rightTopColumnarOptionSet () {
      this.rightTopColumnarOption = {
        grid: {
          left: '1%',
          right: '6%',
          bottom: '10%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          data: this.rightTopColumnarX, //['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
          axisLabel: {
            interval: 0, // 显示所有标签
            fontSize: 10, // 设置x轴文字的大小
            color: '#626c7f'
          }
        },
        yAxis: {
          type: 'value',
          axisLine: {
            show: true
          },
          splitLine: {
            show: false
          },
        },
        series: [
          {
            data: this.rightTopColumnarXData, //[120, 200, 150, 80, 70, 110, 130, 130, 98, 115, 98, 115],
            color:'#49a9ee',
            type: 'bar',
            barMaxWidth: 15
          }
        ]
      }
      this.rightTopColumnar.setOption(this.rightTopColumnarOption)
    },
    leftMiddlePieOptionSet () {
      let value = this.leftMiddlePieData
      // 进度百分比
      this.leftMiddlePieOption = {
        title: [{
          text: value + '%',
          left: 'center',
          top: '40%',
          textStyle: {
            color: '#757575',
            fontSize: 35,
            fontWeight: 'bold',
          }
        }, {
          text: this.leftMiddlePiePlanText,
          left: 'center',
          top: '92%',
          textStyle: {
            color: '#7b7e87',
            fontSize: 12
          }
        }],
        angleAxis: {
          show: false,
          // 后面的180表示圆环的跨越的角度， 如max设置为100*360/270,startAngle设置为-135
          max: 100 * 360 / 270,
          type: 'value',
          startAngle: -135,
          splitLine: {
            show: false
          }
        },
        // 修改环形的宽度
        barMaxWidth: 20,
        radiusAxis: {
          show: false,
          type: 'category'
        },
        polar: {
          // 设置环形的位置
          center: ['50%', '50%'],
          // 设置环形大小
          radius: '180%'
        },
        series:[{
          type: 'bar',
          data: [
            {
              value: value,
              itemStyle: {
                // 这里是已经达到进度的颜色
                color: '#48a9ee',
              }
            }
          ],
          itemStyle: {
            normal: {
              color: 'white' // 设置环形图中心的颜色为白色
            }
          },
          barGap: '-100%',
          coordinateSystem: 'polar',
          z: 3
        }, {
          type: 'bar',
          data: [{
            value: 100,
            itemStyle: {
              // 这里是环形底色
              color: '#f4f4f4',
              borderWidth: 0,

            }
          }],
          barGap: '-100%',
          coordinateSystem: 'polar',
          z: 1
        }]
      }
      this.leftMiddlePie.setOption(this.leftMiddlePieOption)
    },
    leftTopColumnarOptionSet () {
      this.leftTopColumnarOption = {
        grid: {
          left: '1%',
          right: '6%',
          bottom: '10%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          data: this.leftTopColumnarX, //['08-01', '08-02', '08-03', '08-04', '08-05', '08-06', '08-07', '08-08', '08-09', '08-10'],
          axisLabel: {
            interval: 0, // 显示所有标签
            fontSize: 10, // 设置x轴文字的大小
            color: '#626c7f'
          }
        },
        yAxis: {
          type: 'value',
          axisLine: {
            show: true
          },
          splitLine: {
            show: false
          },
        },
        series: [
          {
            data: this.leftTopColumnarXData, //[120, 200, 150, 80, 70, 110, 130, 130, 98, 115],
            color:'#ffd86e',
            type: 'bar',
            barMaxWidth: 15
          }
        ]
      }
      this.leftTopColumnar.setOption(this.leftTopColumnarOption)
    },
    num (num) {
      return (num + '').indexOf('.') == -1 ? num : num.toFixed(1)
      // return num
    },
    getmidddlelist () {
      let data = this.CreateData1(
        '11',
        '中间实时OEE数据展示_查询'
      )
      this.ExecDatabase(data).then((res) => {
        // res.data.forEach((ele) => {
        //   ele.OEE = this.num(ele.OEE)
        //   ele.合格率 = this.num(ele.合格率)
        //   ele.性能利用率 = this.num(ele.性能利用率)
        //   ele.时间利用率 = this.num(ele.时间利用率)
        // })
        this.lineInfo = res.data
      })
    },
    clareData () {
      this.contractMainDataInfoDetail = []
      this.mainShowIndex = 'jd'
    },
    // 查询中间订单 工时 能源 出勤等信息
    getPlanCountInfo () {
      const params = []
      var data = this.CreateData1(
        11,
        'visualization_中间产线实时信息_查询',
        params
      )
      this.ExecDatabase(data).then((res) => {
        this.planCountInfo = []
        if (res.data.length > 0) {
          this.planCountInfo[0] = res.data[0]['当前计划']
          this.planCountInfo[1] = res.data[0]['当前产量']
          this.planCountInfo[2] = res.data[0]['计划完成']
          this.planCountInfo[3] = res.data[0]['工时消耗']
          this.planCountInfo[4] = res.data[0]['能源消耗']
          this.planCountInfo[5] = res.data[0]['生产出勤']
        }
      })
    },
    zeroFill (i) {
      if (i >= 0 && i <= 9) {
        return '0' + i
      } else {
        return i
      }
    },
    getNowTime () {
      const date = new Date()
      const month = this.zeroFill(date.getMonth() + 1)
      const day = this.zeroFill(date.getDate())
      const hour = this.zeroFill(date.getHours())
      const minute = this.zeroFill(date.getMinutes())
      const second = this.zeroFill(date.getSeconds())
      return (
        date.getFullYear() +
        '-' +
        month +
        '-' +
        day +
        ' ' +
        hour +
        ':' +
        minute +
        ':' +
        second
      )
    }
  },
  computed: {},
  watch: {},
  props: {},
  directives: {
    scroll: {
      bind (
        el,
        {
          value: { delay, speed } = {
            delay: 0,
            speed: 50
          }
        }
      ) {
        //  delay 延迟  //speed滚动速度
        // 数据少不滚动
        // 无缝滚动
        let scrollInterval
        setTimeout(() => {
          scrollInterval = setInterval(goScroll, speed)
        }, delay)
        el.addEventListener('mouseenter', () => {
          clearInterval(scrollInterval)
        })
        el.addEventListener('mouseleave', () => {
          scrollInterval = setInterval(goScroll, speed)
        })

        function goScroll () {
          let scrollTotalHeight = JSON.parse(JSON.stringify(el.scrollTop))
          el.scrollTop++
          if (scrollTotalHeight === el.scrollTop) {
            el.scrollTop = 0
          }
        }
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.container {
  width: 100%;
  height: 100%;
  overflow-y: hidden;
  z-index: 100;
  transform-origin: 0 0;
  position: fixed;
  left: 50%;
  top: 50%;
  background-color: #000d3a;
  color: white;

  .content {
    width: 100%;
    height: 100%;
    display: flex;
    overflow: hidden;

    .c-left {
      width: 25%;
      height: 100%;
      background-color: #000d3a;
      border-right: 1px solid #3d4a61;

      .left-header {
        margin-top: 2%;
        background-color: #000d3a;
        height: 11%;
        display: flex;
        align-items: center;

        img {
          margin: 10px;
          height: 120px;
          width: 500px;
        }

        span {
          font-size: 3.5rem;
          margin-left: 1rem;
        }
      }

      .left-content {
        height: 90%;

        .main {
          height: 35%;
        }

        .main2 {
          height: 25%;
        }

        .main3 {
          height: 35%;
        }

        .box {
          display: flex;
          justify-content: space-between;
          height: 90%;
          width: 100%;
        }

        .left {
          width: 50%;
          height: 100%;
        }

        .right {
          width: 44.5%;
          height: 100%;
        }

        .box2 {
          display: flex;
          justify-content: space-between;
          height: 53%;
        }

        .left1 {
          width: 45%;
        }

        .right1 {
          width: 100%;
        }

        .row-item {
          height: 20px !important;
          line-height: 20px !important;
          font-size: 12px;
        }

        .header-item {
          height: 24px;
          line-height: 24px;
        }

        .dv-scroll-board .header {
          font-size: 12px;
        }

        .hezi1 {
          position: absolute;
          top: 10%;
          left: 23%;
        }

        .n1 {
          color: #fff;
        }

        .n2 {
          color: #fff;
          font-size: 12px;
        }

        .n3 {
          color: #fff;
          font-size: 12px;
        }

        .n4 {
          color: #fff;
          font-size: 12px;
        }

        .n5 {
          color: #fff;
          font-size: 12px;
        }
      }
    }

    .c-center {
      width: 50%;
      background-color: #000d3a;
      box-sizing: border-box;

      .center-header {
        background-color: #000d3a;
        height: 10.7%;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 50px;
        font-weight: bold;
        letter-spacing:5px;
      }

      .center-content {
        height: calc(100% - 8rem);
        padding: 1rem;
        box-sizing: border-box;

        .items {
          height: 100%;
          padding: 1rem;
          box-sizing: border-box;

          .item-head {
            height: 10rem;
            display: grid;
            grid-template-columns: repeat(3, 33.3%);
            grid-template-rows: repeat(2, 50%);
            justify-items: center;
            align-content: center;
            box-sizing: border-box;
            padding-bottom: 1rem;

            background: linear-gradient(90deg, #043079 50%, transparent 0)
                repeat-x,
              linear-gradient(90deg, #043079 50%, transparent 0) repeat-x,
              linear-gradient(0deg, #043079 50%, transparent 0) repeat-y,
              linear-gradient(0deg, #043079 50%, transparent 0) repeat-y;
            background-size: 0px 10px, 20px 10px, 10px 0px, 10px 0px;
            background-position: 0 0, 0 100%, 0 0, 100% 0;

            animation: linearGradientMove 0.3s infinite linear;
          }

          @keyframes linearGradientMove {
            100% {
              background-position: -20px 0, 20px 100%, 0 20px, 100% -20px;
            }
          }

          .item-content {
            box-sizing: border-box;
            margin-top: 50px;
            box-sizing: border-box;

            .bg {
              width: 100%;
              height: 100%;
              background-size: 100% 100%;
            }

            .btns {
              position: absolute;
              margin-left: 1rem;
              z-index: 999;

              div {
                border: 2px solid #244d71;
                background-color: #000d3a;
                color: #ffffff;
                padding: 0.5rem 2rem;
                margin: 0.5rem 0;
                font-size: 1.2rem;
              }
            }

            .center-tab {
              position: absolute;
              margin-left: calc(50% - 22.5rem);
              margin-top: 0rem;
              width: 45rem;
              height: 10rem;

              box-sizing: border-box;
              box-shadow: inset 0 0 3rem rgb(24, 78, 135);
            }

            .middle-bottom{
              position: absolute;
              width: 98%;
              margin-left: 1%;
              margin-top: -2rem;
              height: 350px;
              box-sizing: border-box;
              padding-top: 10px;
              padding-left: 10px;

              .diyTab{
                td{
                  font-size: 1.3rem;
                }
              }

              .roll-box div{
                font-size: 13px;
              }
              .roll-table-box div{
                font-size: 14px;
              }
            }
          }

          .item-head > div {
            display: flex;
            align-items: center;
            width: 15rem;

            img {
              height: 4.5rem;
              width: 4.5rem;
              object-fit: cover;
            }

            .data {
              display: flex;
              flex-direction: column;

              .data-value {
                font-size: 1.5rem;
                font-weight: bold;
              }
            }
          }
        }
      }
    }

    .c-right {
      width: 25%;
      background-color: #000d3a;

      border-left: 1px solid #3d4a61;

      .right-header {
        background-color: #000d3a;
        height: 13.2rem;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 4rem;
      }

      .right-content {
        height: calc(100% - 8rem);
      }
    }

    .items {
      height: 30%;
      width: 100%;
      box-sizing: border-box;
      /*右下*/
      box-shadow: inset 0 0 3rem rgb(24, 78 ,135);

      .title {
        height: 15%;
        display: flex;
        align-items: center;
        padding-left: 10%;
        box-sizing: border-box;

        .sign {
          height: 60%;
          width: 1rem;
          background-color: #016eea;
        }

        .text {
          color: white;
          font-size: 1.7rem;
          box-sizing: border-box;
          margin-left: 1.2rem;
        }
      }
    }

    .items > div:last-child {
      height: 85%;
      width: 100%;
    }
  }
}
.right {
  width: 100%;
  height: 100%;
  background-color: #000d3a;
  padding-left: 1.5%;
  box-sizing: border-box;
  .right-head {
    height: 12%;
    display: flex;
    justify-content: flex-end;
    span {
      margin: 25px;
      margin-top: 40px;
      font-weight: 700;
      font-size: 35px;
      color: #fff;
    }
  }

  .main {
    height: 90%;
    .top {
      width: 100%;
      height: 35%;

      .cook-list {
        width: 100%;
        height: 80%;
        display: flex;
        flex-wrap: wrap;
      }
    }

    .center {
      width: 100%;
      height: 25%;

      .center-main {
        width: 100%;
        height: 90%;
        .center-left {
          height: 100%;
          .left-top {
            height: 50%;
            display: flex;

            div {
              width: 33.33%;
              height: 100%;
            }
          }
          .left-bottom {
            height: 50%;
          }
        }

        .center-right {
          width: 40%;
          height: 100%;
          > span {
            color: #fff;
          }

          ::v-deep .row-item {
            .ceil {
              padding: 0;
            }
          }
        }
      }
    }

    .bottom {
      width: 100%;
      height: 35%;
      .bottom-top {
        display: flex;
        width: 100%;
        height: 45%;
        .andong-left {
          width: 60%;
          height: 100%;
          > span {
            color: #fff;
          }

          .analyse {
            width: 100%;
            height: 90%;
          }
        }

        .andong-right {
          width: 40%;
          height: 100%;
          > span {
            color: #fff;
          }

          .call {
            width: 100%;
            height: 90%;
          }
        }
      }
      .bottom-bottom {
        width: 100%;
        height: 44.5%;

        ::v-deep .header-item {
          font-size: 6px;
          padding: 0;
        }
        ::v-deep .row-item {
          font-size: 4px;
          padding: 0;
          .ceil {
            padding: 0;
          }
        }
      }
    }
  }
}

.roll-table{
  margin-left: 5px;
  border: 1px solid #22405c;
  width: 99%;
}
.roll-table-box,.roll-box {
  display: flex;
  justify-content: space-around;
}
.roll-table-box div,
.roll-box div {
  flex: 1;
  text-align: center;
  height: 28px;
  line-height: 28px;
  font-size: 10px;
  overflow: hidden;
}

.roll-table-box div {
  overflow: auto;
  word-wrap: break-word; /* 允许在长单词内部换行 */
  word-break: break-all; /* 允许在任意位置换行 */
  white-space: normal; /* 处理空白符，自动换行 */
  height: 30px;
  line-height: 30px;
  font-size: 11px;
  font-weight: 700;
}

.roll-box {
  display: flex;
}

.table-title{
  width: 100%;
  text-align: center;
  color: #016f74;
  font-size: 20px;
  font-weight: bold;
}
.robot-table{
  width: 100%;
  text-align: center;
  border-collapse: collapse;
  font-size: 15px;
  margin: 10px 0;
  tr{
    border: 3px solid #132d4e;
    height: 40px;
  }
  td{
    .status{
      display: inline-block;
      width: 20px;
      height: 20px;
      border-radius: 10px;
      background-color: #98d87d;
      float: right;
      position: relative;
      right: 10px;
    }
  }
}

span{
  font-size: 13px;
}

.redColor{
  color: #ae021a !important;
}
.red2Color{
  color: #e44035 !important;
}
.yellowColor{
  color: #b89112 !important;
}
.greenColor{
  color: #00b153 !important;
}

</style>
