<template>
  <div class="inspection">
    <layout>
      <template #left>
        <div class="left_spection">
          <HeadlineTag value="出入口列表"></HeadlineTag>
          <div class="box_arch_point">
            <div class="point_box" style="margin-top: 10px;margin-left: 15px;">
              <el-input v-model="input" placeholder="按出入口名称搜索" />
            </div>
            <access :resultData="leftData.DeviceList"></access>
            <!-- <div style="height: calc(100% - 160px);">
              <Empty></Empty>
            </div>
            <div class="center_in">
              <pagination :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize"
                layout="total, prev, pager, next" @pagination="getList" />
            </div> -->
          </div>
        </div>
      </template>
      <template #right>
        <div class="right_spection">
          <div class="operation_spection">
            <HeadlineTag type="right" value="监控设备"></HeadlineTag>
            <div class="box_arch" style="margin-right: 15px;margin-top: 10px;height: calc(100% - 55px);">
              <dv-border-box-1>
                <div class="box_monitoring">
                  <div class="flex_spection box_tion_zx">
                    <div class="line_blue">
                      <div class="blue_dot"></div>
                    </div>
                    <div class="monit_title">空闲车位</div>
                    <span class="monit_num">{{ leftData.Online }}</span>
                  </div>
                  <div class="camera">
                    <div class="entry-box">
                      <div class="entry-box-item">
                        <div class="item-center-line"></div>
                        <div class="item-center-pie"></div>
                      </div>
                    </div>
                    <div class="img_camera">
                      <svg class="camera_box_icon" aria-hidden="true">
                        <defs>
                          <linearGradient id="myGradientil" x1="0%" y1="100%" x2="0%" y2="0%">
                            <stop offset="0%" stop-color="rgb(46, 139, 221)" />
                            <stop offset="100%" stop-color="rgb(4, 223, 247)" />
                          </linearGradient>
                        </defs>
                        <use xlink:href="#icon-parkingSpot" fill="url('#myGradientil')" />
                      </svg>
                    </div>
                  </div>
                  <div class="flex_spection box_tion_lx">
                    <div class="line_green">
                      <div class="green_dot"></div>
                    </div>
                    <div class="monit_title">已占车位</div>
                    <span class="monit_num1">{{ leftData.Offline }}</span>
                  </div>
                </div>
              </dv-border-box-1>
            </div>
          </div>
          <!-- <div class="flex_spection">
        <HeadlineTag type="right" value="实时巡检"></HeadlineTag>
        <div class="box_arch">
          <dv-scroll-board :config="config" style="width:97%;height:calc(100% - 10px);margin-top: 10px;" />
        </div>
      </div> -->
          <div class="flex_spection">
            <HeadlineTag type="right" value="设备出入统计排名(Top5)"></HeadlineTag>
            <div class="box_arch">
              <div ref="chartRouting" style="width: 100%;height: 100%;"></div>
            </div>
          </div>
          <div class="flex_spection">
            <HeadlineTag type="right" value="出入人员统计"></HeadlineTag>
            <div class="box_arch">
              <Personnel :resultData="leftData"></Personnel>
            </div>
          </div>
        </div>
      </template>
    </layout>
  </div>
</template>

<script setup>
import { getAccess } from "@/api/system/passageway"
import layout from "@/components/layout_/index.vue";
import HeadlineTag from '@/components/HeadlineTag'
import Personnel from './Personnel.vue'
import access from './access.vue'
import Empty from '@/components/Empty'
import * as echarts from 'echarts'
const total = ref(0);
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
});
const input = ref('')
const config = ref({
  headerBGC: '#10285c',
  oddRowBGC: '#10285c7f',
  evenRowBGC: '#10285c00',
  header: ['名称', '位置', '列3'],
  data: [
    ['行1列1', '行1列2', '行1列3'],
    ['行2列1', '行2列2', '行2列3'],
    ['行3列1', '行3列2', '行3列3'],
    ['行4列1', '行4列2', '行4列3'],
    ['行5列1', '行5列2', '行5列3'],
    ['行6列1', '行6列2', '行6列3'],
    ['行7列1', '行7列2', '行7列3'],
    ['行8列1', '行8列2', '行8列3'],
    ['行9列1', '行9列2', '行9列3'],
    ['行10列1', '行10列2', '行10列3']
  ]
})

