<template>
  <transition
    appear
    name="animate__animated animate__move"
    enter-active-class="animate__slideInLeft"
    leave-active-class="animate__slideOutLeft"
  >
    <div class="widget-StatisticalSecurity">
      <div class="head">
        <div class="title">
          <div class="icon"></div>
          <span class="site-info">安全统计</span>
        </div>
      </div>
      <div class="content-info">
        <!---->
        <div class="statisticalNumber">
          <div class="sta-item" v-for="(item, index) of staList" :key="item.name">
            <div class="sta-value" :class="'stav' + index">{{ item.value }}个</div>
            <div class="sta-name">{{ item.name }}</div>
          </div>
        </div>
        <div class="riskLevel">
          <div class="title">
            <div class="icon"></div>
            <span class="item-name">危险源等级</span>
          </div>
          <!-- <div class="hierarchy">
            <div class="subhierarchy sh0">一级</div>
            <div class="subhierarchy sh1">二级</div>
            <div class="subhierarchy sh2">三级</div>
            <div class="subhierarchy sh3">四级</div>
          </div> -->
          <div class="hierarchyChart">
            <RiskLevelChart :chartData="chartData" />
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script lang="ts">
import { Vue, Component, Prop, Watch } from 'vue-property-decorator'
import RiskLevelChart from '../../../components/ComprehensiveChart/riskLevelChart.vue'
import { getRequestResult, getSafetyCountData } from '../../../apis'
//安全统计
@Component({
  name: 'StatisticalSecurity',
  components: { RiskLevelChart }
})
export default class StatisticalSecurity extends Vue {
  staList = []
  chartData = {}
  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.staList = [
    //   { name: '施工任务数', value: res.find((e) => e.indexCode == projectCode + '-' + 135).indexValue },
    //   { name: '危险源辨识数', value: res.find((e) => e.indexCode == projectCode + '-' + 136).indexValue },
    //   { name: '高风险作业数', value: res.find((e) => e.indexCode == projectCode + '-' + 137).indexValue }
    // ]
    let dataIndex = Array.from({ length: 6 }, (value, key) => key + 140),
      xData = [],
      highRisk = [],
      levelOne = [],
      levelTwo = [],
      levelThree = [],
      levelFour = []
    // dataIndex.forEach((item) => {
    //   highRisk.push(0)
    //   xData.push(res.find((e) => e.indexCode == projectCode + '-' + item + '-' + '1').indexName.split('月')[0] + '月')
    //   levelOne.push(res.find((e) => e.indexCode == projectCode + '-' + item + '-' + '1').indexValue)
    //   levelTwo.push(res.find((e) => e.indexCode == projectCode + '-' + item + '-' + '2').indexValue)
    //   levelThree.push(res.find((e) => e.indexCode == projectCode + '-' + item + '-' + '3').indexValue)
    //   levelFour.push(res.find((e) => e.indexCode == projectCode + '-' + item + '-' + '4').indexValue)
    // })
    const interfaceResult = await getSafetyCountData({ code: this.projectCode })
    const { gfxzysNum, sgrwNum, wxybsNum, hiddenEcharts } = interfaceResult.result
    this.staList = [
      { name: '施工任务数', value: sgrwNum },
      { name: '危险源辨识数', value: wxybsNum },
      { name: '高风险作业数', value: gfxzysNum }
    ]
    const { seriesDatas, xaxis } = hiddenEcharts
    xData = xaxis.map((item) => this.getMonth(item))
    seriesDatas.forEach((item) => {
      if (item.name == '高风险作业') highRisk = item.seriesData
      if (item.name == '四级') levelFour = item.seriesData
      if (item.name == '三级') levelThree = item.seriesData
      if (item.name == '二级') levelTwo = item.seriesData
      if (item.name == '一级') levelOne = item.seriesData
    })
    this.chartData = { xData, highRisk, levelOne, levelTwo, levelThree, levelFour }
  }
  getMonth(item) {
    let month = item.split('-')[1]
    month = month[0] == '0' ? month.slice(1) : month
    return month + '月'
  }
}
</script>

