<template>
  <transition
    appear
    name="animate__animated animate__move"
    enter-active-class="animate__slideInRight"
    leave-active-class="animate__slideOutRight"
  >
    <div class="widget-MonthlyStatistics">
      <div class="head">
        <div class="title">
          <div class="icon"></div>
          <span class="site-info">月度投资结算统计</span>
          <!-- <div class="dateRange">{{ beginTime }}～{{ endTime }}</div> -->
          <div class="dateRange">{{ currentTime }}</div>
        </div>
      </div>
      <div class="content-info">
        <!--  -->
        <div class="totalSettlement-content">
          <div class="icon-content">
            <img :src="require('@/views/groupPage/images/模块图标/统计分析/本月图标.png')" />
          </div>
          <div class="amount-content">
            <span>{{ totalMoney }}万元</span>
            <span>本月结算合计</span>
          </div>
        </div>
        <!--  -->
        <div class="barchart-content">
          <ComSplitBarChart :chartData="chartData" />
        </div>
        <!--  -->
        <div class="piechart-content">
          <div class="title">
            <div class="icon"></div>
            <span class="item-name">各类型费用饼图统计</span>
          </div>
          <div class="pc-chartContent">
            <ComExpenseTypeChart :chartData="chartData" />
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script lang="ts">
import moment from 'moment'
import { Vue, Component, Prop, Watch } from 'vue-property-decorator'
import { getImgFiles, getEpcQbsDetailPage } from '../../../apis'
import request from '@/utils/request'
import ComSplitBarChart from '@/views/groupPage/components/BarChart/ComSplitBarChart.vue'
import ComExpenseTypeChart from '@/views/groupPage/components/PieChart/ComExpenseTypeChart.vue'
const legendNameList = [
  { key: 'lx_cost', name: '建设期利息' },
  { key: 'one_cost', name: '一类费用' },
  { key: 'two_cost', name: '二类费用' },
  { key: 'rest_cost', name: '存量' },
  { key: 'yunwei_cost', name: '运维' },
  { key: 'unique_cost', name: '专项费用' },
  { key: 'ready_cost', name: '预备费用' }
]
//月度投资结算统计
@Component({
  name: 'MonthlyStatistics',
  components: { ComSplitBarChart, ComExpenseTypeChart }
})
export default class MonthlyStatistics extends Vue {
  @Prop({ type: Array, default: () => {} }) dataInfo!: any
  beginTime = moment(new Date().setDate(new Date().getDate() - 6)).format('YYYY.MM.DD')
  endTime = moment(new Date()).format('YYYY.MM.DD')
  currentTime = moment(new Date()).format('YYYY年MM月')

  chartData = null
  totalMoney = 0
  get projectCode() {
    return this.$store.state.bigScreen.currentProjectCode
  }
  @Watch('dataInfo')
  onChangMehod() {
    this.getData()
  }
  getData() {
    const investInfo = this.dataInfo[0]
    let infoData = [],
      amount = 0
    Object.keys(investInfo).forEach((key) => {
      if (key.includes('_month')) {
        infoData.push({
          name: (legendNameList.find((i) => i.key == key.substring(0, key.lastIndexOf('_'))) || {}).name,
          value: investInfo[key]
        })
        amount += +investInfo[key]
      }
    })
    this.totalMoney = amount
    this.chartData = infoData
  }
}
</script>

<style lang='scss' scoped>
.animate__slideInRight,
.animate__slideOutRight {
  animation-duration: 3s; //动画持续时间
  animation-delay: 0s; //动画延迟时间
}
.widget-MonthlyStatistics {
  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;
        margin-right: 0.052083rem; /* 10/192 */
      }
    }
  }
  .content-info {
    width: 100%;
    height: calc(100% - 0.166667rem);
    font-family: Source Han Sans CN;
    background: linear-gradient(0deg, rgba(14, 167, 255, 0.16) 0%, rgba(14, 167, 255, 0.02) 100%);
    padding: 0.052083rem /* 10/192 */;
    @mixin center() {
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .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 {
        font-family: Source Han Sans CN;
        color: #0ea7ff;
        font-size: 0.072917rem /* 14/192 */;
        font-weight: 500;
      }
    }
    .totalSettlement-content {
      width: 100%;
      height: 0.59375rem /* 114/192 */;
      background: rgba(6, 34, 57, 0.9);
      display: flex;
      .icon-content {
        height: 100%;
        width: 50%;
        @include center();
        img {
          height: 0.427083rem /* 82/192 */;
          width: 0.338542rem /* 65/192 */;
        }
      }
      .amount-content {
        height: 100%;
        width: 50%;
        @include center();
        flex-flow: column;
        margin-left: -0.15625rem /* 30/192 */;
        & > span:first-child {
          font-size: 0.125rem /* 24/192 */;
          font-family: Alimama ShuHeiTi;
          font-weight: bold;
          font-style: italic;
          color: #ffffff;
          background: linear-gradient(0deg, #1483ff 0%, #ebd674 100%);
          background-clip: text;
          -webkit-text-fill-color: transparent;
          margin-bottom: 0.067708rem /* 13/192 */;
        }
        span {
          display: inline-block;
          width: 100%;
          font-size: 0.09375rem /* 18/192 */;
          font-family: Source Han Sans CN;
          font-weight: 400;
          color: #ffffff;
        }
      }
    }
    .barchart-content {
      margin-top: 0.104167rem /* 20/192 */;
      width: 100%;
      height: calc(100% - 2.416667rem /* 464/192 */);
      overflow: auto;
    }
    .piechart-content {
      margin-top: 0.052083rem /* 10/192 */;
      width: 100%;
      height: 1.666667rem /* 320/192 */;
      .pc-chartContent {
        width: 100%;
        height: calc(100% - 0.072917rem /* 14/192 */);
      }
    }
  }
}
</style>