<template>
  <transition
    appear
    name="animate__animated animate__move"
    enter-active-class="animate__slideInRight"
    leave-active-class="animate__slideOutRight"
  >
    <div class="widget-RiskAndSecurity">
      <div class="head">
        <div class="title">
          <div class="icon"></div>
          <span class="site-info">近期隐患与安全</span>
          <div class="dateRange">{{ beginTime }}～{{ endTime }}</div>
        </div>
      </div>
      <div class="content-info">
        <!---->
        <div class="securityContent">
          <div class="title">
            <div class="icon"></div>
            <span class="item-name">安全</span>
          </div>
          <!---->
          <div class="sc-text">
            <div class="sctItem">
              <div class="sctItem-content">
                <span class="sctItem-title"></span>
                {{ weeklySafetyReport }}
              </div>
            </div>
            <!-- <div class="sctItem">
              <div class="sctItem-content">
                <span class="sctItem-title">2、</span>
                宜昌建设部组织各标段质量员、资料员学习质量验收
              </div>
            </div> -->
          </div>
          <!---->
          <div class="rectificationStatistic">
            <div class="title">
              <!-- <div class="icon"></div> -->
              <span class="item-name">近7天隐患上报和隐患整改数量统计</span>
            </div>
            <div class="rsChart">
              <StatisticalReportingChart :type="'rectify'" :chartData="chartData" />
            </div>
          </div>
        </div>
        <!---->
        <div class="riskContent">
          <div class="title">
            <div class="icon"></div>
            <span class="item-name">隐患</span>
          </div>
          <!---->
          <div class="rc-text">
            <div class="rctItem">
              <div class="rctItem-content" v-for="(item, index) in rcList" :key="index">
                <span class="rctItem-title">{{ index + 1 }}、</span>
                {{ item }}
              </div>
            </div>
            <!-- <div class="rctItem">
              <div class="rctItem-content">
                <span class="rctItem-title">3、</span>
                本周三峡发展董事长毛三军莅临宜昌两网二期项目， 重点检查了二网项目各施工现场的安全生产工作，指出要
                加强人车分离、安全用电、人员安全防护等安全问题整改
              </div>
            </div> -->
          </div>
          <!---->
          <!-- <div class="rc-sta">
            <div class="title">
              <span class="item-name">近1个月、半年危险源和高风险作业数量统计</span>
            </div>
            <div class="rc-sta-content">
              <div class="rscItem" v-for="(item, index) of rcStaList" :key="item.level">
                <div class="rscI-level" :class="'rscII' + index">{{ item.level }}</div>
                <div class="rscI-citem">
                  <div class="citem-value">{{ item.lastMonth }}</div>
                  <div class="citem-title">近1个月</div>
                </div>
                <div class="rscI-citem">
                  <div class="citem-value">{{ item.past6Months }}</div>
                  <div class="citem-title">近半年</div>
                </div>
              </div>
            </div>
          </div> -->
        </div>
      </div>
    </div>
  </transition>
</template>

