<template>
  <transition
    appear
    name="animate__animated"
    enter-active-class="animate__slideInLeft"
    leave-active-class="animate__slideOutLeft"
  >
    <div class="widget-ContractInfo" v-if="show">
      <div class="head">
        <div class="title">
          <div class="icon"></div>
          <span class="site-info">合同情况</span>
        </div>
      </div>
      <div class="content-info">
        <div class="content-item">
          <div class="title">
            <div class="icon"></div>
            <span class="item-name">建管项目：</span>
            <span class="item-info">项目数量{{ ProjectTotal }}个，累计完成产值{{ TotalValue }}亿</span>
          </div>
          <div class="content">
            <div class="chart-container">
              <div class="chart-title">完成占比：{{ complishPercent }}%</div>
              <ComThreeDimensionsChart v-on="{ fontSize }" :chartData="staList" />
              <!-- 底座背景 -->
              <div class="bg"></div>
            </div>
            <div class="dataInfo">
              <div
                class="data-item"
                v-for="(item, index) of staList"
                :key="item.name"
                :style="index === 0 ? 'background: rgba(11, 122, 192,0.16)' : 'background: rgba(8, 178, 114,0.16)'"
              >
                <div class="pointSymbol" :style="index === 0 ? 'background:#2BA7FF' : 'background:#13D28A'"></div>
                <div class="data-title">{{ item.name }}</div>
                <div class="data-value">{{ item.value }}{{ item.unit }}</div>
              </div>
            </div>
          </div>
        </div>
        <div class="content-item">
          <div class="title">
            <div class="icon"></div>
            <span class="item-name">EPC项目：</span>
            <span class="item-info">总投资{{ EPCInvestNum }}亿</span>
          </div>
          <div class="content epc">
            <ComBatteryChart :chartData="EPCData" v-on="{ fontSize }" />
          </div>
        </div>
        <div class="content-item">
          <div class="title">
            <div class="icon"></div>
            <span class="item-name">近6个月数据（万元）</span>
            <span class="item-info"></span>
          </div>
          <div class="content">
            <ComLineChart :chartData="latestData" v-on="{ fontSize }" />
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
import { getRequestResult } from '@/views/groupPage/apis'
import { setNullAndUndefinedEmpty, fontSize as fs } from '@/views/groupPage/util'
import ComThreeDimensionsChart from '@/views/groupPage/components/OthersChart/ComThreeDimensionsChart.vue'
import ComBatteryChart from '@/views/groupPage/components/BatteryChart/ComBatteryChart.vue'
import ComLineChart from '@/views/groupPage/components/LineChart/ComLineChart.vue'
export default {
  name: 'ContractInfo', //合同情况
  components: {
    ComThreeDimensionsChart,
    ComBatteryChart,
    ComLineChart
  },
  props: {
    show: {}
  },
  data() {
    return {
      staList: [
        { name: '本年投资计划', value: 0, unit: '亿' },
        { name: '本年累计完成产值', value: 0, unit: '亿' }
      ],
      //建管项目
      ProjectTotal: 0, //项目总数
      TotalValue: 0, //累计完成产值
      complishPercent: 0, //完成占比
      //EPC
      EPCInvestNum: 0, //EPC项目投资数
      EPCData: {
        spending: 0,
        income: 0,
        profits: 0
      }, //EPC收支信息
      latestData: {
        income: [],
        spending: [],
        profits: []
      }
    }
  },
  watch: {
    show: {
      handler(n, o) {}
    }
  },
  computed: {
    setNoNull() {
      return setNullAndUndefinedEmpty
    },
    fontSize() {
      return fs
    }
  },
  mounted() {
    this.getPageData()
  },
  methods: {
    roundFun(value, n) {
      return Math.round(value * Math.pow(10, n)) / Math.pow(10, n)
    },
    getPageData() {
      let data = { blockCode: 'ycepclist' }
      //获取全部数据
      getRequestResult(data).then((res) => {
        res = res.map((item) => {
          return {
            ...item,
            indexValue:
              item.unit === '万元'
                ? this.roundFun(this.setNoNull(item.indexValue) / 10000, 2)
                : this.setNoNull(item.indexValue)
          }
        })
        //获取项目数据
        this.ProjectTotal = res.filter((item) => item.indexCode === 'A1')[0].indexValue
        this.TotalValue = res.filter((item) => item.indexCode === 'A5')[0].indexValue
        this.staList[0].value = res.filter((item) => item.indexCode === 'A6')[0].indexValue
        this.staList[1].value = res.filter((item) => item.indexCode === 'A7')[0].indexValue
        this.complishPercent = ((this.staList[1].value / this.staList[0].value) * 100).toFixed(2)
        //获取EPC数据
        this.EPCInvestNum = res.filter((item) => item.indexCode === 'A4')[0].indexValue
        this.EPCData = {
          spending: res.filter((item) => item.indexCode === 'A10')[0].indexValue,
          income: res.filter((item) => item.indexCode === 'A9')[0].indexValue,
          profits:
            res.filter((item) => item.indexCode === 'A9')[0].indexValue -
            res.filter((item) => item.indexCode === 'A10')[0].indexValue
        }
        //获取近六个月数据
        this.latestData.income.push(res.filter((item) => item.indexCode === 'A47')[0].indexValue)
        this.latestData.income.push(res.filter((item) => item.indexCode === 'A50')[0].indexValue)
        this.latestData.income.push(res.filter((item) => item.indexCode === 'A53')[0].indexValue)
        this.latestData.income.push(res.filter((item) => item.indexCode === 'A56')[0].indexValue)
        this.latestData.income.push(res.filter((item) => item.indexCode === 'A59')[0].indexValue)
        this.latestData.income.push(res.filter((item) => item.indexCode === 'A62')[0].indexValue)
        //
        this.latestData.spending.push(res.filter((item) => item.indexCode === 'A48')[0].indexValue)
        this.latestData.spending.push(res.filter((item) => item.indexCode === 'A51')[0].indexValue)
        this.latestData.spending.push(res.filter((item) => item.indexCode === 'A54')[0].indexValue)
        this.latestData.spending.push(res.filter((item) => item.indexCode === 'A57')[0].indexValue)
        this.latestData.spending.push(res.filter((item) => item.indexCode === 'A60')[0].indexValue)
        this.latestData.spending.push(res.filter((item) => item.indexCode === 'A63')[0].indexValue)
        //
        this.latestData.profits.push(res.filter((item) => item.indexCode === 'A49')[0].indexValue)
        this.latestData.profits.push(res.filter((item) => item.indexCode === 'A52')[0].indexValue)
        this.latestData.profits.push(res.filter((item) => item.indexCode === 'A55')[0].indexValue)
        this.latestData.profits.push(res.filter((item) => item.indexCode === 'A58')[0].indexValue)
        this.latestData.profits.push(res.filter((item) => item.indexCode === 'A61')[0].indexValue)
        this.latestData.profits.push(res.filter((item) => item.indexCode === 'A64')[0].indexValue)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.animate__slideInLeft,
.animate__slideOutLeft {
  animation-duration: 3s; //动画持续时间
  animation-delay: 0s; //动画延迟时间
}
.widget-ContractInfo {
  $size10: 0.052083rem /* 10/192 */;
  $size20: 0.104167rem /* 20/192 */;
  z-index: 2;
  //position
  bottom: $size10 /* 10/192 */;
  margin-left: $size20 /* 20/192 */;
  position: absolute;
  //size
  height: calc(100% - 0.557292rem /* 107/192 */);
  width: 2.083333rem /* 400/192 */;
  //background
  // background-color: rgba(20, 24, 47, 0.5);
  color: #eee;
  // box-shadow: 0 0 20px rgba(1, 9, 20, 1);
  //font
  // font-family: Source Han Sans CN-HEAVY;
  .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;
      }
      .el-select {
        flex: 0.4;
        /deep/ input {
          padding: 0;
          background: transparent;
          border: none;
          font-size: 0.072917rem /* 14/192 */;
          font-weight: 500;
          color: #2ba7ff;
        }
        /deep/ .el-icon-arrow-up:before {
          content: '';
          display: block;
          // 定义元素宽高
          margin-top: 0.041667rem /* 8/192 */;
          width: 0.130208rem /* 25/192 */;
          height: 0.078125rem /* 15/192 */;
          background: url('~@/views/groupPage/images/三角下.png') no-repeat center center;
          background-size: 100% 100%;
          transform: rotate(180deg);
        }
      }
      .datePicker {
        position: absolute;
        left: 1.041667rem /* 200/192 */;
        top: 0.182292rem /* 35/192 */;
        .el-range-editor--mini.el-input__inner {
          width: 1.041667rem /* 200/192 */;
          height: 0.145833rem /* 28/192 */;
        }
        /deep/ .el-date-editor .el-range-input {
          width: 100%;
        }
      }
    }
  }
  .content-info {
    width: 100%;
    height: calc(100% - 0.166667rem);
    overflow: auto;
    font-family: Source Han Sans CN-MEDIUM;
    .content-item {
      width: 100%;
      height: 33%;
      .title {
        width: 100%;
        display: flex;
        // padding: .145833rem 0 .104167rem 0;
        padding: 0.145833rem 0 0.026042rem /* 5/192 */ 0;
        .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 {
          color: #ffffff;
          font-size: 0.072917rem /* 14/192 */;
          font-weight: 500;
        }
        .item-info {
          color: #2ba7ff;
          font-size: 0.072917rem /* 14/192 */;
          font-weight: 500;
        }
      }
      .content {
        height: calc(100% - 0.234375rem /* 45/192 */);
        width: 100%;
        display: flex;
        .chart-container {
          height: 100%;
          width: 50%;
          position: relative;
          .chart-title {
            position: absolute;
            left: 0.234375rem /* 45/192 */;
            font-size: 0.083333rem /* 16/192 */;
            font-family: Source Han Sans CN;
            font-weight: bold;
            top: 0.104167rem /* 20/192 */;
            color: #ffffff;
          }
          .bg {
            width: 100%;
            height: 100%;
          }
          .bg {
            position: absolute;
            // top: 0.614583rem /* 118/192 */;
            top: 15%;
            left: 0.041667rem /* 8/192 */;
            z-index: -1;
            width: 0.9375rem /* 180/192 */;
            height: 0.807292rem /* 155/192 */;
            background: no-repeat center;
            background-image: url('~@/views/groupPage/images/底座样式.png');
            background-size: 100% 100%;
          }
        }
        .dataInfo {
          width: 50%;
          display: flex;
          flex-flow: column;
          justify-content: space-around;
          font-family: Source Han Sans CN;
          .data-item {
            display: flex;
            align-items: center;
            padding: 0.052083rem /* 10/192 */;
            color: #ffffff;
            height: 0.338542rem /* 65/192 */;
            .pointSymbol,
            .data-title {
              margin-right: 0.052083rem /* 10/192 */;
              white-space: nowrap;
            }
            .pointSymbol {
              border-radius: 50%;
              height: 0.052083rem /* 10/192 */;
              width: 0.052083rem /* 10/192 */;
            }
            .data-title {
              font-size: 0.072917rem /* 14/192 */;
              font-weight: 400;
              color: #ffffff;
            }
            .data-value {
              font-size: 0.083333rem /* 16/192 */;
              font-family: Source Han Sans CN-HEAVY;
              font-weight: bold;
              color: #ffffff;
              position: absolute;
              right: 2%;
            }
          }
        }
      }
      .epc {
        background: rgba(14, 167, 255, 0.08);
        margin-top: 0.15625rem /* 30/192 */;
        height: calc(100% - 0.390625rem /* 75/192 */);
      }
    }
  }
}
</style>