<template>
  <div class="zl-box">
    <div class="zl-container-box">
      <div class="top-box">
        <div class="left-box lr-box">
          <!-- <div class = "container-title">
            <a-select
              class="title-select"
              ref="select"
              v-model:value="currentTitleValue"
              @change="handleTitleChange"
            >
              <a-select-option value="2">15212工作面</a-select-option>
              <a-select-option value="1598491318007898113">采煤工作面</a-select-option>
              <a-select-option value="3">掘进工作面</a-select-option>
            </a-select>
          </div> -->
          <div class="analysis-box">
            <div class="pie-group">
              <div class="item-pie">
                <div class="pie">
                  <div class="qiu qiu1">
                    <p>{{ totalEnterNum }}</p>
                  </div>
                </div>
                <div class="pie-data">
                  <span class="data-text">总进风量</span>
                </div>
              </div>
              <div class="item-pie">
                <div class="pie">
                  <div class="qiu qiu2">
                    <p>{{ totalToNum }}</p>
                  </div>
                </div>
                <div class="pie-data">
                  <span class="data-text">总回风量</span>
                </div>
              </div>
            </div>
            <div class="detail-data-group">
              <div class="container-item" v-for="(data, index) in analysisDetailDataList" :key="index">
                <div class="item-icon">
                  <SvgIcon class="icon-style" size="18" :name="data.icon" />
                </div>
                <div class="item-name">{{ data.name }}</div>
                <div v-if="data.code !== 'level' && data.code !== 'resistance'" class="item-value">{{ data.value }} </div>
                <div v-if="data.code == 'level'" class="item-value">
                  <span class="signal-round signal-round-run"></span>
                </div>
                <div v-if="data.code == 'resistance'" class="item-value">{{ totalPa }}</div>
              </div>
            </div>
            <div class="feature-group">
              <div class="feature-item">
                <div class="pie">
                  <Progress
                    type="circle"
                    :width="50"
                    :stroke-color="{
                      '0%': '#FC9C1D',
                      '100%': '#1FF8FB',
                    }"
                    :percent="Number(rate1)"
                  />
                </div>
                <div class="data">可靠度</div>
              </div>
              <div class="feature-item">
                <div class="pie">
                  <Progress
                    type="circle"
                    :width="50"
                    :stroke-color="{
                      '0%': '#A02EFF',
                      '100%': '#1FF8FB',
                    }"
                    :percent="Number(rate2)"
                  />
                </div>
                <div class="data">风阻合理度</div>
              </div>
              <div class="feature-item">
                <div class="pie">
                  <Progress
                    type="circle"
                    :width="50"
                    :stroke-color="{
                      '0%': '#108ee9',
                      '100%': '#1FF8FB',
                    }"
                    :percent="Number(rate3)"
                  />
                </div>
                <div class="data">有效风量率</div>
              </div>
            </div>
          </div>
        </div>
        <div class="right-box lr-box">
          <div class="sensor-box">
            <div class="item-top-title">传感器实时数据</div>
            <BorderBox1 class="table-box">
              <div class="table-container">
                <a-table :columns="sensorColumns" :data-source="sensorDataList" :pagination="false" size="small" />
              </div>
            </BorderBox1>
          </div>
          <div class="warning-box">
            <div class="item-top-title">预警报警信息</div>
            <BorderBox1 class="table-box">
              <div class="table-container">
                <a-table :columns="warningColumns" :data-source="warningDataList" :pagination="false" size="small">
                  <template #bodyCell="{ column, record }">
                    <div v-if="column.dataIndex == 'level'">
                      <span
                        class="signal-round"
                        :class="{
                          'signal-round-red': record['level'] == 1,
                          'signal-round-orange': record['level'] == 2,
                          'signal-round-yellow': record['level'] == 3,
                        }"
                      ></span>
                    </div>
                  </template>
                </a-table>
              </div>
            </BorderBox1>
          </div>
        </div>
      </div>
      <!-- <div class="bottom-box">
        <div class="bottom-left bottom-lr-box">
          <BorderBox11 title="实时网络解算" :color="['#00FFFF']">
            <div class="network-top">
              <div class="network-top-left">
                <div>
                  准确率：
                  <span class="accuracy-rate">95%</span>
                </div>
                <div>
                  迭代误差：
                  <span class="error-rate">0.0941%</span>
                </div>
              </div>
              <div class="network-top-right">
                本次解算时间：
                <span class="time">{{ currentTime }}</span>
              </div>
            </div>
            <div class="table-container">
              <a-table :columns="networkColumns" :data-source="networkDataList" :pagination="false" size="small" />
            </div>
          </BorderBox11>
        </div>
        <div class="bottom-right bottom-lr-box">
          <BorderBox11 title="最大阻力路线">
            <div class="zl-top">
              <div>
                <span class="btn active">1号回风斜井</span>
                <span class="btn">2号回风斜井</span>
              </div>
              <div>
                路线阻力
                <span class="data">{{ totalPa }}</span>
                Pa
              </div>
            </div>
            <div class="zl-container">
              <div class="zl-path-item position1">
                <div class="title">副平硐</div>
              </div>
              <div class="zl-path-item position2">
                <div class="title">5煤组盘区辅运巷</div>
              </div>
              <div class="zl-path-item position3">
                <div class="title">1521辅运顺槽</div>
              </div>
              <div class="zl-path-item position4">
                <div class="title">15212综采工作面</div>
              </div>
              <div class="zl-path-item position5">
                <div class="title">15211辅运顺槽</div>
              </div>
              <div class="zl-path-item position6">
                <div class="title">15212胶运顺槽</div>
              </div>
              <div class="zl-path-item position7">
                <div class="title">15212回风顺槽回风联巷</div>
              </div>
              <div class="zl-path-item position8">
                <div class="title">5煤组盘曲回风大巷</div>
              </div>
              <div class="zl-path-item position9">
                <div class="title">回风斜井联络巷</div>
              </div>
              <div class="zl-path-item position10">
                <div class="title">1盘曲回风斜井</div>
              </div>
            </div>
          </BorderBox11>
        </div>
      </div> -->
    </div>
  </div>
