<template>
  <div :style="{
    width: `${style.width}px`,
    height: `${style.height}px`,
    transform: `${style.transform}`,
  }" class="container">
    <div class="content">
      <div class="heardTitle">
        <div>
          <img alt="logo" src="@/assets/logo2.png" />
        </div>
      </div>
      <div class="inputvideo">
        <!--        <video-player-->
        <!--            class="video-player vjs-custom-skin"-->
        <!--            ref="videoPlayer"-->
        <!--            :playsinline="true"-->
        <!--            :options="playerOptions"-->
        <!--            style="height: 980px"-->
        <!--        ></video-player>-->
        <d-m-t ref="dmtCom" containerHeight="980px" containerWidth="1920px" style="z-index: 950;" />
      </div>
      <div v-if="deviceId !== 'none'" class="inputvideo2">
        <d-m-t2 ref="dmtCom2" :device-data="deviceData" :DeviceId="deviceId" containerHeight="100%"
          containerWidth="100%" style="z-index: 960;" />
      </div>
      <!-- <div class="inputTable">
        <dv-border-box-12 style="background-color: rgba(0, 13, 58,6);;padding: 5px 10px; width: 95%; height: 99%;overflow: hidden">
          <div class="roll-table-box" style="display: flex;">
            <div>参数名称</div>
            <div>参数值</div>
            <div>单位</div>
          </div>
          <vue-seamless-scroll ref="seamlessScroll" :class-option="signalTableListOption" :data="signalTableList"
            style="overflow: hidden;height: 90%;">
            <div v-for="(item, index) in signalTableList" :key="index"
              :style="{ backgroundColor: (index % 2 == 1) ? 'rgba(255,255,255,.0)' : 'rgba(20, 43, 84,.5)' }"
              class="roll-box">
              <div v-text="item.参数名称"></div>
              <div v-text="item.参数值"></div>
              <div v-text="item.单位"></div>
            </div>
          </vue-seamless-scroll>
        </dv-border-box-12>
      </div> -->
      <div class="flex-box-top">
        <div class="item-box" v-for="(item, index) in topLabelList" @click="openUrl(webManageBaseUrl + '/#/' + item.url)"
          :key="index">
          <div class="item-box-icon" :style="{ color: item.color }">
            <svg-icon :icon-class="item.svg" />
          </div>
          <div class="item-box-label">{{ item.label }}</div>
        </div>
      </div>
      <div class="c-left">
        <div class="left-content">
          <div class="flex-box-button">
            <dv-border-box-12 style="width: 38%; height: 95%;overflow: hidden">
              <div style="margin: 5px 0 5px 10px">
                <span style="
                    width: 20px;
                    height: 10px;
                    background: #016ce9;
                    display: inline-block;
                  "></span>
                <span style="color: #fff;margin-left: 10px;font-size: 20px;font-weight: 700;cursor: pointer"
                  @click="changeDeviceShow('none')">设备状态</span>
              </div>
              <div class="roll-table-box" style="display: flex;">
                <div>编号</div>
                <div>状态</div>
                <div style="flex: 1.3">料筒温度</div>
                <div>油温</div>
                <div style="flex: 2">物料名称</div>
                <div>数量</div>
                <div>完成数</div>
                <div style="flex: 1.2">完成率</div>
                <div style="flex: 3">设备状态履历</div>
              </div>
              <vue-seamless-scroll ref="seamlessScroll" :class-option="deviceStatusOption" :data="deviceStatusData"
                style="overflow: hidden;height: 90%;">
                <div v-for="(item, index) in deviceStatusData" :key="index" :class="'roll-boxLine-' + item.工位号" :style="{
                  backgroundColor:
                    index % 2 == 1
                      ? 'rgba(255,255,255,.0)'
                      : 'rgba(20, 43, 84,.5)',
                }" class="roll-box">
                  <div class="GWH" :style="{ backgroundColor: item.显示颜色 }"
                    style="cursor: pointer;border-bottom: 1px solid #00893d" v-text="item.工位号"
                    @click="changeDeviceShow(item.工序编码, item.工位号)"></div>
                  <!--                  <div v-if="item.状态 == 2" class="redColor">报警</div>-->
                  <!--                  <div v-else-if="item.状态 == 1" class="greenColor">运行</div>-->
                  <!--                  <div v-else-if="item.状态 == -1" class="grayColor">离线</div>-->
                  <!--                  <div v-else-if="item.状态 == 0" class="yellowColor">待机</div>-->
                  <!--                  <div v-else class="redColor">未知</div>-->
                  <div :style="{ color: getRollStatusColor(item.状态) }" class="ZT">
                    {{ rollStatusList[item.状态 + 1] }}
                  </div>
                  <div style="flex: 1.3" class="LTWD" v-text="item.料筒温度"></div>
                  <div class="YW" v-text="item.油温"></div>
                  <div style="flex: 2" class="WLMC" v-text="item.物料名称"></div>
                  <div class="SL" v-text="item.数量"></div>
                  <div class="WCS" v-text="item.产量"></div>
                  <div style="flex: 1.2" class="W" v-text="item.完成率 + '%'"></div>
                  <div style="flex: 3">
                    <div :class="'deviceStatusEcharts' + item.工位号" style="width: 200px;height: 30px"></div>
                  </div>
                </div>
              </vue-seamless-scroll>
            </dv-border-box-12>
            <dv-border-box-12 style="width: 20%;height: 95%;">
              <div style="margin: 13px 0 5px 20px">
                <span style="
                  width: 20px;
                  height: 10px;
                  background: #016ce9;
                  display: inline-block;
                "></span>
                <span style="color: #fff;margin-left: 10px;font-size: 20px;font-weight: 700;">全员设备使用情况</span>
              </div>
              <div id="bottomLeft" style="width: 100%; height: 200px;margin-top: 20px"></div>
            </dv-border-box-12>
            <dv-border-box-12 style="width: 20%;height: 95%;">
              <div style="margin: 13px 0 5px 20px">
                <span style="
                    width: 20px;
                    height: 10px;
                    background: #016ce9;
                    display: inline-block;
                  "></span>
                <span style="color: #fff;margin: 10px;font-size: 20px;font-weight: 700;">报警信息</span>
              </div>
              <div class="roll-table" style="height: 80%;">
                <div class="roll-table-box" style="display: flex;">
                  <div style="flex: .7;">编号</div>
                  <div style="flex: 1.5">报警内容</div>
                  <div style="flex: 1.3">报警时间</div>
                </div>
                <vue-seamless-scroll ref="seamlessScroll" :class-option="MiddleOption" :data="workOkDataInfo"
                  style="overflow: hidden;height: 100%">
                  <div v-for="(item, index) in workOkDataInfo" :key="index" :style="{
                    backgroundColor:
                      index % 2 == 1
                        ? 'rgba(255,255,255,.0)'
                        : 'rgba(20, 43, 84,.5)',
                  }" class="roll-box">
                    <div style=" flex: .6;" v-text="item.工位号"></div>
                    <div style=" flex: 1.5;text-align: left;" v-text="item.报警内容"></div>
                    <div style=" flex: 1.3" v-text="item.开始时间"></div>
                  </div>
                </vue-seamless-scroll>
              </div>
              <!-- <div id="bottomMiddle" style="width: 100%; height: 140px;margin-top: 20px"></div> -->
            </dv-border-box-12>
            <dv-border-box-12 style="width: 20%;height: 95%;">
              <div style="margin: 13px 0 5px 20px">
                ·
                <span style="
                  width: 20px;
                  height: 10px;
                  background: #016ce9;
                  display: inline-block;
                "></span>
                <span style="color: #fff;margin-left: 10px;font-size: 20px;font-weight: 700;">故障统计</span>
              </div>
              <div id="bottomRight" style="width: 100%; height: 200px;margin-top: 20px"></div>
            </dv-border-box-12>
          </div>
        </div>
      </div>
      <div class="c-center">
        <div class="center-header">浙江保镖智慧工厂总控中心</div>
        <div class="center-head">
          <div class="left">{{ hour + ":" + minute }}</div>
          <div class="right">
            <div class="r1">{{ year + "-" + month + "-" + day }}</div>
            <div class="r2">{{ dayOfWeek }}</div>
          </div>
        </div>
        <div class="center-content">
          <div class="middle-bottom"></div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { mqttIp, mqttPort, opname } from "@/utils/request";
