<!-- 安全风险预警处置 -->
<template>
  <div class="warningComponents">
    <title-page-img-components :propsData="propsData"></title-page-img-components>
    <div class="map-max-big-box">
      <!--北校区-->
      <div class="map-one-max-big-box">
        <div class="position-text-max-box">
          <div>
            <p>预警处置总数:</p>
            <p>{{deptData.handleTotal}}</p>
          </div>
          <div>
            <p>昨日处置总数:</p>
            <p>{{deptData.yesterdayHandleTotal}}</p>
          </div>
          <div>
            <p>今日处置总数:</p>
            <p>{{deptData.todayHandleTotal}}</p>
          </div>
          <div>
            <p>环比增长:</p>
            <p>{{deptData.rate}}</p>
          </div>
        </div>
        <!--星期-->
        <!--<div class="date-max-box">-->
        <!--<div :class="dayIndex==index?'checkColor':''" v-for="(item,index) in timeList" :key="index" @click="dayButton(index)">-->
        <!--<p>{{item.label}}</p>-->
        <!--<p>{{item.name}}</p>-->
        <!--</div>-->
        <!--</div>-->
        <div class="for-position-dept-max-box">
          <div class="for-position-dept-box"
               v-for="(item,index) in deptData.warningHandleSubs" :key="index">
            <div class="for-position-name-box-one" v-if="item.handleTotal>0">
              <p>{{item.deptSortName}}</p>
              <p>今日预警处置：{{item.handleTotal}}</p>
              <img src="@/assets/ZDimages/img_bg_xtred@1x.png">
            </div>
            <div class="for-position-name-box" v-if="item.handleTotal == 0">
              <p>{{item.deptSortName}}</p>
              <img src="@/assets/ZDimages/img_bg_xtblu@1x.png">
            </div>
            <p class="for-position-address-img-one" v-if="item.handleTotal>0">{{item.handleTotal}}</p>
            <p class="for-position-address-img" v-if="item.handleTotal == 0">{{item.handleTotal}}</p>
          </div>
        </div>
      </div>
      <!--<p style="position: absolute;bottom:0;right:0;color:red;">{{deptData.schoolName}}</p>-->
    </div>
  </div>
