<template>
  <div class="videoDaysDetail">
    <el-dialog
      title="录像详情"
      :visible.sync="isShow"
      width="1200px"
      :destroy-on-close="true"
    >
      <el-descriptions title="基础信息" :column="3">
        <el-descriptions-item label="通道名称">{{
          data.channelName
        }}</el-descriptions-item>
        <el-descriptions-item label="监控主机">{{
          data.hostName
        }}</el-descriptions-item>
        <el-descriptions-item label="IP地址">{{
          data.channelIp
        }}</el-descriptions-item>
        <!--        <el-descriptions-item label="组织机构" >{{data.orgName}}</el-descriptions-item>-->
        <!--        <el-descriptions-item label="上报时间" >{{data.updateTime}}</el-descriptions-item>-->
        <!--        <el-descriptions-item label="监控主机" >{{data.equipmentName}}</el-descriptions-item>-->
        <!--        <el-descriptions-item label="摄像头" >{{data.channelName}}</el-descriptions-item>-->
        <!--        <el-descriptions-item label="通道号" >{{data.channelCode}}</el-descriptions-item>-->
        <!--        <el-descriptions-item label="计划存储天数" >{{data.planDays}}</el-descriptions-item>-->
        <!--        <el-descriptions-item label="实际存储天数" >{{data.realDays}}</el-descriptions-item>-->
        <!--        <el-descriptions-item label="计划录像开始时间" >{{data.planStartTime}}</el-descriptions-item>-->
        <!--        <el-descriptions-item label="计划录像结束时间" >{{data.planEndTime}}</el-descriptions-item>-->
      </el-descriptions>
      <el-descriptions
        title="录像质量"
        :column="3"
        v-if="data.quality == null || data.quality.state == null"
      >
        <el-descriptions-item label="检测结果"> 未知 </el-descriptions-item>
      </el-descriptions>
      <div v-else>
        <el-descriptions title="录像质量" :column="3">
          <el-descriptions-item label="检测结果">{{
            data.quality.state == 1 ? "异常" : "正常"
          }}</el-descriptions-item>
          <el-descriptions-item label="更新时间">{{
            dayjs(data.quality.updateTime).format("YYYY年M月D日H时m分")
          }}</el-descriptions-item>
        </el-descriptions>
        <el-descriptions :column="1" v-if="data.quality.quality == 1">
          <el-descriptions-item label="诊断截图">
            <div>
              <ul class="legend-box">
                <li>
                  <el-tag
                    size="small"
                    type="warning"
                    v-if="data.quality.signalLost"
                    >视频信号</el-tag
                  >
                </li>
                <li>
                  <el-tag
                    size="small"
                    type="warning"
                    v-if="data.quality.occlude"
                    >遮挡</el-tag
                  >
                </li>
                <li>
                  <el-tag size="small" type="warning" v-if="data.quality.blurry"
                    >模糊</el-tag
                  >
                </li>
                <li>
                  <el-tag
                    size="small"
                    type="warning"
                    v-if="data.quality.colorCast"
                    >偏色</el-tag
                  >
                </li>
                <li>
                  <el-tag
                    size="small"
                    type="warning"
                    v-if="data.quality.snowflake"
                    >雪花</el-tag
                  >
                </li>
                <li>
                  <el-tag size="small" type="warning" v-if="data.quality.stripe"
                    >条纹</el-tag
                  >
                </li>
                <li>
                  <el-tag
                    size="small"
                    type="warning"
                    v-if="data.quality.contrast"
                    >对比度</el-tag
                  >
                </li>
                <li>
                  <el-tag
                    size="small"
                    type="warning"
                    v-if="data.quality.brightness"
                    >亮度</el-tag
                  >
                </li>
              </ul>
              <div
                style="
                  display: block;
                  width: 300px;
                  max-height: 300px;
                  margin-top: 20px;
                "
              >
                -->
                <el-image
                  :src="data.quality.image"
                  :preview-src-list="[data.quality.image]"
                >
                  <div slot="error" class="image-slot">
                    <i class="el-icon-picture-outline"></i>
                  </div>
                </el-image>
              </div>
            </div>
          </el-descriptions-item>
        </el-descriptions>
      </div>

      <el-descriptions
        title="录像完整性"
        :column="3"
        v-if="data.integrity == null || data.integrity.state == null"
      >
        <el-descriptions-item label="检测结果"> 未知 </el-descriptions-item>
      </el-descriptions>
      <div v-else>
        <el-descriptions title="录像完整性" :column="3">
          <el-descriptions-item label="检测结果">{{
            data.integrity.state == 1 ? "异常" : "正常"
          }}</el-descriptions-item>
          <el-descriptions-item label="录像日期">{{
            dayjs(data.integrity.recordDate).format("YYYY年M月D日")
          }}</el-descriptions-item>
          <el-descriptions-item label="丢失时长">{{
            data.integrity.loseDuration == 0
              ? "未丢失"
              : data.integrity.loseDuration + "分钟"
          }}</el-descriptions-item>
          <el-descriptions-item label="更新时间">{{
            dayjs(data.integrity.updateTime).format("YYYY年M月D日H时m分")
          }}</el-descriptions-item>
        </el-descriptions>
        <el-descriptions :column="1">
          <el-descriptions-item label="丢失时段">
            <!--          <time-line></time-line>-->
            <ul class="legend-box">
              <li>
                <i class="legend" style="background-color: #00b2ff"></i>
                <span>计划时长</span>
              </li>
              <li>
                <i class="legend" style="background-color: green"></i>
                <span>有录像</span>
              </li>
              <li>
                <i class="legend" style="background-color: red"></i>
                <span>无录像</span>
              </li>
              <li>
                <i class="legend" style="background-color: #aaa"></i>
                <span>未知</span>
              </li>
            </ul>
          </el-descriptions-item>
        </el-descriptions>

        <div class="time-line-box">
          <!--        <div style="width: 100%;height: 20px;background-color: red; "></div>-->
          <progress-bar
            :timeCell="timeCells"
            :videoData="playVideoObj"
            :startTime="start_timestamp"
          ></progress-bar>
        </div>
        <div class="time-line">
          <el-timeline :reverse="false">
            <el-timeline-item
              v-for="(activity, index) in data.loseDateList"
              :key="index"
              color="rgb(208 230 253)"
              size="large"
              type="primary"
            >
              <div class="time">
                <div>
                  <span class="year">
                    {{ activity.month }}
                  </span>
                </div>
                <!-- <div class="day">{{ activity.time.substring(0, 4) }}年</div> -->
              </div>
              <div class="ml10">
                <el-tag
                  v-for="(date, number) in activity.lostDates"
                  :key="number"
                >
                  <div>
                    {{ date }}
                    <div class="reTip"></div>
                  </div>
                </el-tag>
              </div>
            </el-timeline-item>
          </el-timeline>
        </div>
      </div>
      <el-descriptions
        title="录像存储"
        :column="3"
        v-if="data.storage == null || data.storage.planDays == null"
      >
        <el-descriptions-item label="存储状态"> 未知 </el-descriptions-item>
      </el-descriptions>
      <div v-else>
        <el-descriptions title="录像存储" :column="3">
          <el-descriptions-item label="计划存储"
            >{{ data.storage.planDays }}天</el-descriptions-item
          >
          <el-descriptions-item label="实际存储"
            >{{ data.storage.realDays }}天</el-descriptions-item
          >
          <el-descriptions-item label="最早录像存储日期"
            >dayjs(data.storage.earliestTime).format("YYYY年M月D日")</el-descriptions-item
          >
        </el-descriptions>
        <el-descriptions :column="1">
          <el-descriptions-item label="存储状态">
            <!--          <time-line></time-line>-->
            <ul class="legend-box">
              <li>
                <i class="legend" style="background-color: green"></i>
                <span>录像完整</span>
              </li>
              <li>
                <i class="legend" style="background-color: orange"></i>
                <span>部分丢失</span>
              </li>
              <li>
                <i class="legend" style="background-color: red"></i>
                <span>全部丢失</span>
              </li>
              <li>
                <i class="legend" style="background-color: #cbd5e0"></i>
                <span>计划录像天数</span>
              </li>
            </ul>
          </el-descriptions-item>
        </el-descriptions>

        <div class="calendar-box">
          <Calendar
            :startDate="data.storage.earliestTime"
            :full="data.storage.fullDates"
            :paritialLoss="data.storage.partialLossDates"
            :allLoss="data.storage.allLostDates"
          ></Calendar>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="onHide">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import TimeLine from "./timeLine.vue";