import mqtt from "mqtt";
import SvgIcon from '@/components/SvgIcon/index.vue'

import DMT from "@/components/DMT/index";
import DMT2 from "@/components/DMT/index2";
import * as echarts from "echarts";
import { getLine } from "@/api/FactoryCalendar";
import $ from "jquery";
import axios from "axios";

export default {
  components: {
    SvgIcon,
    DMT,
    DMT2,
  },
  data() {
    return {
      mqttClient: null,
      dt_IframeUrl: "",
      timer1: null,
      refreshTab: true,
      planCountInfo: [4624, 2696, 58.3, 1252, 50, 96],
      rollStatusList: ["离线", "待机", "运行", "报警"],
      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",
      开始日期: "",
      bottomLeft: null, // 下左饼图
      bottomMiddle: null, // 下中 曲线
      bottomRight: null, // 下右 饼图

      bottomLeftOption: null, // 下左饼图配置
      bottomMiddleOption: null, // 下中 曲线配置
      bottomRightOption: null, // 下右 饼图配置

      leftTopCurveX: [],
      leftTopCurveXData1: [],
      leftTopCurveXData2: [],
      leftTopCurveXData3: [],
      leftTopCurveXData4: [],
      leftBottomPieData: {
        外派: "0",
        采购: "0",
        自制: "0",
      },
      bottomLeftData: [
        { value: 10, name: "关机", itemStyle: { color: "#626c7f" } },
        { value: 15, name: "报警", itemStyle: { color: "#ad4846" } },
        { value: 25, name: "运行", itemStyle: { color: "#489765" } },
        { value: 0, name: "待机", itemStyle: { color: "#ff9a02" } },
      ],
      leftBottomColumnarX: [],
      leftBottomColumnarXData1: [],
      leftBottomColumnarXData2: [],
      leftBottomColumnarXData3: [],
      rightMiddleCurveX: [],
      rightMiddleCurveXData1: [],
      rightMiddleCurveXData2: [],
      rightMiddleCurveXData3: [],
      rightBottomPieDataColor: [
        "#49a9ee",
        "#98d87d",
        "#ffd86e",
        "#f3857b",
        "#8996e6",
      ],
      rightBottomPieData: [
        { value: 76, name: "OP10", itemStyle: { color: "#49a9ee" } },
        { value: 56, name: "OP20", itemStyle: { color: "#98d87d" } },
        { value: 40, name: "OP30", itemStyle: { color: "#ffd86e" } },
        { value: 20, name: "OP40", itemStyle: { color: "#f3857b" } },
        { value: 12, name: "OP50", itemStyle: { color: "#8996e6" } },
      ],
      style: {
        width: "1920",
        height: "1080",
        transform: "scaleY(1) scaleX(1) translate(-50%, -50%)",
      },
      signalTableList: [],
      deviceId: "none",
      deviceIdName: "none",
      deviceNameList: [],
      deviceData: [],
      deviceDataTimer: null,
      timer: "",
      timer2: "",
      time: "time",
      // 时间属性
      year: "",
      month: "",
      day: "",
      hour: "",
      minute: "",
      second: "",
      dayOfWeek: "",
      deviceStatus_colors: ["grey", "orange", "green", "green", "blue"],
      deviceStatus_state: ["关机", "待机", "运行", "报警", "暂停"],
      deviceStatus_table: [],
      leftTopColumnarX: [
        "0.01",
        "0.02",
        "0.03",
        "0.04",
        "0.05",
        "0.06",
        "0.07",
        "0.08",
        "0.09",
      ],
      leftTopColumnarXData1: [3, 9, 12, 41, 56, 43, 21, 11, 5],
      leftTopColumnarXData2: [2, 7, 11, 34, 41, 31, 16, 6, 2],
      leftMiddleColumnarX: [
        "播门气打上料",
        "播门气下料",
        "ST1挡料气缸",
        "5T3推靠气缸",
      ],
      leftMiddleColumnarXData1: [16, 40, 27, 41],
      leftMiddleColumnarXData2: [48, 28, 46, 38],
      leftMiddleColumnarXData3: [31, 17, 44, 28],
      rightMiddlePieColorList: ["#e2ae03", "#aa493c", "#459763", "#49a9ee"],
      bottomMiddleX: ["08", "09", "10", "11", "12", "13", "14"],
      bottomMiddleXData1: [48, 45, 62, 42, 50, 52, 49],
      // 1-计划，2-计划确认，3-下达，4-开工，5-完工，6-结案，7-结算
      orderStatusList: [
        "计划",
        "计划确认",
        "下达",
        "开工",
        "完工",
        "结案",
        "结算",
      ],
      // 中间滚动
      MiddleOption: {
        step: 0.2,
        direction: 1,
        limitMoveNum: 3,
        openWatch: true,
        hoverStop: true,
      },
      webManageBaseUrl: window.dt_Config.openManageBaseUrl,
      // 订单看板
      workOkDataInfo: [],
      deviceStatusData: [],
      deviceStatusDataOld: {},
      deviceStatusOption: {
        step: 0.4,
        direction: 1,
        limitMoveNum: 36,
        openWatch: true,
        hoverStop: true,
      },
      signalTableListOption: {
        step: 0.4,
        direction: 1,
        limitMoveNum: 20,
        openWatch: true,
        hoverStop: true,
      },
      topLabelList: [
        { label: '订单查询', url: 'ReportQuery/WorkOrderSearch/index', svg: 'MenuManagement', color: '#34812e' },
        { label: '报警查询', url: 'ReportQuery/AlarmSearch/index', svg: 'BasicAlarmMaintenance', color: '#897a4e' },
        { label: '关键数据曲线', url: 'ReportQuery/SpcSearch/index', svg: 'GrindingQualityHistory', color: '#705e92' },
        { label: '设备状态履历', url: 'ReportQuery/DeviceRunTimeStatus/index', svg: 'MachiningSequenceAdjustment', color: '#6c7e24' },
        { label: '日产量统计', url: 'ReportQuery/DayOutputCount/index', svg: 'MachineToolsMaintenance', color: '#197f31' },
        { label: 'JPH统计', url: 'ReportQuery/JPHCount/index', svg: 'ProcessPlanningNew', color: '#715f4c' },
        { label: '质量数据查询', url: 'ReportQuery/QualityDataSearch/index', svg: 'ReplenishmentOrders', color: '#217f6e' },
        { label: '过点信息查询', url: 'ReportQuery/WorkpieceOverStationSearch/index', svg: 'TLScoresApproval', color: '#3b7c38' },
        { label: '参数实时监控', url: 'ReportQuery/SignalNowSearch/index', svg: 'ViewFocusMaintenance', color: '#6d7c8a' },
        { label: '信号实时监控', url: 'ReportQuery/KeyPositionNowSearch/index', svg: 'BasicVariableMaintenance', color: '#75371c' },
        { label: '设备实时状态', url: 'ReportQuery/DeviceNowStatusSearch/index', svg: 'MachiningSequenceAdjustment', color: '#75371c' }
      ],
      playerOptions: {
        // 视频源
        // sources: [
        //   {
        //     type: 'video/mp4', // 视频类型
        //     src: require('@/assets/保镖视频.mp4') // 视频源地址
        //   }
        //   // 你可以在这里添加多个源以支持不同的格式或分辨率
        // ],
        // 视频封面
        // poster: 'https://example.com/path/to/poster.jpg',
        // 是否自动播放
        autoplay: true,
        // 是否静音
        muted: true,
        // 是否循环播放
        loop: true,
        // 是否预加载视频
        preload: "auto",
        // 控制栏显示选项
        controls: true,
        // 语言
        language: "zh-CN",
        // 其他播放器选项
        notSupportedMessage: "此视频暂无法播放，请稍后再试", // 当无法播放时显示的消息
        // 流配置，适用于直播流
        live: false,
        // 更多配置...
      },
    };
  },
  created() {
    // this.dt_IframeUrl = window.ConnectConfig.dt_IframeUrl
  },
  mounted() {
    const that = this;

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

    // echarts图表绘制部分
    this.initEchartDom();
    this.getShowDataList();
    this.setEchartData();
    this.getDeviceStatusList(); // 设备状态列表
    this.getSignalTableList();
    // 定时器部分
    this.timer = setInterval(() => {
      this.getNowTime();
    }, 1000);
    this.timer2 = setInterval(() => {
      this.setEchartData();
    }, 1000 * 10);
    setInterval(() => {
      this.getDeviceStatusList(); // 设备状态列表
      this.getSignalTableList();
      this.getShowDataList();
    }, 1000 * 5);
  },
  beforeDestroy() {
    clearInterval(this.timer);
    clearInterval(this.timer2);
  },
  methods: {
    getShowDataList() {
      var param = [];
      param[0] = ["OpName", this.deviceIdName];
      const data = this.CreateData1("11", "基础_数据显示_查询", param);
      this.ExecDatabase(data).then((res) => {
        this.deviceNameList = [];
        if (res.data.length > 0) {
          this.deviceNameList = res.data;
        }
      });
    },
    changeDeviceShow(deviceId, deviceIdName) {
      this.deviceId = "none";
      this.deviceIdName = "";
      this.deviceData = [];
      const scope = this;
      if (this.deviceDataTimer) {
        clearInterval(this.deviceDataTimer);
      }
      setTimeout(() => {
        scope.deviceId = deviceId;
        scope.deviceIdName = deviceIdName;
        scope.deviceDataTimer = setInterval(() => {
          scope.getDeviceData();
        }, 1000);
      }, 1000);
    },
    getDeviceData() {
      let TagList = "";
      if (this.deviceNameList.length === 0) {
        return;
      }
      TagList = JSON.stringify(this.deviceNameList);
      axios
        .post(window.dt_Config.getPlcDataUrl, {
          req_code: "4e2b25bf-c275-989a-2f67-695a406d347d",
          req_from: "WEB_Manage",
          req_cmd: "Cmd_Opc_Read",
          req_param: {
            TagList: TagList,
          },
        })
        .then((res) => {
          const data = res.data.res_data;
          const StructSerialize = data.StructSerialize;
          try {
            this.deviceData = JSON.parse(StructSerialize);
          } catch (e) {
            this.deviceData = [];
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    getSignalTableList() {
      const data = this.CreateData1("11", "TV_信号数据_查询");
      this.ExecDatabase(data).then((res) => {
        this.signalTableList = [];
        if (res.data.length > 0) {
          this.signalTableList = res.data;
        }
      });
    },
    getMainPlanCountInfoData() {
      const 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() {
      const 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() {
      const data = this.CreateData1("11", "左中装配看板_表格_查询");
      this.ExecDatabase(data).then((res) => {
        this.workDataInfo = res.data;
      });
    },
    getUnfinishedDataInfo() {
      const data = this.CreateData1("11", "左下未完成看板_表格_查询");
      this.ExecDatabase(data).then((res) => {
        this.unfinishedDataInfo = res.data;
      });
    },
    getContract2DataInfo() {
      const data = this.CreateData1("11", "右上合同看板_表格_查询");
      this.ExecDatabase(data).then((res) => {
        this.contract2DataInfo = res.data;
      });
    },
    getLackDataInfo() {
      const data = this.CreateData1("11", "右中缺件看板_表格_查询");
      this.ExecDatabase(data).then((res) => {
        this.lackDataInfo = res.data;
      });
    },
    getQualityDataInfo() {
      const data = this.CreateData1("11", "右下质量看板_表格_查询");
      this.ExecDatabase(data).then((res) => {
        this.qualityDataInfo = res.data;
      });
    },
    getContractMainDataInfo() {
      const 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) {
      const param = [];
      param[0] = ["合同号", row.内部合同号];
      const 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.bottomLeft = echarts.init(document.getElementById("bottomLeft"));
      // this.bottomMiddle = echarts.init(document.getElementById('bottomMiddle'))
      this.bottomRight = echarts.init(document.getElementById("bottomRight"));
    },
    setEchartData() {
      this.getBottomLeftOptionData();
      // this.getBottomMiddleOptionData()
      this.getBottomRightOptionData();
      this.getWorkOkDataInfo();
    },
    getDeviceStatusList() {
      const param = [];
      const data = this.CreateData1("11", "设备状态_查询", param);
      this.ExecDatabase(data).then((res) => {
        if (res.data.length > 0) {
          // this.deviceStatusData = res.data
          // 有不同才写入数据
          if (this.deviceStatusData.length === 0) {
            this.deviceStatusData = res.data;
          } else {
            for (let i = 0; i < this.deviceStatusData.length; i++) {
              const item = this.deviceStatusData[i];
              const item2 = res.data[i];
              const className = ".roll-boxLine-" + item2.工位号;
              if (item.工位号 !== item2.工位号) {
                item.工位号 = item2.工位号;
                $(className + " .GWH").text(item2.工位号);
              }
              if (item.状态 !== item2.状态) {
                item.状态 = item2.状态;
                $(className + " .ZT").text(this.rollStatusList[item2.状态 + 1]);
                $(className + " .ZT").css({
                  color: this.getRollStatusColor(item2.状态),
                });
              }
              if (item.料筒温度 !== item2.料筒温度) {
                item.料筒温度 = item2.料筒温度;
                $(className + " .LTWD").text(item2.料筒温度);
              }
              if (item.油温 !== item2.油温) {
                item.油温 = item2.油温;
                $(className + " .YW").text(item2.油温);
              }
              if (item.物料名称 !== item2.物料名称) {
                item.物料名称 = item2.物料名称;
                $(className + " .WLMC").text(item2.物料名称);
              }
              if (item.数量 !== item2.数量) {
                item.数量 = item2.数量;
                $(className + " .SL").text(item2.数量);
              }
              if (item.产量 !== item2.产量) {
                item.产量 = item2.产量;
                $(className + " .WCS").text(item2.产量);
              }
              if (item.完成率 !== item2.完成率) {
                item.完成率 = item2.完成率;
                $(className + " .WCL").text(item2.完成率 + "%");
              }
            }
          }
          this.deviceStatusData = this.deviceStatusData;
          for (const item of res.data) {
            const param = [];
            param[0] = ["工位号", item.工位号];
            const data2 = this.CreateData1(
              "11",
              "设备管理_设备每分钟状态_查询",
              param
            );
            this.ExecDatabase(data2).then((res) => {
              // if (res.data.length > 0) {
              this.setDeviceStatusById(
                "deviceStatusEcharts" + item.工位号,
                res.data
              );
              // }
            });
          }
        }
      });
    },
    getRollStatusColor(status) {
      if (status === -1) return "#919499";
      if (status === 0) return "#b89112";
      if (status === 1) return "#00b153";
      if (status === 2) return "#ae021a";
    },
    setDeviceStatusById(id, data) {
      const deviceStatus_table = data;
      const scope = this;
      const deviceStatus_data = [];
      const deviceStatus_yAxisValue = [];
      let deviceStatus_index = 0;
      if (deviceStatus_table.length === 1) {
        deviceStatus_data.push({
          itemStyle: { normal: { color: deviceStatus_table[0].颜色 } }, // 条形颜色
          name: deviceStatus_table[0].设备状态名称,
          value: [
            0,
            deviceStatus_table[0].开始时间,
            deviceStatus_table[0].结束时间,
          ],
        });
      } else {
        for (let i = 0; i < deviceStatus_table.length; i++) {
          if (i < deviceStatus_table.length) {
            if (i === 0) {
              deviceStatus_index = 0;
              deviceStatus_yAxisValue.push(deviceStatus_table[i].工位号);
            } else if (
              deviceStatus_table[i].工位号 !== deviceStatus_table[i - 1].工位号
            ) {
              deviceStatus_index++; // y轴索引
              deviceStatus_yAxisValue.push(deviceStatus_table[i].工位号);
            }
          }
          deviceStatus_data.push({
            itemStyle: { normal: { color: deviceStatus_table[i].颜色 } }, // 条形颜色
            name: deviceStatus_table[i].设备状态名称,
            value: [
              parseInt(deviceStatus_index),
              deviceStatus_table[i].开始时间,
              deviceStatus_table[i].结束时间,
            ],
          });
        }
      }
      // const myChart = echarts.init(document.getElementById('myChart4'))
      var option = {
        // title: {
        //   left: 'center',
        //   text: '设备状态分布图(分钟)',
        //   textStyle: {
        //     color: '#ffffff'
        //   }
        // },
        // 隐藏标题
        title: {
          show: false,
        },
        color: this.deviceStatus_colors,
        tooltip: {
          // 提示框
          formatter(params) {
            return (
              params.value[1].substr(11, 5) +
              "~" +
              params.value[2].substr(11, 5)
            );
          }, // 数据的值
        },
        grid: {
          // 绘图网格
          left: "-40%",
          right: "5%",
          top: "25%",
          bottom: "-50%",
          containLabel: true,
          show: false,
        },
        legend: {
          // 图例
          data: ["关机", "待机", "运行", "暂停", "报警"],
          selectedMode: false,
          textStyle: {
            color: "#ffffff",
          },
          show: false,
        },
        xAxis: {
          type: "time",
          axisLine: {
            lineStyle: {
              color: "#ffffff",
            },
            show: true,
          },
          axisTick: {
            show: true,
          },
          show: false,
          boundaryGap: false, // 确保坐标轴从绘图区域的边缘开始
          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",
            },
          },
          show: false,
          boundaryGap: false, // 确保坐标轴从绘图区域的边缘开始
          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,
          },
        ],
      };

      var chartContainers = document.querySelectorAll("." + id);
      // console.log(chartContainers)
      chartContainers.forEach(function (container) {
        var existInstance = echarts.getInstanceByDom(container);
        if (existInstance) {
          // console.log('已存在DOM 设值')
          // 判断 新config与老config 是否一致
          if (
            option.series[5].data.length !==
            existInstance.getOption().series[5].data.length
          ) {
            // existInstance.dispose()
            existInstance.clear();
            console.log("值发生变化，更新数据");
            var startTime222 = new Date().getTime();
            existInstance.setOption(option);
            var endTime222 = new Date().getTime();
            var executionTime222 = endTime222 - startTime222;
            console.log("方法222执行时间：" + executionTime222 + "毫秒");
          } else {
            return;
          }
        } else {
          console.log("不存在DOM 设值");
          var chart = echarts.init(container);
          chart.setOption(option);
        }

        // 初始化新的实例
        // var chart = echarts.init(container)
        // 设置图表的配置项
        // chart.setOption(option)
      });

      // const DeviceStatus = echarts.init(document.getElementById(id))
      // DeviceStatus.setOption(option)
    },
    getRightMiddlePieData() {
      const 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++) {
            const 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() {
      const 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].目标稼动率;
          const 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() {
      const 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++) {
            const ele = res.data[i];
            this.rightTopColumnarX.push(ele.HH);
            this.rightTopColumnarXData.push(
              Number(ele.DataCountOK) + Number(ele.DataCountNG)
            );
          }
        })
        .then(() => {
          this.rightTopColumnarOptionSet();
        });
    },
    getLeftTopColumnarData() {
      getLine().then((response) => {
        console.log(response.data, 4444);
        if (response.data.length !== 0) {
          // this.drawLine(response.data)
          this.leftTopColumnarOptionSet(response.data);
        } else {
          this.$message.error("数据数量过少,无法统计");
        }
      });
      // const data = this.CreateData1('11', 'SPC_查询')
      // this.ExecDatabase(data).then((res) => {
      //   if (res.data.length <= 0) {
      //     return
      //   }
      //   this.leftTopColumnarX = []
      //   this.leftTopColumnarXData1 = []
      //   this.leftTopColumnarXData2 = []
      //   for (let i = 0; i < res.data.length; i++) {
      //     const ele = res.data[i]
      //     this.leftTopColumnarX.push(ele.value1)
      //     this.leftTopColumnarXData1.push(ele.value2)
      //     this.leftTopColumnarXData2.push(ele.value3)
      //   }
      // }).then(() => {
      //   this.leftTopColumnarOptionSet()
      // })
    },
    openUrl(url) {
      window.open(url, '_blank');
    },
    getLeftMiddleColumnarData() {
      const data = this.CreateData1("11", "零部件智能预测性维护_查询");
      this.ExecDatabase(data)
        .then((res) => {
          if (res.data.length <= 0) {
            return;
          }
          this.leftMiddleColumnarX = [];
          this.leftMiddleColumnarXData1 = [];
          this.leftMiddleColumnarXData2 = [];
          this.leftMiddleColumnarXData3 = [];
          for (let i = 0; i < res.data.length; i++) {
            const ele = res.data[i];
            this.leftMiddleColumnarX.push(ele.名称);
            this.leftMiddleColumnarXData1.push(ele.制定);
            this.leftMiddleColumnarXData2.push(ele.已用);
            this.leftMiddleColumnarXData3.push(ele.剩余);
          }
        })
        .then(() => {
          this.leftMiddleColumnarOptionSet();
        });
    },
    getBottomRightOptionData() {
      const data = this.CreateData1("11", "故障统计_查询");
      this.ExecDatabase(data)
        .then((res) => {
          if (res.data.length <= 0) {
            res.data = [
              {
                工位号: "无",
                数量: 0,
              },
            ];
            // return
          }
          this.rightBottomPieData = [];
          for (let i = 0; i < res.data.length; i++) {
            const ele = res.data[i];
            const obj = {
              value: ele.数量,
              name: ele.工位号,
              itemStyle: {
                color: this.rightBottomPieDataColor[i],
              },
            };
            this.rightBottomPieData.push(obj);
          }
        })
        .then(() => {
          this.bottomRightOptionSet();
        });
    },
    getBottomLeftOptionData() {
      const data = this.CreateData1("11", "设备使用情况_查询");
      this.ExecDatabase(data)
        .then((res) => {
          this.bottomLeftData[0].value = res.data[0].关机;
          this.bottomLeftData[1].value = res.data[0].报警;
          this.bottomLeftData[2].value = res.data[0].工作;
          this.bottomLeftData[3].value = res.data[0].待机;
        })
        .then(() => {
          this.bottomLeftOptionSet();
        });
    },
    getBottomRightPieOptionData() {
      const data = this.CreateData1("11", "故障统计_查询");
      this.ExecDatabase(data)
        .then((res) => {
          if (res.data.length <= 0) {
            return;
          }
          this.rightBottomPieData = [];
          for (let i = 0; i < res.data.length; i++) {
            const ele = res.data[i];
            const obj = {
              value: ele.数量,
              name: ele.工位号,
              itemStyle: {
                color: this.rightBottomPieDataColor[i],
              },
            };
            this.rightBottomPieData.push(obj);
          }
        })
        .then(() => {
          this.bottomRightPieOptionSet();
        });
    },
    getWorkOkDataInfo() {
      var param = [];
      const data = this.CreateData1(
        "11",
        "TV_报警_记录_历史_查询",
        param
      );
      this.ExecDatabase(data).then((response) => {
        if (response.data.length > 0) {
          this.workOkDataInfo = response.data;
        } else {
          this.workOkDataInfo = [];
        }
      });
    },
    getWorkStatusData() {
      var param = [];
      const data = this.CreateData1("11", "生产状态_查询", param);
      this.ExecDatabase(data).then((response) => {
        this.workStatusData.planCount = response.data[0].计划产量;
        this.workStatusData.actualCount = response.data[0].实际产量;
        this.workStatusData.fillRate = this.num(response.data[0].完成率);
      });
    },
    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() {
      const 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(res) {
      const usl = parseFloat(res.split("|")[4].split(",")[0]).toFixed(4);
      const qu = parseFloat(res.split("|")[4].split(",")[1]).toFixed(4);
      const sl = parseFloat(res.split("|")[4].split(",")[2]).toFixed(4);
      const ql = parseFloat(res.split("|")[4].split(",")[3]).toFixed(4);
      const lsl = parseFloat(res.split("|")[4].split(",")[4]).toFixed(4);
      const cpk = parseFloat(res.split("|")[1].split(",")[6]).toFixed(2);
      const cp = parseFloat(res.split("|")[1].split(",")[5]).toFixed(2);
      const USL = parseInt(res.split("|")[4].split(",")[0]);
      const QU = parseInt(res.split("|")[4].split(",")[1]);
      const SL = parseInt(res.split("|")[4].split(",")[2]);
      const QL = parseInt(res.split("|")[4].split(",")[3]);
      const LSL = parseInt(res.split("|")[4].split(",")[4]);
      const xData = res.split("|")[3].split(",");
      const xdata = [];
      for (let i = 0; i < xData.length; i++) {
        xdata.push(xData[i]);
      }
      const yData = res.split("|")[2].split(",");
      const ydata = [];
      for (let i = 0; i < yData.length; i++) {
        ydata.push(yData[i]);
      }
      const lineData = res.split("|")[0].split(",");
      const linedata = [];
      for (let i = 0; i < lineData.length; i++) {
        linedata.push(lineData[i]);
      }
      console.log(xData, 1, lineData, 2);
      const leftTopColumnarOption2 = {
        title: {
          left: "center",
          text: "正态分布图",
          subtext: "Cp=" + cp + " Cpk=" + cpk,
          textStyle: {
            color: "#afafaf",
          },
        },
        tooltip: {
          trigger: "axis",
        },
        xAxis: {
          type: "category",
          data: xdata,
          show: false,
        },
        yAxis: {
          type: "value",
          scale: "true",
        },
        series: [
          {
            smooth: true,
            showSymbol: false,
            name: "测量值",
            type: "line",
            data: linedata,
            markLine: {
              data: [
                { xAxis: USL, name: "USL", value: usl },
                { xAxis: LSL, name: "LSL", value: lsl },
                { xAxis: QU, name: "QU", value: qu },
                { xAxis: QL, name: "QL", value: ql },
                { xAxis: SL, name: "SL", value: sl },
              ],
              label: {
                normal: {
                  position: "middle",
                  formatter: "{b} : {c}",
                },
              },
              lineStyle: {
                color: {
                  type: "radial",
                  x: 0.5,
                  y: 0.5,
                  r: 0.5,
                  colorStops: [
                    {
                      offset: 0,
                      color: "red", // 0% 处的颜色
                    },
                    {
                      offset: 1,
                      color: "blue", // 100% 处的颜色
                    },
                  ],
                  globalCoord: false, // 缺省为 false
                },
              },
            },
          },
        ],
      };
      if (this.leftTopColumnarOption !== leftTopColumnarOption2) {
        this.leftTopColumnarOption = leftTopColumnarOption2;
        this.leftTopColumnar.setOption(this.leftTopColumnarOption);
      }
    },
    inputPlanCount() {
      // 使用element ui弹出输入框输入计划产量
      this.$prompt("请输入计划产量", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputPattern: /^[0-9]*$/,
        inputErrorMessage: "请输入数字",
      }).then(({ value }) => {
        var param = [];
        param[0] = ["计划产量", value];
        const data = this.CreateData1(
          "12",
          "大屏看板配置_计划产量_修改",
          param
        );
        this.ExecDatabase(data).then((response) => {
          if (response.data[0].result == 1) {
            this.$message({
              type: "success",
              message: "修改成功!",
            });
            this.getWorkStatusData();
          } else {
            this.$message({
              type: "error",
              message: "修改失败!",
            });
          }
        });
      });
    },
    leftMiddleColumnarOptionSet() {
      this.leftMiddleColumnarOption = {
        legend: {
          top: "5%",
          right: "5%", // 将图例放置在右侧
          icon: "circle", // 设置图例的标识样式为实心圆点
          itemWidth: 10, // 设置图例标记的宽度
          itemHeight: 10, // 设置图例标记的高度
          textStyle: {
            fontSize: 12,
            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"; // 默认颜色，如果没有匹配到
            },
          },
        },
        grid: {
          top: "15%",
          left: "7%",
          right: "5%",
          bottom: "10%",
        },
        tooltip: {
          trigger: "item",
        },
        xAxis: {
          type: "category",
          data: this.leftMiddleColumnarX, // ['1T240211-1', '1T240211-2', '1T240211-3', '1T240211-4'],
          axisLabel: {
            interval: 0, // 显示所有标签
            fontSize: 10, // 设置x轴文字的大小
            color: "#fff",
          },
        },
        yAxis: {
          type: "value",
          splitLine: {
            show: true,
            lineStyle: {
              type: "dashed", // 分隔线类型设置为虚线
            },
          },
          axisTick: {
            show: false,
          },
          axisLine: {
            show: true,
          },
        },
        series: [
          {
            name: "制定",
            data: this.leftMiddleColumnarXData1, // [40, 22, 47, 39],
            type: "bar",
            itemStyle: { color: "#ad4846" },
            barWidth: 15,
            barCategoryGap: "30",
          },
          {
            name: "已用",
            data: this.leftMiddleColumnarXData2, // [21, 45, 32, 46],
            type: "bar",
            itemStyle: { color: "#479867" },
            barWidth: 15,
            barCategoryGap: "30",
          },
          {
            name: "剩余",
            data: this.leftMiddleColumnarXData3, // [21, 45, 32, 46],
            type: "bar",
            smooth: true,
            itemStyle: { color: "#e6ad00" },
            barWidth: 15,
            barCategoryGap: "30",
          },
        ],
      };
      this.leftMiddleColumnar.setOption(this.leftMiddleColumnarOption);
    },
    bottomMiddleOptionSet() {
      this.bottomMiddleOption = {
        title: {
          text: "计划执行情况",
          left: "center",
          top: "-3%",
          textStyle: {
            color: "#007175",
            fontSize: 18,
          },
        },
        tooltip: {
          trigger: "axis",
        },
        legend: {
          data: ["工艺部", "采购部", "生产部", "装配部"],
          orient: "vertical", // 设置图例为竖向排列
          right: 10, // 将图例放置在右侧
          icon: "circle", // 设置图例的标识样式为实心圆点
          itemWidth: 10, // 设置图例标记的宽度
          itemHeight: 10, // 设置图例标记的高度
          textStyle: {
            color: "#a2a7b3",
            fontSize: 14,
          },
        },
        grid: {
          top: "15%",
          left: "3%",
          right: "16%",
          bottom: "0%",
          containLabel: true,
        },
        xAxis: {
          type: "category",
          boundaryGap: false,
          data: [
            "09-01",
            "09-02",
            "09-03",
            "09-04",
            "09-05",
            "09-06",
            "09-07",
            "09-08",
            "09-09",
            "09-10",
            "09-11",
            "09-12",
            "09-13",
            "09-14",
            "09-15",
            "09-16",
            "09-17",
            "09-18",
            "09-19",
          ],
          axisLabel: {
            color: "#747c8c",
          },
        },
        yAxis: {
          type: "value",
          axisLine: {
            show: true,
          },
          axisLabel: {
            color: "#747c8c",
          },
        },
        series: [
          {
            name: "工艺部",
            type: "line",
            data: [
              120,
              132,
              101,
              134,
              90,
              230,
              210,
              120,
              132,
              101,
              134,
              90,
              230,
              210,
              120,
              132,
              101,
              134,
              90,
            ],
            itemStyle: {
              color: "#f48491", // 设置线条颜色
            },
          },
          {
            name: "采购部",
            type: "line",
            data: [
              220,
              182,
              191,
              234,
              290,
              330,
              310,
              220,
              182,
              191,
              234,
              290,
              330,
              310,
              220,
              182,
              191,
              234,
              290,
            ],
            itemStyle: {
              color: "#f4f400", // 设置线条颜色
            },
          },
          {
            name: "生产部",
            type: "line",
            data: [
              150,
              232,
              201,
              154,
              190,
              330,
              410,
              150,
              232,
              201,
              154,
              190,
              330,
              410,
              150,
              232,
              201,
              154,
              190,
            ],
            itemStyle: {
              color: "#7b44bb", // 设置线条颜色
            },
          },
          {
            name: "装配部",
            type: "line",
            data: [
              320,
              332,
              301,
              334,
              390,
              330,
              320,
              320,
              332,
              301,
              334,
              390,
              330,
              320,
              320,
              332,
              301,
              334,
              390,
            ],
            itemStyle: {
              color: "#00b273", // 设置线条颜色
            },
          },
        ],
      };
      this.bottomMiddle.setOption(this.bottomMiddleOption);
    },
    bottomLeftOptionSet() {
      this.bottomLeftOption = {
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          right: 5,
          top: "3%",
          itemGap: 10,
          icon: "circle",
          formatter: function (name) {
            var total = 0;
            var targetValue;
            // 直接使用rightBottomPieOption，而不是this
            this.bottomLeftOption.series[0].data.forEach(function (item) {
              total += item.value;
              if (item.name === name) {
                targetValue = item.value;
              }
            });
            var percentage = ((targetValue / total) * 100).toFixed(0) + "%";
            return name + " " + targetValue + "台 " + percentage;
          }.bind(this), // 使用bind(this)确保this指向正确的上下文
          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%", "80%"],
            center: ["30%", "50%"],
            avoidLabelOverlap: false,
            itemStyle: {
              borderRadius: 10,
              borderColor: "rgba(9, 26, 54,.2)",
              borderWidth: 5,
            },
            label: {
              show: false,
              position: "center",
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 40,
                fontWeight: "bold",
              },
            },
            labelLine: {
              show: false,
            },
            data: this.bottomLeftData,
          },
        ],
      };
      this.bottomLeft.setOption(this.bottomLeftOption);
    },
    bottomRightOptionSet() {
      this.bottomRightOption = {
        tooltip: {
          trigger: "item",
        },
        legend: {
          orient: "vertical",
          right: 5,
          top: "5%",
          itemGap: 10,
          icon: "circle",
          formatter: function (name) {
            var total = 0;
            var targetValue;
            // 直接使用rightBottomPieOption，而不是this
            this.bottomRightOption.series[0].data.forEach(function (item) {
              total += item.value;
              if (item.name === name) {
                targetValue = item.value;
              }
            });
            var percentage = ((targetValue / total) * 100).toFixed(2) + "%";
            if (targetValue == 0 && total == 0) percentage = "100%";
            return name + " " + targetValue + "个 " + percentage;
          }.bind(this), // 使用bind(this)确保this指向正确的上下文
          textStyle: {
            fontSize: 14,
            color: "#fff",
          },
        },
        series: [
          {
            name: "故障统计",
            type: "pie",
            radius: "80%",
            right: "50%",
            center: ["50%", "50%"],
            labelLine: {
              show: false,
            },
            label: {
              show: false,
            },
            data: this.rightBottomPieData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };
      this.bottomRight.setOption(this.bottomRightOption);
    },
    num(num) {
      return (num + "").indexOf(".") == -1 ? num : num.toFixed(1);
      // return num
    },
    getmidddlelist() {
      const 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 weekday = [
        "星期日",
        "星期一",
        "星期二",
        "星期三",
        "星期四",
        "星期五",
        "星期六",
      ];
      const date = new Date();
      this.year = date.getFullYear();
      this.month = this.zeroFill(date.getMonth() + 1);
      this.day = this.zeroFill(date.getDate());
      this.hour = this.zeroFill(date.getHours());
      this.minute = this.zeroFill(date.getMinutes());
      this.second = this.zeroFill(date.getSeconds());
      this.dayOfWeek = weekday[date.getDay()];
    },
  },
  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() {
          const 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;
  background-color: #00802d;
  color: white;

  .heardTitle {
    //margin-top: 2%;
    height: 100px;
    display: flex;
    width: 100%;
    align-items: center;
    position: fixed;
    background-color: #0a1936;

    img {
      margin: 10px 30px;
      height: 80px;
      width: 200px;
    }
  }

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

    .c-left {
      width: 40%;
      height: 100%;
      margin-top: 110px;

      .left-content {
        height: 92.5%;

        .main {
          height: 32%;
        }

        .main2 {
          height: 80%;
        }

        .main3 {
          height: 32%;
        }

        .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: 76%;
      box-sizing: border-box;
      position: relative;
      left: -1.2%;

      .center-header {
        height: 10.7%;
        display: flex;
        //justify-content: center;
        margin-left: -30px;
        //align-items: center;
        font-size: 50px;
        font-weight: bold;
        letter-spacing: 5px;
        line-height: 100px;
      }

      .center-head {
        width: 300px;
        height: 60px;
        position: absolute;
        right: 60px;
        top: 20px;
        display: flex;
        text-align: center;

        .left {
          width: 40%;
          font-size: 40px;
          line-height: 70px;
          font-weight: bold;
        }

        .right {
          width: 60%;
          font-size: 25px;
          line-height: 35px;
        }
      }

      .center-content {
        height: 0px;
        padding: 1rem;
        box-sizing: border-box;
        z-index: -10;

        .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);
            }
          }

          .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;
              }
            }
          }
        }

        .middle-bottom {
          position: absolute;
          bottom: 10px;
          width: 100%;
          height: 315px;
          box-sizing: border-box;
          margin-top: 10px;
          display: flex;

          .middle-bottom-left {
            width: 40%;
            margin: 0 5px;
          }

          .middle-bottom-middle {
            width: 35%;
          }

          .middle-bottom-right {
            margin: 0 0 0 2px;
            width: 40%;
          }
        }
      }

      .center-bottom {
        height: 300px;
        padding: 1rem;
        box-sizing: border-box;
      }
    }

    .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%;
    }
  }
}