/** 查询列表 */
function getList() {
};
const chartRouting = ref(null);
let chartInstance = null;
// 初始化图表
const initChart = () => {
  // var data = [91, 82, 73, 61, 54, 46];
  var data = [];
  // var yAxis = ['北京市', '天津市', '河北省', '吉林省', '辽宁省', '内蒙古']
  var yAxis = []
  chartInstance = echarts.init(chartRouting.value);
  chartInstance.setOption({
    tooltip: {
      textStyle: {
        fontSize: 16
      },
      formatter: function (res) {
        return `${res.name} : ${res.data}万人`;
      },
      textStyle: {
        color: '#fafafa',
      },
      borderColor: 'transparent',
      backgroundColor: 'rgba(0, 0, 0, 0.5)',
      extraCssText: 'backdrop-filter: blur(6px);',
    },
    legend: {
      selectedMode: false,
      show: false
    },
    grid: {
      left: '2%',
      right: '5%',
      bottom: '0%',
      top: 5,
      containLabel: true
    },
    xAxis: [{
      type: 'value',
      show: false
    }],
    yAxis: [{
      splitLine: {
        show: false
      },
      axisLine: { // y轴
        show: false
      },
      type: 'category',
      inverse: true, /// 柱状图顺序
      axisTick: {
        show: false
      },
      data: yAxis,
      axisLabel: {
        show: true,
        textStyle: {
          color: '#ffffff'
        },
        formatter: (res, index) => {
          var num = 0;
          num = index + 1;
          if (index === 0) {
            return '{no1|' + 'TOP' + num + '}' + '{data|' + res + '}';
          } else if (index === 1) {
            return '{no2|' + 'TOP' + num + '}' + '{data|' + res + '}';
          } else if (index === 2) {
            return '{no3|' + 'TOP' + num + '}' + '{data|' + res + '}';
          } else if (index === 3) {
            return '{no4|' + 'TOP' + num + '}' + '{data|' + res + '}';
          } else if (index === 4) {
            return '{no5|' + 'TOP' + num + '}' + '{data|' + res + '}';
          } else if (index === 5) {
            return '{no6|' + 'TOP' + num + '}' + '{data|' + res + '}';
          }
          return res;
        },
        rich: {
          no1: {
            color: '#EF5525',
            fontSize: 14
          },
          data: {
            color: '#fff',
            fontSize: 14
          },
          no2: {
            color: '#EFAF25',
            fontSize: 14
          },
          no3: {
            color: '#D0EF25',
            fontSize: 14
          },
          no4: {
            color: '#26EFC2',
            fontSize: 14
          },
          no5: {
            color: '#2BE4FF',
            fontSize: 14
          },
          no6: {
            color: '#2BE4FF',
            fontSize: 14
          }
        }

      }
    }],
    series: [{
      name: '标准化',
      type: 'bar',
      barWidth: 14, // 柱子宽度
      label: {
        show: true,
        position: 'right', // 位置
        color: '#fff',
        fontSize: 14,
        distance: 20 // 距离
      }, // 柱子上方的数值
      itemStyle: {
        barBorderRadius: [20, 20, 20, 20],
        color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
          '#4C67EB', '#00F6FF'
        ].map((color, offset) => ({
          color,
          offset
        }))) // 渐变
      },
      data: data
    }]
  }
  );
};

// 生命周期
onMounted(() => {
  intervalId.value = setInterval(getAccessData, 10000);
  getAccessData()
  initChart()
});
onUnmounted(() => {
  clearInterval(intervalId.value);
})
const intervalId = ref(null)
const leftData = ref({})
function getAccessData() {
  getAccess().then((res) => {
    if (res.code == 200) {
      leftData.value = res.data
    }
  })
}

watch(() => leftData.value, (newVal) => {
  if (chartInstance) {
    let result = newVal.DeviceRanking.map(person => person.DeviceName)
    var firstFive = result.slice(0, 5)
    let result1 = newVal.DeviceRanking.map(person => person.Value)
    var firstFive1 = result1.slice(0, 5)
    chartInstance.setOption({
      yAxis: [{
        data: firstFive,
      }],
      series: [{
        name: '标准化',
        data: firstFive1,
      }],
    })
  }
}, { deep: true, immediate: true } // 开启深度监听
)
// 窗口自适应
window.addEventListener('resize', () => {
  chartInstance?.resize();
});
</script>