</template>
<script>
  import {
    reportReportBigDataWarningHandle
  } from '@/api/index'
  import titlePageImgComponents from '@/components/titlePageImgComponents.vue'

  export default {
    name: 'warningComponents',
    components: {
      titlePageImgComponents
    },
    data() {
      return {
        propsData: {
          title: '安全风险预警处置'
        },
        dateData: new Date().getDay(),
        dayIndex: null,
        timeList: [],
        //获取数据
        deptList: [],
        //展示数据
        deptData: {},
        deptListIndex: 0,
        eChartsTimer: null
      }
    },
    created() {

    },
    mounted() {
      this.initialize()
    },
    methods: {
      timedRefresh() {
        let self = this
        self.getData()
        //定时动画
        window.clearInterval(self.eChartsTimer)
        self.eChartsTimer = setInterval(function() {
          self.deptListIndex++
          if (self.deptList[self.deptListIndex]) {
            self.$set(self, 'deptData', self.deptList[self.deptListIndex])
          } else {
            self.getData()
          }
        }, 1000 * 30)
      },
      //日期初始化
      initialize() {
        let thisWeekDates = this.getThisWeekDates()
        let timeList = []
        let day = new Date().getDay()
        day = day == 0 ? 7 : day
        this.$set(this, 'dayIndex', day - 1)
        for (let i = 0; i < thisWeekDates.length; i++) {
          timeList.push({
            label: i + 1,
            name: i == 0 ? 'Mon' : (i == 1 ? 'Tue' : (i == 2 ? 'Wed' : (i == 3 ? 'Thur' : (i == 4 ? 'Fri' : (i == 5 ? 'Sat' : (i == 6 ? 'Sun' : '')))))),
            value: thisWeekDates[i]
          })
        }
        this.$set(this, 'timeList', timeList)
        this.timedRefresh()
      },
      getThisWeekDates() {
        const today = new Date()
        const dayOfWeek = today.getDay()
        const firstDayOfWeek = new Date(today)
        if (dayOfWeek === 0) {
          firstDayOfWeek.setDate(firstDayOfWeek.getDate() - 6)
        } else {
          firstDayOfWeek.setDate(firstDayOfWeek.getDate() - dayOfWeek + 1)
        }
        const dates = []
        for (let i = 0; i < 7; i++) {
          let time = new Date(firstDayOfWeek.getTime() + i * 24 * 60 * 60 * 1000).toLocaleDateString().split('/')
          if (time[1] < 10) {
            time[1] = '0' + time[1]
          }
          if (time[2] < 10) {
            time[2] = '0' + time[2]
          }
          dates.push(time.join('-'))
          // dates.push(new Date(firstDayOfWeek.getTime() + i * 24 * 60 * 60 * 1000).toLocaleDateString().split("/") .join("-") );
        }
        return dates
      },
      //日期点击
      dayButton(index) {
        if (index != this.dayIndex) {
          this.$set(this, 'dayIndex', index)
        }
      },
      //获取数据
      getData() {
        reportReportBigDataWarningHandle({ date: this.timeList[this.dayIndex].value }).then(response => {
          let list = [];
          for(let i=0;i<response.data.length;i++){
            let obj = {
              handleTotal:response.data[i].handleTotal,
              rate:response.data[i].rate,
              schoolName:response.data[i].schoolName,
              todayHandleTotal:response.data[i].todayHandleTotal,
              yesterdayHandleTotal:response.data[i].yesterdayHandleTotal,
              warningHandleSubs:[],
            }
            for(let o=0;o<response.data[i].warningHandleSubs.length;o++){
              if(o<18){
                obj.warningHandleSubs.push(response.data[i].warningHandleSubs[o])
              }
            }
            list.push(obj)
          }
          this.$set(this, 'deptList', list)
          this.$set(this, 'deptListIndex', 0)
          this.$set(this, 'deptData', this.deptList[this.deptListIndex])
          // this.$set(this, 'deptList', response.data)
          // this.$set(this, 'deptListIndex', 0)
          // this.$set(this, 'deptData', this.deptList[this.deptListIndex])
        })
      }
    },
    beforeDestroy() {
      //清除定时器
      window.clearInterval(this.eChartsTimer)
    },
    destroyed() {
      //清除定时器
      window.clearInterval(this.eChartsTimer)
    }
  }