import ProgressBar from "./ProgressBar";
import Calendar from "./Calendar.vue";
import dayjs from "dayjs";
import { detail } from "@/api/iot/videoDiagnosis.js";

export default {
  components: { TimeLine, ProgressBar, Calendar },
  data() {
    return {
      src: "https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg",
      isShow: false,
      data: {},
      id: null,
      playVideoObj: {}, //选中的正在播放的录像
      timeCells: [], //录像时间块
      start_timestamp: new Date().getTime() - 5 * 60 * 60 * 1000, //刻度轴开始时间
    };
  },
  methods: {
    dayjs,
    async show(hostCode, channelCode) {
      this.data = await detail(hostCode, channelCode);
      this.isShow = true;
    },
    onHide() {
      this.isShow = false;
    },
  },
};
</script>

<style lang="scss">
.videoDaysDetail {
  .block {
    display: block;
  }

  .time-line {
    margin-top: 10px;
    margin-left: 80px;
  }

  .list-title {
    font-size: 16px;
    font-family: PingFangSC-Medium, PingFang SC;
    font-weight: 500;
    color: #181b1e;
  }

  .list-company {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #2991ff;
    margin-top: 15px;
    margin-bottom: 15px;
  }

  .list-desc {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #596878;
  }

  .el-tag--small {
    margin-bottom: 10px;
  }

  .reTip {
    display: block;
    background: #f00;
    border-radius: 50%;
    width: 4px;
    height: 4px;
    top: -21px;
    right: -26px;
    position: relative;
    z-index: 4;
  }

  //左侧时间
  .time {
    color: rgb(181 215 251);
    position: absolute;
    left: -35px;
    top: -1px;

    .year {
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #20354a;
    }

    .day {
      font-size: 14px;
      font-family: PingFangSC-Regular, PingFang SC;
      font-weight: 400;
      color: #596878;
      text-align: center;
      margin-top: 10px;
    }
  }

  .legend-box {
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    align-items: center;
    > li {
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      align-items: center;
      margin-right: 20px;
      i {
        margin-right: 5px;
      }
    }
  }
  .time-line-box {
    width: 100%;
    padding: 0 80px 50px 80px;
  }
  .calendar-box {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    //>div{
    //  width: 30%;
    //}
  }
  .el-calendar-table .el-calendar-day {
    padding: 5px;
    height: auto;
  }
  .el-calendar__button-group {
    display: none;
  }
  .legend {
    display: block;
    width: 14px;
    height: 10px;
    margin-right: 5px;
  }
}
</style>