<style scoped lang="scss">
.inspection {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.left_spection {
  position: absolute;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.right_spection {
  position: absolute;
  right: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.box_arch_point {
  height: calc(100% - 40px);
}

.operation_spection {
  height: 30%;
  color: #fff;
}

.flex_spection {
  flex: 1;
  color: #fff;
}

.box_arch {
  display: flex;
  align-items: center;
  height: calc(100% - 40px);
}

.image_tubbiness {
  position: relative;
  flex: none;
  width: 200px;
  height: 100%;
  background: url("@/assets/images/tubbiness.png");
  background-size: 80% 80%;
  background-position: center center;
  background-repeat: no-repeat;

  .work_num {
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    text-align: center;
    color: rgb(84, 218, 250);
    font-size: 20px;

    span {
      font-size: 14px;
      color: rgb(158, 174, 195);
    }
  }

  .work_title {
    position: absolute;
    bottom: 36px;
    left: 0px;
    right: 0px;
    text-align: center;
  }
}

.right_content {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;

  .work_week {
    display: flex;
    align-items: center;
    font-size: 22px;
    font-weight: bold;
    color: #fff;

    span {
      padding-right: 10px;
      font-size: 16px;
      color: rgb(214, 218, 222);
    }
  }
}

.color_line_xj {
  width: 6px;
  height: 6px;
  margin-right: 10px;
}

.box_tion_zx {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.box_tion_lx {
  padding-right: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.box_monitoring {
  display: flex;
  align-items: center;
  height: 100%;
}

.line_blue {
  position: relative;
  height: 5px;
  width: 70%;
  background-color: rgba(12, 208, 67, .5);
  margin-bottom: 10px;
}

.blue_dot {
  position: absolute;
  left: 5px;
  top: 0;
  bottom: 0;
  width: 20px;
  border-left: 5px solid rgb(5, 26, 52);
  border-right: 5px solid rgb(5, 26, 52);
  background-color: rgba(12, 208, 67, 1);
}

.line_green {
  position: relative;
  height: 5px;
  width: 70%;
  background-color: rgba(254, 33, 44, .5);
  margin-bottom: 10px;
}

.green_dot {
  position: absolute;
  left: 5px;
  top: 0;
  bottom: 0;
  width: 20px;
  border-left: 5px solid rgb(5, 26, 52);
  border-right: 5px solid rgb(5, 26, 52);
  background-color: rgba(254, 33, 44, 1);
}

.img_camera {
  position: absolute;
  width: 120px;
  height: 120px;
  top: calc(50% - 60px);
  left: calc(50% - 60px);
  border-radius: 50%;
  border: 1px solid rgb(15, 39, 66);
  box-shadow: inset 0px 0px 20px 2px rgb(42, 147, 223);
}

.camera_box_icon {
  width: 70px;
  height: 70px;
  position: absolute;
  top: calc(50% - 35px);
  left: calc(50% - 35px);
  vertical-align: -2px;
}

.camera {
  width: 190px;
  height: 100%;
  display: flex;
  position: relative;

  .entry-box {
    width: 100%;
    height: 100%;
    object-fit: fill;
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .entry-box-item {
    width: 100%;
    height: 180px;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    background: radial-gradient(circle,
        rgba(51, 149, 233, 0) 100px,
        rgba(51, 149, 233, 0) 100px);

    .item-center-line {
      width: 180px;
      height: 180px;
      background-color: transparent;
      border-top: 3px solid rgb(22, 110, 191);
      border-bottom: 3px solid rgb(22, 110, 191);
      border-radius: 50%;
      box-sizing: border-box;
      position: absolute;
      top: calc(50% - 90px);
      left: calc(50% - 90px);
      animation: rotate 8s infinite linear;
    }

    .item-center-pie {
      width: 150px;
      height: 150px;
      background-color: transparent;
      border-top: 2px solid rgb(22, 110, 191);
      border-bottom: 2px solid rgb(22, 110, 191);
      border-radius: 50%;
      box-sizing: border-box;
      position: absolute;
      top: calc(50% - 75px);
      left: calc(50% - 75px);
      animation: rotate1 8s infinite linear;
    }
  }
}

/* 定义中间球体顺时针转动 */
@keyframes rotate {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

/* 定义中间圆逆时针转动 */
@keyframes rotate1 {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(-360deg);
  }
}

.monit_title {
  font-size: 16px;
  background-image: -webkit-linear-gradient(bottom, rgb(120, 173, 221), rgb(229, 232, 236));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  padding: 6px 0px;
}

.monit_num {
  font-size: 30px;
  color: rgba(12, 208, 67, 1);
  font-weight: bold;
}

.monit_num1 {
  font-size: 30px;
  color: rgba(254, 33, 44, 1);
  font-weight: bold;
}
</style>
<style lang="scss" scoped>
.point_box :deep(.el-input__wrapper) {
  background-color: transparent !important;
  box-shadow: 0 0 0 1px rgb(58, 86, 117) inset !important;
}

.point_box :deep(.el-input__wrapper.is-focus) {
  box-shadow: 0 0 0 1px #409EFF inset !important;
}

.point_box :deep(.el-input__inner) {
  color: #ffffff !important;
}
</style>