</script>
<style scoped lang="scss">
  .warningComponents {
    width: 934px;
    margin: 16px 30px;
    height: 530px;
    .map-max-big-box {
      position: relative;
      .map-one-max-big-box {
        height: 468px;
        width: 933px;
        background: no-repeat;
        background-image: url("../../../assets/ZDimages/mapBackImg.png");
        background-size: 100%;
        position: relative;
      }
      .position-text-max-box {
        position: absolute;
        top: 10px;
        display: flex;
        div:nth-child(1), div:nth-child(2), div:nth-child(3) {
          margin-bottom: 40px;
        }
        div {
          width: 202px;
          height: 50px;
          background: no-repeat;
          background-image: url("../../../assets/ZDimages/img_yjczbg@1x.png");
          background-size: 100%;
          display: flex;
          margin-left: 25px;
          p:nth-child(1) {
            color: #fff;
            line-height: 52px;
            font-size: 18px;
            font-weight: 700;
            margin-left: 20px;
            flex: 1;
          }
          p:nth-child(2) {
            color: #FF8400;
            line-height: 52px;
            font-size: 18px;
            font-weight: 700;
            margin-right: 15px;
          }
        }
      }
      .date-max-box {
        position: absolute;
        top: 15px;
        right: 30px;
        display: flex;
        .checkColor {
          p {

            color: #00FFFF !important;
          }
        }
        div {
          cursor: pointer;
          width: 60px;
          height: 60px;
          margin-right: 10px;
          padding: 5px 0;
          p {
            font-size: 18px;
            color: #fff;
            line-height: 25px;
            text-align: center;
          }
        }
      }
      .for-position-dept-max-box {
        position: relative;
        .for-position-dept-box {
          display: inline-block;
          position: absolute;
          .for-position-name-box-one {
            border-radius: 8px;
            display: inline-block;
            min-width: 150px;
            height: 54px;
            border: 1px solid #D80707;
            box-shadow: inset 0px 0px 10px 0px #D80707;
            p {
              text-align: center;
              color: #fff;
              font-size: 16px;
              line-height: 16px;
              height: 16px;
              margin: 6px 0 0;
            }
            img {
              display: block;
              width: 120px;
              height: 4px;
              margin: 0 auto;
            }
          }
          .for-position-name-box {
            border-radius: 8px;
            display: inline-block;
            min-width: 130px;
            height: 30px;
            border: 1px solid #00E6FF;
            box-shadow: inset 0px 0px 10px 0px #047581;
            p {
              text-align: center;
              color: #fff;
              font-size: 16px;
              line-height: 16px;
              height: 16px;
              margin: 6px 0 0;
            }
            img {
              display: block;
              width: 120px;
              height: 4px;
              margin: 0 auto;
            }
          }
          .for-position-address-img-one {
            height: 50px;
            width: 50px;
            margin: 4px auto 0;
            background: no-repeat;
            background-image: url("../../../assets/ZDimages/address_1.png");
            background-size: 100%;
            color: #D80707;
            font-size: 16px;
            line-height: 31px;
            text-align: center;
          }
          .for-position-address-img {
            height: 50px;
            width: 50px;
            margin: 4px auto 0;
            background: no-repeat;
            background-image: url("../../../assets/ZDimages/address_2.png");
            /*background-image: url("../../../assets/ZDimages/address_1.png");*/
            background-size: 100%;
            color: #00E6FF;
            font-size: 16px;
            line-height: 31px;
            text-align: center;
          }
        }
        .for-position-dept-box:nth-child(1) {
          top: 100px;
          left: 30px;
        }
        .for-position-dept-box:nth-child(2) {
          top: 100px;
          left: 280px;
        }
        .for-position-dept-box:nth-child(3) {
          top: 100px;
          left: 530px;
        }
        .for-position-dept-box:nth-child(4) {
          top: 100px;
          left: 780px;
        }
        .for-position-dept-box:nth-child(5) {
          top: 165px;
          left: 153px;
        }
        .for-position-dept-box:nth-child(6) {
          top: 165px;
          left: 403px;
        }
        .for-position-dept-box:nth-child(7) {
          top: 165px;
          left: 653px;
        }
        .for-position-dept-box:nth-child(8) {
          top: 230px;
          left: 30px;
        }
        .for-position-dept-box:nth-child(9) {
          top: 230px;
          left: 280px;
        }
        .for-position-dept-box:nth-child(10) {
          top: 230px;
          left: 530px;
        }
        .for-position-dept-box:nth-child(11) {
          top: 230px;
          left: 780px;
        }
        .for-position-dept-box:nth-child(12) {
          top: 295px;
          left: 153px;
        }
        .for-position-dept-box:nth-child(13) {
          top: 295px;
          left: 403px;
        }
        .for-position-dept-box:nth-child(14) {
          top: 295px;
          left: 653px;
        }
        .for-position-dept-box:nth-child(15) {
          top: 360px;
          left: 30px;
        }
        .for-position-dept-box:nth-child(16) {
          top: 360px;
          left: 280px;
        }
        .for-position-dept-box:nth-child(17) {
          top: 360px;
          left: 530px;
        }
        .for-position-dept-box:nth-child(18) {
          top: 360px;
          left: 780px;
        }
      }
    }
  }
</style>