<script lang="ts">
import moment from 'moment'
import { Vue, Component, Prop, Watch } from 'vue-property-decorator'
import StatisticalReportingChart from '../../../components/ComprehensiveChart/statisticalReportingChart.vue'
import { getRequestResult, getDangerCheckSevenDayData, getWeekCountData } from '../../../apis'
//近期隐患与安全
@Component({
  name: 'RiskAndSecurity',
  components: { StatisticalReportingChart }
})
export default class RiskAndSecurity extends Vue {
  beginTime = moment(new Date().setDate(new Date().getDate() - 6)).format('YYYY.MM.DD')
  endTime = moment(new Date()).format('YYYY.MM.DD')
  // beginTime = ''
  // endTime = ''
  weeklySafetyReport = ''
  chartData = {}
  rcStaList = [
    { level: '一级', lastMonth: 22, past6Months: 50 },
    { level: '二级', lastMonth: 22, past6Months: 50 },
    { level: '三级', lastMonth: 22, past6Months: 50 },
    { level: '四级', lastMonth: 22, past6Months: 50 },
    { level: '高风险作业', lastMonth: 22, past6Months: 50 }
  ]
  rcList = []
  get projectCode() {
    return this.$store.state.bigScreen.currentProjectCode
  }
  @Watch('projectCode', { immediate: true })
  onChangMehod() {
    this.getPageData()
  }
  async getPageData() {
    let data = { blockCode: 'ycepclist' }
    let projectCode = this.projectCode
    //获取全部数据
    const result = await getRequestResult(data)
    let res = (result as any).filter((item) => item.indexCode.indexOf(projectCode + '-') != -1)
    res = res.map((item) => {
      Object.keys(item).forEach((val) => (item[val] = item[val] || ''))
      return { ...item }
    })
    // this.weeklySafetyReport = res.find((e) => e.indexCode == projectCode + '-' + 148).indexValue
    let dataIndex = Array.from({ length: 7 }, (value, key) => key + 1), //1-7
      xData = [],
      report = [],
      rectification = []
    // dataIndex.forEach((item) => {
    //   xData.push(res.find((e) => e.indexCode == projectCode + '-' + '149' + '-' + item).indexName.split('上')[0])
    //   report.push(res.find((e) => e.indexCode == projectCode + '-' + '149' + '-' + item).indexValue)
    //   rectification.push(res.find((e) => e.indexCode == projectCode + '-' + '150' + '-' + item).indexValue)
    // })
    // this.chartData = {
    //   xData,
    //   report,
    //   rectification
    // }
    this.rcList = res.find((e) => e.indexCode == projectCode + '-' + 151).indexValue.split('/')

    const interfaceResult = await getDangerCheckSevenDayData({ code: this.projectCode })
    console.log('近7天隐患上报和隐患整改数量统计', interfaceResult)
    const { xaxis, seriesDatas } = interfaceResult.result || {}
    xData = xaxis
    seriesDatas.forEach((item) => {
      if (item.name == '上报') report = item.seriesData
      if (item.name == '整改') rectification = item.seriesData
    })
    this.chartData = {
      xData,
      report,
      rectification
    }
    //
    const WeekCountData = await getWeekCountData({ code: this.projectCode })
    if (!WeekCountData.result) return
    const { safety_content, start_date, end_date } = WeekCountData.result || {}
    this.weeklySafetyReport = safety_content
    // this.beginTime = start_date.split(' ')[0]
    // this.endTime = end_date.split(' ')[0]
  }
}
</script>