.topWorkStatus {
  //height: 300px;
  position: fixed;
  top: 150px;
  left: 850px;
  z-index: 9999999999;
  display: flex;
  background-color: rgba(0, 0, 0, 0);

  .item {
    display: flex;
    width: 200px;

    .left {
      width: 75px;
      height: 60px;
      background: url("~@/../src/assets/time.png") no-repeat !important;
      background-size: 100% 100% !important;
      margin-right: 10px;
    }

    .right {
      background-color: rgba(0, 0, 0, 0) !important;

      .top {
        font-size: 23px;
        font-weight: 700;
      }

      .bottom {
        font-size: 22px;
        font-weight: 700;
      }
    }
  }

  .item1 {
    .right>.bottom {
      color: #4572a7;
    }
  }

  .item2 {
    margin: 0 100px;

    .right>.bottom {
      color: #f9bf00;
    }
  }

  .item3 {
    .right>.bottom {
      color: #479867;
    }
  }
}

.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;
          }
        }
      }
    }
  }
}

.dv-border-box-12 {
  background-color: rgba(10, 25, 54, 0.4);
  z-index: 100;
}

.roll-table {
  border: 1px solid #22405c;
  width: 94%;
  margin-left: 3%;
  height: 260px;
  overflow: hidden;
}

.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: 14px;
  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: 15px;
  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;
    }
  }
}