</template>

<script setup lang="ts">
  import { ref, onMounted, onUnmounted } from 'vue';
  import { Icon as SvgIcon } from '/@/components/Icon';
  import { Progress } from 'ant-design-vue';
  import { BorderBox11, BorderBox1 } from '@kjgl77/datav-vue3';
  import { sensorColumns, sensorData, networkColumns, networkData, warningColumns, warningData } from './network.data';
  import dayjs from 'dayjs';
  const currentTitleValue = ref('2'); // 监测工作面id

  let count = 0;
  const sensorDataList = ref<any[]>([]);
  const networkDataList = ref<any[]>([]);
  const warningDataList = ref<any[]>([]);
  const currentTime = ref(dayjs(new Date('2022-10-11 15:03:11').getTime() + count).format('YYYY-MM-DD HH:mm:ss'));

  const totalEnterNum = ref(23855 + '');
  const totalToNum = ref(244436 + '');
  const totalPa = ref(1640 + '');
  const rate1 = ref(95 + '');
  const rate2 = ref(95 + '');
  const rate3 = ref(95 + '');

  const analysisDetailDataList = ref([
    {
      code: '',
      name: '通风巷道规模（m）',
      value: '21000',
      icon: 'path-icon1',
    },
    {
      code: 'level',
      name: '通风难易程度',
      value: '21000',
      icon: 'path-icon2',
    },
    {
      code: 'resistance',
      name: '总阻力',
      value: totalPa.value,
      icon: 'path-icon3',
    },
    {
      code: '',
      name: '等积孔（㎡）',
      value: '11.27',
      icon: 'path-icon4',
    },
  ]);

  let timer: null | NodeJS.Timeout = null;
  function getMonitorData() {
    if (Object.prototype.toString.call(timer) === '[object Null]') {
      timer = setTimeout(async () => {
        sensorDataList.value = sensorData();
        networkDataList.value = networkData();
        warningDataList.value = warningData();
        currentTime.value = dayjs(new Date('2022-10-11 15:03:11').getTime() + ++count * 5000).format('YYYY-MM-DD HH:mm:ss');
        totalEnterNum.value = Number(Math.random() * 200 - 100 + 23855).toFixed(0);
        totalToNum.value = Number(Math.random() * 200 - 100 + 244436).toFixed(0);
        totalPa.value = Number(Math.random() * 50 - 25 + 1640).toFixed(0);
        rate1.value = Number(Math.random() * 4 - 2 + 95).toFixed(0);
        rate2.value = Number(Math.random() * 4 - 2 + 95).toFixed(0);
        rate3.value = Number(Math.random() * 4 - 2 + 95).toFixed(0);
        sensorDataList.value = sensorData();
        networkDataList.value = networkData();
        warningDataList.value = warningData();
        if (timer) {
          timer = null;
        }
        getMonitorData();
      }, 5000);
    }
  }

  // 标题选择
  function handleTitleChange() {
    //
  }

  onMounted(() => {
    getMonitorData();
    // if (document.body.getAttribute('class')?.includes('style-styleTwo')) document.body.removeAttribute('class', 'style-styleTwo');
  });

  onUnmounted(() => {
    if (timer) {
      clearTimeout(timer);
      timer = undefined;
    }
  });