<style lang='scss' scoped>
.animate__slideInRight,
.animate__slideOutRight {
  animation-duration: 3s; //动画持续时间
  animation-delay: 0s; //动画延迟时间
}
.widget-RiskAndSecurity {
  z-index: 2;
  //position
  bottom: $size10 /* 10/192 */;
  margin-right: $size20 /* 20/192 */;
  right: 0;
  position: absolute;
  //size
  height: calc(100% - 0.557292rem /* 107/192 */);
  width: 2.083333rem /* 400/192 */;
  .head {
    height: 0.166667rem /* 32/192 */;
    width: 100%;
    background: linear-gradient(-90deg, rgba(43, 167, 255, 0.2) 0%, rgba(43, 167, 255, 0.08) 100%);
    font-family: Source Han Sans CN-HEAVY;
    .title {
      width: 100%;
      height: 100%;
      display: flex;
      font-weight: 400;
      align-items: center;
      .icon {
        height: 0.166667rem /* 32/192 */;
        width: 0.34375rem /* 66/192 */;
        background: url('~@/views/groupPage/images/模块图标/统计分析/近期隐患与安全.png') no-repeat center center;
        background-size: 100% 100%;
      }
      span {
        flex: 1;
        font-weight: bold;
        font-size: 0.083333rem /* 16/192 */;
        color: #ffffff;
        padding: 0.041667rem /* 8/192 */;
        background: linear-gradient(0deg, #9bd2fa 0%, #ffffff 100%);
        background-clip: text;
        -webkit-text-fill-color: transparent;
      }
      .dateRange {
        height: 0.0625rem /* 12/192 */;
        font-size: 0.072917rem /* 14/192 */;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #ffffff;
      }
    }
  }
  .content-info {
    width: 100%;
    height: calc(100% - 0.166667rem);
    display: inline-block;
    background: linear-gradient(0deg, rgba(14, 167, 255, 0.16) 0%, rgba(14, 167, 255, 0.02) 100%);
    font-family: Source Han Sans CN;
    .title {
      width: 100%;
      display: flex;
      align-items: center;
      .icon {
        height: 0.072917rem /* 14/192 */;
        width: 0.078125rem /* 15/192 */;
        margin-right: 0.046875rem /* 9/192 */;
        background: url('~@/views/groupPage/images/三角.png') no-repeat center center;
        background-size: 100% 100%;
      }
      .item-name,
      .item-type {
        font-family: Source Han Sans CN;
        color: #0ea7ff;
        font-size: 0.072917rem /* 14/192 */;
        font-weight: 500;
      }
      .item-type {
        color: #89c3ec !important;
      }
      .symbol {
        margin-left: 0.052083rem /* 10/192 */;
        width: 0.208333rem /* 40/192 */;
        height: 0.104167rem /* 20/192 */;
        font-size: 0.072917rem /* 14/192 */;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #ffffff;
        background: linear-gradient(90deg, #2188d3, #9c2bec);
        border-radius: 2px;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }
    .securityContent {
      margin-top: 0.088542rem /* 17/192 */;
      width: 100%;
      height: 2.34375rem /* 450/192 */;
      .sc-text {
        margin-top: 0.072917rem /* 14/192 */;
        height: 0.729167rem /* 140/192 */;
        width: 100%;
        background: #062239;
        overflow: auto;
        .sctItem {
          width: 100%;
          padding: 0.052083rem /* 10/192 */;
          color: #feffff;
          font-family: Source Han Sans CN;
          font-size: 0.072917rem /* 14/192 */;
          .sctItem-content {
            line-height: 0.114583rem /* 22/192 */;
            word-break: break-all;
            .sctItem-title {
              color: #17aaff;
            }
          }
        }
      }
      .rectificationStatistic {
        margin-top: 0.104167rem /* 20/192 */;
        height: calc(100% - 0.90625rem /* 174/192 */);
        width: 100%;
        .rsChart {
          height: calc(100% - 0.072917rem /* 14/192 */);
          width: 100%;
        }
      }
    }
    .riskContent {
      margin-top: 0.15625rem /* 30/192 */;
      width: 100%;
      // height: calc(100% - 2.588542rem /* 497/192 */);
      height: calc(100% - 1.489583rem /* 286/192 */);
      .rc-text {
        margin-top: 0.052083rem /* 10/192 */;
        width: 100%;
        height: calc(100% - 1.223958rem /* 235/192 */);
        background: #052742;
        overflow: auto;
        .rctItem {
          width: 100%;
          padding: 0.052083rem /* 10/192 */;
          color: #feffff;
          font-family: Source Han Sans CN;
          font-size: 0.072917rem /* 14/192 */;
          .rctItem-content {
            line-height: 0.114583rem /* 22/192 */;
            .rctItem-title {
              color: #17aaff;
            }
          }
        }
      }
      @mixin contentCenter() {
        display: flex;
        align-items: center;
        flex-flow: column;
        justify-content: space-evenly;
      }
      .rc-sta {
        margin-top: 0.052083rem /* 10/192 */;
        width: 100%;
        height: 1.046875rem /* 201/192 */;
        .rc-sta-content {
          margin: 0.052083rem /* 10/192 */ 0;
          height: calc(100% - 0.177083rem /* 34/192 */);
          width: 100%;
          display: grid;
          grid-template-columns: repeat(5, 1fr);
          grid-template-rows: 100%;
          .rscItem {
            @include contentCenter();
            position: relative;
            .rscI-level {
              font-size: 0.072917rem /* 14/192 */;
              font-family: Source Han Sans CN-HEAVY;
              font-weight: bold;
              color: #ff3132;
            }
            .rscII0 {
              color: #ff3132;
            }
            .rscII1 {
              color: #e5811f;
            }
            .rscII2 {
              color: #d89a2d;
            }
            .rscII3 {
              color: #c6b558;
            }
            .rscII4 {
              color: #2ba7ff;
            }
            .rscI-citem {
              @include contentCenter();
              justify-content: space-between;
              height: 0.197917rem /* 38/192 */;
              .citem-value {
                font-size: 0.072917rem /* 14/192 */;
                font-family: Source Han Sans CN-HEAVY;
                font-weight: bold;
                color: #ffffff;
              }
              .citem-title {
                font-size: 0.072917rem /* 14/192 */;
                font-family: Source Han Sans CN;
                font-weight: 400;
                color: #84bde5;
              }
            }
          }
          .rscItem:not(:last-child):after {
            content: '';
            height: 100%;
            width: 0.005208rem /* 1/192 */;
            background: rgba(255, 255, 255, 0.2);
            position: absolute;
            margin: auto 0;
            top: 0;
            bottom: 0;
            right: 0;
          }
        }
      }
    }
  }
}
</style>