<style lang="scss" scoped>
.animate__slideInLeft,
.animate__slideOutLeft {
  animation-duration: 3s; //动画持续时间
  animation-delay: 0s; //动画延迟时间
}
.widget-StatisticalSecurity {
  z-index: 2;
  //position
  bottom: 0.052083rem /* 10/192 */;
  margin-left: $size20 /* 20/192 */;
  position: absolute;
  //size
  height: calc(100% - 3.265625rem /* 627/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;
      }
    }
  }
  @mixin positionCenter() {
    display: flex;
    align-items: center;
  }
  .content-info {
    width: 100%;
    height: calc(100% - 0.166667rem);
    display: inline-block;
    font-family: Source Han Sans CN;
    background: linear-gradient(0deg, rgba(14, 167, 255, 0.16) 0%, rgba(14, 167, 255, 0.02) 100%);
    .title {
      width: 100%;
      display: flex;
      .icon {
        height: 0.072917rem /* 14/192 */;
        width: 0.078125rem /* 15/192 */;
        margin: 0 0.046875rem /* 9/192 */;
        background: url('~@/views/groupPage/images/三角.png') no-repeat center center;
        background-size: 100% 100%;
      }
      .item-name {
        font-family: Source Han Sans CN;
        color: #0ea7ff;
        font-size: 0.072917rem /* 14/192 */;
        font-weight: 500;
      }
    }
    .statisticalNumber {
      width: 100%;
      height: 0.354167rem /* 68/192 */;
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      background: rgba(6, 34, 57, 0.9);
      .sta-item {
        display: flex;
        flex-flow: column;
        align-items: center;
        justify-content: space-evenly;
        font-family: Source Han Sans CN;
        color: #ffffff;
        .sta-value {
          font-family: Source Han Sans CN-HEAVY;
          font-size: 0.083333rem /* 16/192 */;
          font-weight: bold;
          height: 0.083333rem /* 16/192 */;
        }
        .sta-name {
          font-size: 0.072917rem /* 14/192 */;
          font-weight: 400;
        }
        .stav0 {
          background: linear-gradient(0deg, #1890ff 0%, #00e8fd 100%);
          background-clip: text;
          -webkit-text-fill-color: transparent;
        }
        .stav1 {
          background: linear-gradient(0deg, #f66f14 0%, #ffd34b 100%);
          background-clip: text;
          -webkit-text-fill-color: transparent;
        }
        .stav2 {
          background: linear-gradient(0deg, #04dfe7 0%, #f4db4e 100%);
          background-clip: text;
          -webkit-text-fill-color: transparent;
        }
      }
    }
    .riskLevel {
      margin-top: 0.052083rem /* 10/192 */;
      height: calc(100% - 0.40625rem /* 78/192 */);
      width: 100%;
      @mixin contentCenter() {
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .hierarchy {
        height: 0.125rem /* 24/192 */;
        margin: 0.026042rem /* 5/192 */ 0;
        width: 100%;
        display: flex;
        .subhierarchy {
          height: 100%;
          font-size: 0.072917rem /* 14/192 */;
          font-family: Source Han Sans CN;
          font-weight: 500;
          color: #fefefe;
          @include contentCenter();
        }
        .sh0 {
          width: 0.385417rem /* 74/192 */;
          background-color: #ed2727;
        }
        .sh1 {
          width: 0.364583rem /* 70/192 */;
          background-color: #d6791f;
        }
        .sh2 {
          width: 0.520833rem /* 100/192 */;
          background-color: #efa82d;
        }
        .sh3 {
          width: calc(100% - 1.270833rem /* 244/192 */);
          background-color: #d4c953;
        }
      }
      .hierarchyChart {
        width: 100%;
        // height: calc(100% - 0.25rem /* 48/192 */);
        height: calc(100% - 0.072917rem /* 14/192 */);
      }
    }
  }
}
</style>