.flex-box-button {
  position: fixed;
  display: flex;
  bottom: 10px;
  justify-content: space-evenly;
  align-items: center;
  width: 100vw;
  height: 300px;
  z-index: 100;
}

.flex-box-top {
  display: flex;
  position: fixed;
  top: 100px;
  left: 0;
  width: 100vw;
  height: 10vh;
  z-index: 100;
  text-align: center;
  justify-content: space-evenly;

  .item-box {

    .item-box-icon {
      width: 100px;
      height: 80px;
      margin: 0 auto;
      font-size: 60px;
      color: #fff;
    }

    .item-box-label {
      font-size: 20px;
      font-weight: 700;
      color: #fff;
    }
  }
}

.redColor {
  color: #ae021a !important;
}

.red2Color {
  color: #e44035 !important;
}

.yellowColor {
  color: #b89112 !important;
}

.greenColor {
  color: #00b153 !important;
}

.grayColor {
  color: #919499 !important;
}

.inputvideo {
  position: fixed;
  bottom: 0;
  left: 0px;
  height: 980px;
  width: 1920px;
  z-index: 50;

  .video-player {
    height: 980px;

    video {
      width: 100%;
      /* 视频宽度占满容器 */
      height: 100%;
      /* 视频高度占满容器 */
      object-fit: fill;
      /* 视频内容拉伸以填满整个容器，不保持宽高比 */
    }
  }
}

.inputvideo2 {
  position: fixed;
  top: 230px;
  right: 280px;
  height: 450px;
  z-index: 50;
}

.inputTable {
  position: fixed;
  top: 230px;
  right: 10px;
  height: 450px;
  width: 250px;
  z-index: 960;
}

::v-deep .video-js .vjs-tech {
  object-fit: fill;
}

::v-deep .vjs-poster {
  background-size: cover;
}

::v-deep .video-js {
  height: 980px !important;
  z-index: 10;
}

.scroll-text {
  display: inline-block;
  position: absolute;
  white-space: nowrap;
  animation: scrollText 10s linear infinite;
  /* 动画效果 */
}

@keyframes scrollText {
  0% {
    transform: translateX(100%);
  }

  100% {
    transform: translateX(-100%);
  }
}
</style>
