<template>
  <transition
    appear
    name="animate__animated"
    enter-active-class="animate__slideInLeft"
    leave-active-class="animate__slideOutLeft"
  >
    <div class="widget-ContractInfo">
      <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> -->
            <span class="item-info">三峡发展承揽项目{{ ProjectTotal }}个，总合同金额{{ TotalValue }}亿元</span>
          </div>
          <div class="content">
            <div class="chart-container">
              <!-- <div class="chart-title">完成占比：{{ complishPercent }}%</div> -->
              <div class="chart-title">本年产值完成占比：{{ complishPercent }}%</div>
              <ComThreeDimensionsChart v-on="{ fontSize }" :chartData="staList" />
              <!-- 底座背景 -->
              <div class="bg" :style="{ 'background-image': `url('${url}')` }"></div>
              <div class="invest-title">
                <span>累计结算{{ allCost }}亿元</span><span>本年度累计结算{{ yearCost }}亿元</span>
              </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="data-value" :title="item.value + item.unit">{{ item.value }}{{ item.unit }}</div>
                <div class="data-wrap">
                  <div class="pointSymbol" :style="index === 0 ? 'background:#2BA7FF' : 'background:#13D28A'"></div>
                  <div class="data-title">{{ item.name }}</div>
                </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">{{ code ? '分公司收支情况（亿）' : '近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 url from '@/views/groupPage/images/base64/3dBaseBack'