</script>
<style scoped lang="less">
  @ventSpace: zxm;

  .zl-box {
    width: 100%;
    height: calc(100% - 100px);
    color: #fff;
    background-position: center;
    background-size: cover;

    .modal-box {
      position: relative;
      width: 100%;
      height: 100%;
      top: 0;
      left: 0;
    }
  }

  .zl-container-box {
    pointer-events: none;
    margin-top: 30px;

    .top-box {
      display: flex;
      justify-content: space-between;
      height: calc(70% - 20px);
      .lr-box {
        width: 374px;
        margin-top: 10px;
      }

      .left-box {
        // .container-title {
        //   width: 398px;
        //   height: 34px;
        //   top: -30px;
        //   background: url('/@/assets/images/vent/new-home/container-title-bg.png') no-repeat;
        //   background-size: contain;
        //   padding: 0 0 0 180px;
        //   font-size: 20px;
        //   pointer-events: auto;
        //   position: relative;

        //   .title-select {
        //     width: 198px;
        //     position: absolute;
        //     top: 0;
        //     left: 180px;
        //   }
        // }

        .analysis-box {
          position: relative;

          .pie-group {
            display: flex;
            flex-direction: row;
            .item-pie {
              flex: 1;
              padding: 5px;
              display: flex;
              flex-direction: column;
              justify-content: center;
              align-items: center;

              .pie {
                width: 140px;
                height: 80px;
                background: url('/@/assets/images/vent/path/di.png') no-repeat;
                background-size: contain;
                display: flex;
                justify-content: center;

                .qiu1 {
                  background: url('/@/assets/images/vent/path/cicle01.png') no-repeat center;
                }

                .qiu2 {
                  background: url('/@/assets/images/vent/path/cicle04.png') no-repeat center;
                }

                .qiu {
                  position: relative;
                  width: 60px;
                  height: 60px;
                  background-size: 100%;
                  display: flex;
                  justify-content: center;
                  padding-top: 18px;

                  &::before {
                    content: '';
                    display: block;
                    width: 60px;
                    height: 60px;
                    position: absolute;
                    left: 50%;
                    top: 50%;
                    transform: translate(-50%, -50%);
                    border-radius: 50%;
                    border: 3px solid rgba(255, 255, 255, 0.5);
                    animation: scale 2s linear infinite;
                  }
                }
              }

              .pie-data {
                width: 140px;
                height: 20px;
                display: flex;
                justify-content: center;
                position: relative;
                background: url('/@/assets/images/vent/path/pie-line.png');

                .data-text {
                  display: block;
                  position: absolute;
                  top: -8px;
                }
              }
            }
          }

          .detail-data-group {
            width: 100%;
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-top: 15px;

            .container-item {
              width: 307px;
              height: 63px;
              display: flex;
              position: relative;
              background: url('/@/assets/images/vent/plane-bottom.png') no-repeat;
              background-size: auto;
              background-position: bottom;
              padding: 10px 30px;

              &::before {
                content: '';
                display: block;
                width: 100%;
                height: 5px;
                position: absolute;
                top: 62px;
                left: 0;
                background-color: #73f4ff66;
                backdrop-filter: blur(5px);
              }

              .item-icon {
                width: 60px;
                height: 45px;
                background: url('/@/assets/images/vent/plane-icon-bg.png') no-repeat;
                background-size: cover;

                .icon-style {
                  margin: 10px 0 0 18px;
                }
              }

              .item-name {
                width: 180px;
                line-height: 60px;
                margin-left: 5px;
                text-align: left;
              }

              .item-value {
                position: relative;
                height: 26px;
                line-height: 24px;
                margin: 15px 0;
                text-align: center;
                width: 80px;
                border: 1px solid #00f5fe;
                border-radius: 13px;
                background: linear-gradient(to right, #00f5fe44, #0090ff44);

                &::before {
                  width: 6px;
                  height: 6px;
                  content: '';
                  position: absolute;
                  left: -3px;
                  top: 8px;
                  background: #ffa500;
                  border-radius: 3px;
                }
              }
            }
          }

          .feature-group {
            display: flex;
            flex-direction: row;
            padding: 20px;
            margin-top: 15px;

            .feature-item {
              width: 108px;
              height: 120px;
              background: url('/@/assets/images/vent/path/path-feature-bg.png');
              display: flex;
              flex-direction: column;
              // justify-content: center;

              .pie {
                display: flex;
                justify-content: center;
              }

              .data {
                margin-top: 15px;
                font-size: 12px;
                scale: 0.9;
                text-align: center;
              }
            }
          }
        }
      }

      .right-box {
        display: flex;
        flex-direction: column;

        .sensor-box,
        .warning-box {
          position: relative;

          // min-height: 220px;
          // max-height: 250px;
          .table-box {
            height: 280px;
            position: relative;

            .table-container {
              margin: 25px 20px 20px;
              height: 250px;
              position: absolute;
            }
          }
        }

        .sensor-box {
          .item-top-title {
            &::after {
              left: 110px;
            }

            &::before {
              left: 265px;
            }
          }
        }

        .warning-box {
          margin-top: 10px;
        }
      }
    }

    .bottom-box {
      width: 100%;
      height: calc(30% - 20px);
      display: flex;
      justify-content: space-between;
      margin-top: 20px;

      .bottom-lr-box {
        flex: 1;
        display: flex;
        justify-content: center;
      }

      .bottom-left {
        margin-right: 10px;

        .network-top {
          display: flex;
          flex-direction: row;
          justify-content: space-between;
          position: relative;
          top: 55px;
          padding: 0 30px;

          .network-top-left {
            display: flex;

            div {
              margin-right: 20px;
            }

            span {
              font-family: 'douyuFont';
              font-size: 15px;
            }

            .accuracy-rate {
              color: #ffa500;
            }

            .error-rate {
              color: #00f5fe;
            }
          }

          .time {
            color: #949494;
          }
        }

        .table-container {
          height: 150px;
          margin-top: 55px;
          margin-left: 15px;
          margin-right: 10px;
        }
      }

      .bottom-right {
        margin-left: 10px;

        .zl-top {
          width: calc(100% - 30px);
          padding: 0 20px;
          display: flex;
          flex-direction: row;
          justify-content: space-between;
          position: relative;
          top: 35px;
          z-index: 99;
          margin: 10px;
          border-bottom: 1px solid #00f5fe88;

          .btn {
            padding: 3px 10px;
            border-top: 1px solid #c6c6c6;
            background-image: linear-gradient(#c2c2c2aa, #b3b3b388 20%, #5a5a5a88);
            cursor: pointer;
            margin-right: 5px;

            &:hover,
            &:active {
              border-top: 1px solid #00f5fe;
              background-image: linear-gradient(#00f5feaa, #1adce288 20%, #00848988);
            }
          }

          .active {
            border-top: 1px solid #00f5fe;
            background-image: linear-gradient(#00f5feaa, #1adce288 20%, #00848988);
          }

          .data {
            font-family: 'douyuFont';
            color: #ffa500;
            font-size: 15px;
          }
        }

        .zl-container {
          width: 100%;
          height: 100%;
          margin: 0 15px;
          background: url('/@/assets/images/vent/path/zl-bg1.png') no-repeat;
          background-size: 920px 190px;
          position: relative;

          &::after {
            content: '';
            display: block;
            position: absolute;
            width: 100%;
            height: 100%;
            top: 85px;
            background: url('/@/assets/images/vent/path/zl-bg2.png') no-repeat;
            background-size: 920px 100px;
          }
        }

        .zl-path-item {
          height: 67px;
          background: url('/@/assets/images/vent/path/zl-path-item-bg.png') no-repeat;
          background-size: auto;
          background-position: center bottom;
          position: absolute;
          scale: 0.9;

          .title {
            position: relative;
            top: -20px;
            text-align: center;
            font-size: 12px;
            background: #00f5fe33;
            padding: 3px 5px;
            backdrop-filter: blur(5px);
          }
        }

        .position10 {
          top: 130px;
          left: 0px;
        }

        .position9 {
          top: 52px;
          left: 100px;
        }

        .position8 {
          top: 132px;
          left: 220px;
        }

        .position7 {
          top: 128px;
          left: 420px;
        }

        .position6 {
          top: 60px;
          left: 320px;
        }

        .position5 {
          top: 120px;
          left: 580px;
        }

        .position4 {
          top: 123px;
          left: 690px;
        }

        .position3 {
          top: 103px;
          left: 830px;
        }

        .position2 {
          top: 90px;
          left: 740px;
        }

        .position1 {
          top: 80px;
          left: 535px;
        }
      }
    }
  }

  .item-top-title {
    width: 374px;
    height: 32px;
    text-align: center;
    line-height: 34px;
    font-size: 15px;
    font-weight: 600;
    color: #fafafa;
    position: absolute;
    padding-top: 0px;
    top: -9px;
    z-index: 999;

    &::before {
      content: '';
      display: block;
      width: 40px;
      height: 1px;
      position: absolute;
      left: 255px;
      top: 50%;
      transform: translateY(-50%);
      -webkit-transform: translate(-50%, -50%);
      background-color: #00d4fe88;
    }

    &::after {
      content: '';
      display: block;
      width: 40px;
      height: 1px;
      position: absolute;
      left: 120px;
      top: 50%;
      transform: translateY(-50%);
      -webkit-transform: translate(-50%, -50%);
      background-color: #00d4fe88;
    }
  }

  .signal-round {
    display: inline-block;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    position: relative;
    top: -3px;

    &::after {
      display: block;
      content: '';
      position: absolute;
      width: 8px;
      height: 8px;
      top: -2px;
      left: -2px;
      border-radius: 50%;
      background-color: #daffc044;
      box-shadow: 0 0 1px 1px #c6ff7722;
    }
  }

  .signal-round-run {
    background-color: #67fc00;

    &::after {
      background-color: #daffc044;
      box-shadow: 0 0 1px 1px #c6ff7722;
    }
  }

  .signal-round-red {
    background-color: #ff3823;

    &::after {
      background-color: #ff382344;
      box-shadow: 0 0 1px 1px #ff382333;
    }
  }

  .signal-round-orange {
    background-color: #ff9b17;

    &::after {
      background-color: #ff9b1744;
      box-shadow: 0 0 1px 1px #ff9b1733;
    }
  }

  .signal-round-yellow {
    background-color: #ffff00;

    &::after {
      background-color: #ffff0044;
      box-shadow: 0 0 1px 1px #ffff0033;
    }
  }

  .table-container {
    overflow-y: auto;
    overflow-x: hidden;
    pointer-events: auto;

    &::-webkit-scrollbar {
      width: 8px;
      height: 8px;
      background-color: #f5f5f500;
    }

    &::-webkit-scrollbar-track {
      background-color: #ffffff33;
      border-radius: 10px;
    }

    &::-webkit-scrollbar-thumb {
      background-color: #cccccc44;
      border-radius: 10px;
    }
  }

  @keyframes scale {
    0% {
      transform: translate(-50%, -50%) scale(0.9);
      opacity: 1;
    }

    100% {
      transform: translate(-50%, -50%) scale(1.5);
      opacity: 0;
    }
  }

  :deep(.@{ventSpace}-progress-text) {
    color: #fff !important;
  }

  :deep(.@{ventSpace}-table-thead) {
    background-color: transparent !important;

    & > tr {
      border: 1px solid #00f5fe !important;
    }

    & > tr > th {
      // border: none !important;
      color: #00f5fe !important;
      border-top: 1px solid #00f5fe !important;
      border-bottom: 1px solid #00f5fe !important;
      border-left: none !important;
      border-right: none !important;
      font-size: 13px;
    }
  }

  :deep(.@{ventSpace}-table-tbody) {
    & > tr > td {
      font-size: 13px;
    }
  }

  :deep(.@{ventSpace}-table-small) {
    border: none !important;
  }

  :deep(.@{ventSpace}-layout) {
    background: transparent !important;
  }
</style>