import { getRequestResult, getEpcMonthCountData, getCostData } from '@/views/groupPage/apis'
import { setNullAndUndefinedEmpty, fontSize as fs, subtraction } 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'
import { roundFun } from '@/views/groupPage/util'
export default {
  name: 'ContractInfo', //合同情况
  components: {
    ComThreeDimensionsChart,
    ComBatteryChart,
    ComLineChart
  },
  props: {
    dataInfo: { type: Object, default: () => {} }
  },
  data() {
    return {
      url,
      staList: [
        { name: '本年投资计划', value: 0, unit: '亿' },
        { name: '本年累计完成产值', value: 0, unit: '亿' }
      ],
      //建管项目
      ProjectTotal: '', //项目总数
      TotalValue: '', //累计完成产值
      complishPercent: 0, //完成占比
      //EPC
      EPCInvestNum: 0, //EPC项目投资数
      EPCData: {
        spending: 0,
        income: 0,
        profits: 0
      }, //EPC收支信息
      latestData: {
        month: new Array(6).fill(''),
        income: new Array(6).fill(0),
        spending: new Array(6).fill(0),
        profits: new Array(6).fill(0)
      },
      allCost: 0,
      yearCost: 0
    }
  },
  watch: {
    dataInfo: {
      handler(n, o) {
        Object.assign(this.$data, this.$options.data())
        if (n) this.setData()
      },
      immediate: true
    }
  },
  computed: {
    setNoNull() {
      return setNullAndUndefinedEmpty
    },
    fontSize() {
      return fs
    },
    code() {
      return this.$store.state.bigScreen.groupCodeValue
    }
  },
  methods: {
    //获取总公司数据
    async getPageData() {
      // let data = { blockCode: 'ycepclist' }
      // //获取全部数据
      // getRequestResult(data).then((res) => {
      //   res = res.map((item) => {
      //     return {
      //       ...item,
      //       indexValue:
      //         item.unit === '万元'
      //           ? roundFun(this.setNoNull(item.indexValue) / 10000, 2)
      //           : this.setNoNull(item.indexValue)
      //     }
      //   })
      //   //获取项目数据
      //   {
      //     const { indexName, indexValue, unit } = res.find((item) => item.indexCode === 'A65')
      //     this.ProjectTotal = indexName + indexValue + unit
      //   }
      //   {
      //     const { indexName, indexValue, unit } = res.find((item) => item.indexCode === 'A66')
      //     this.TotalValue = indexName + indexValue + unit
      //   }
      //   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 = roundFun((this.staList[1].value / this.staList[0].value) * 100, 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: subtraction(
      //       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)
      //   // //
      //   // this.latestData.month.push(this.getMonth(res.filter((item) => item.indexCode === 'A47')[0].indexName))
      //   // this.latestData.month.push(this.getMonth(res.filter((item) => item.indexCode === 'A50')[0].indexName))
      //   // this.latestData.month.push(this.getMonth(res.filter((item) => item.indexCode === 'A53')[0].indexName))
      //   // this.latestData.month.push(this.getMonth(res.filter((item) => item.indexCode === 'A56')[0].indexName))
      //   // this.latestData.month.push(this.getMonth(res.filter((item) => item.indexCode === 'A59')[0].indexName))
      //   // this.latestData.month.push(this.getMonth(res.filter((item) => item.indexCode === 'A62')[0].indexName))
      // })
    },
    // getMonth(name) {
    //   let res = name.split('月')
    //   return res[0] + '月'
    // },
    //获取分公司数据
    getBranchPageData() {
      // let data = { blockCode: 'ycepclist', 'paras[0].name': 'projectName', 'paras[0].val': this.code }
      // //获取全部数据
      // getRequestResult(data).then((res) => {
      //   res = res.map((item) => {
      //     return {
      //       ...item,
      //       indexValue:
      //         item.unit === '万元'
      //           ? roundFun(this.setNoNull(item.indexValue) / 10000, 2)
      //           : this.setNoNull(item.indexValue)
      //     }
      //   })
      //   //获取项目数据
      //   {
      //     const { indexName, indexValue, unit } = res.find((item) => item.indexCode === this.code + '-32')
      //     this.ProjectTotal = indexName + indexValue + unit
      //   }
      //   {
      //     const { indexName, indexValue, unit } = res.find((item) => item.indexCode === this.code + '-33')
      //     this.TotalValue = indexName + indexValue + unit
      //   }
      //   this.staList[0].value = res.filter((item) => item.indexCode === this.code + '-6')[0].indexValue
      //   this.staList[1].value = res.filter((item) => item.indexCode === this.code + '-7')[0].indexValue
      //   this.complishPercent = roundFun((this.staList[1].value / this.staList[0].value) * 100, 2)
      //   //获取EPC数据
      //   this.EPCInvestNum = res.filter((item) => item.indexCode === this.code + '-4')[0].indexValue
      //   this.EPCData = {
      //     spending: res.filter((item) => item.indexCode === this.code + '-10')[0].indexValue,
      //     income: res.filter((item) => item.indexCode === this.code + '-9')[0].indexValue,
      //     profits: subtraction(
      //       res.filter((item) => item.indexCode === this.code + '-9')[0].indexValue,
      //       res.filter((item) => item.indexCode === this.code + '-10')[0].indexValue
      //     )
      //   }
      //   //获取分公司收支情况
      //   this.latestData = {
      //     income: [],
      //     spending: [],
      //     profits: [],
      //     month: []
      //   }
      //   this.latestData.income.push(res.find((item) => item.indexCode === this.code + '-12').indexValue)
      //   this.latestData.income.push(res.find((item) => item.indexCode === this.code + '-15').indexValue)
      //   this.latestData.income.push(res.find((item) => item.indexCode === this.code + '-18').indexValue)
      //   this.latestData.income.push(res.find((item) => item.indexCode === this.code + '-21').indexValue)
      //   //
      //   this.latestData.spending.push(res.find((item) => item.indexCode === this.code + '-13').indexValue)
      //   this.latestData.spending.push(res.find((item) => item.indexCode === this.code + '-16').indexValue)
      //   this.latestData.spending.push(res.find((item) => item.indexCode === this.code + '-19').indexValue)
      //   this.latestData.spending.push(res.find((item) => item.indexCode === this.code + '-22').indexValue)
      //   //
      //   this.latestData.profits.push(res.find((item) => item.indexCode === this.code + '-14').indexValue)
      //   this.latestData.profits.push(res.find((item) => item.indexCode === this.code + '-17').indexValue)
      //   this.latestData.profits.push(res.find((item) => item.indexCode === this.code + '-20').indexValue)
      //   this.latestData.profits.push(res.find((item) => item.indexCode === this.code + '-23').indexValue)
      //   //
      //   this.latestData.month.push(res.find((item) => item.indexCode === this.code + '-12').indexName.split('省')[0])
      //   this.latestData.month.push(res.find((item) => item.indexCode === this.code + '-15').indexName.split('省')[0])
      //   this.latestData.month.push(res.find((item) => item.indexCode === this.code + '-18').indexName.split('省')[0])
      //   this.latestData.month.push(res.find((item) => item.indexCode === this.code + '-21').indexName.split('省')[0])
      // })
    },

    //new
    async setData() {
      const settleRes = await getCostData({ commanyName: this.code })
      const { allCost, yearCost } = settleRes.result
      this.allCost = allCost
      this.yearCost = yearCost
      const { jgTzjh, jgLjcz, jgWczb, jgZhtje, jgNum, epcZtz, epcLjlr, epcLjsr, epcLjzc } = this.dataInfo || {}
      //建管项目
      this.$nextTick(() => {
        this.staList = [
          { name: '本年投资计划', value: jgTzjh, unit: '亿' },
          { name: '本年累计完成产值', value: jgLjcz, unit: '亿' }
        ]
      })
      this.ProjectTotal = jgNum
      this.TotalValue = jgZhtje
      this.complishPercent = jgWczb
      //PC项目
      this.EPCInvestNum = epcZtz
      this.EPCData = {
        spending: epcLjzc,
        income: epcLjsr,
        profits: epcLjlr
      }
      //近6个月数据（亿）
      this.latestData.income = []
      this.latestData.spending = []
      this.latestData.profits = []
      this.latestData.month = []
      const res = await getEpcMonthCountData({ name: this.code })
      let { legendData, seriesDatas, xaxis } = res.result
      this.latestData.month = xaxis.map((item) => this.getMonth(item))
      seriesDatas.forEach((item) => {
        if (item.name == '收入') this.latestData.income = item.seriesData
        if (item.name == '支出') this.latestData.spending = item.seriesData
        // if (item.name == '利润') this.latestData.profits = item.seriesData
      })
    },
    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-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;
          white-space: nowrap;
        }
        .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;
        overflow: hidden;
        .chart-container {
          height: 100%;
          width: 50%;
          position: relative;
          .chart-title {
            position: absolute;
            text-align: center;
            // left: 0.234375rem /* 45/192 */;
            left: 0.104167rem /* 20/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%;
          }
          .invest-title {
            position: absolute;
            bottom: 0;
            font-size: 0.083333rem /* 16/192 */;
            font-family: Source Han Sans CN;
            font-weight: bold;
            color: #ffffff;
            display: flex;
            flex-flow: column;
            justify-content: center;
            align-items: center;
            left: 0.15625rem; /* 30/192 */
            span {
              white-space: nowrap;
            }
          }
        }
        .dataInfo {
          width: 50%;
          display: flex;
          flex-flow: column;
          justify-content: space-around;
          font-family: Source Han Sans CN;
          .data-item {
            display: flex;
            flex-flow: column;
            align-items: center;
            justify-content: space-around;
            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-wrap {
              display: flex;
            }
            .data-value {
              font-size: 0.083333rem /* 16/192 */;
              font-family: Source Han Sans CN-HEAVY;
              font-weight: bold;
              color: #ffffff;
            }
          }
        }
      }
      .epc {
        background: rgba(14, 167, 255, 0.08);
        margin-top: 0.15625rem /* 30/192 */;
        height: calc(100% - 0.390625rem /* 75/192 */);
      }
    }
  }
}
</style>