<template>
  <transition
    appear
    name="animate__animated animate__move"
    enter-active-class="animate__slideInLeft"
    leave-active-class="animate__slideOutLeft"
  >
    <div class="widget-ProjectOverview">
      <div class="head">
        <div class="title">
          <div class="icon"></div>
          <span class="site-info">项目概况</span>
        </div>
      </div>
      <div class="content-info">
        <div class="sewage-plant-info">
          <div
            :class="[{ 'info-item': item.subtitle, 'info-item-short': !item.subtitle }]"
            v-for="item of plantInfoList"
            :key="item.title"
          >
            <template v-if="item.subtitle">
              <div class="left">
                <div class="title">{{ item.title }}：</div>
                <div :class="['value', { emphasis: item.num !== 0 }]">{{ item.num }}{{ item.unit }}</div>
              </div>
              <div class="right">
                <div class="title">{{ item.subtitle }}：</div>
                <div :class="['value', { emphasis: item.capacity !== 0 }]">{{ item.capacity }}{{ item.cunit }}</div>
              </div>
            </template>
            <template v-else>
              <div class="title">{{ item.title }}：</div>
              <div :class="['value', { emphasis: item.num !== 0 }]">{{ item.num }}{{ item.unit }}</div>
            </template>
          </div>
        </div>
        <!-- <div class="drainage-pipe-info">
          <div class="info-item" v-for="item of pipeInfoList" :key="item.title">
            <div class="wrap">
              <div :class="['value', { emphasis: item.num !== 0 }]">{{ item.num }}{{ item.unit }}</div>
              <div class="title">{{ item.title }}</div>
            </div>
          </div>
        </div> -->
      </div>
    </div>
  </transition>
</template>

<script lang="ts">
import { getRequestResult } from '../../apis'
import { Vue, Component, Prop, Watch } from 'vue-property-decorator'
//项目概况
@Component({ name: 'ProjectOverview' })
export default class ProjectOverview extends Vue {
  @Prop({ type: Object, default: () => {} }) dataInfo!: any
  plantInfoList: Array<any> = [
    { title: '新建污水处理厂', num: 0, unit: '座', subtitle: '处理规模', capacity: 0, cunit: '万m³/日' },
    { title: '提标改造污水处理厂', num: 0, unit: '座', subtitle: '处理能力', capacity: 0, cunit: '万m³/日' },
    { title: '存量污水处理厂', num: 0, unit: '座', subtitle: '处理规模', capacity: 0, cunit: '万m³/日' },
    { title: '新建供水管网', num: 0, unit: 'km' },
    { title: '存量管网长度', num: 0, unit: 'km' },
    { title: '新建雨污管网', num: 0, unit: 'km' },
    { title: '管网治理长度', num: 0, unit: 'km' },
    { title: '新建排水管网', num: 0, unit: 'km' },
    { title: '污泥资源化能力', num: 0, unit: '吨/天' }
  ]
  // pipeInfoList: Array<any> = [
  //   { title: '新建排水管网', num: 0, unit: 'km' },
  //   { title: '管网修复', num: 0, unit: 'km' },
  //   { title: '河道治理长度', num: 0, unit: 'km' },
  //   { title: '污泥资源化能力', num: 0, unit: '吨/天' }
  // ]
  get projectCode() {
    return this.$store.state.bigScreen.currentProjectCode
  }
  @Watch('dataInfo')
  onChangMehod() {
    this.getPageData()
  }
  getPageData() {
    if (!this.dataInfo) return
    const {
      sewage_new_plant,
      sewage_new_ability,
      sewage_reform_plant,
      sewage_reform_ability,
      sewage_stock_plant,
      sewage_stock_ability,
      pipe_supply_length,
      pipe_stock_length,
      pipe_new_rain,
      pipe_govern,
      pipe_new_drainage,
      pipe_resource_ability
    } = this.dataInfo || {}
    this.plantInfoList = [
      {
        title: '新建污水处理厂',
        num: sewage_new_plant,
        unit: '座',
        subtitle: '处理规模',
        capacity: sewage_new_ability,
        cunit: '万m³/日'
      },
      {
        title: '提标改造污水处理厂',
        num: sewage_reform_plant,
        unit: '座',
        subtitle: '处理能力',
        capacity: sewage_reform_ability,
        cunit: '万m³/日'
      },
      {
        title: '存量污水处理厂',
        num: sewage_stock_plant,
        unit: '座',
        subtitle: '处理规模',
        capacity: sewage_stock_ability,
        cunit: '万m³/日'
      },
      { title: '新建供水管网', num: pipe_supply_length, unit: 'km' },
      { title: '存量管网长度', num: pipe_stock_length, unit: 'km' },
      { title: '新建雨污管网', num: pipe_new_rain, unit: 'km' },
      { title: '管网治理长度', num: pipe_govern, unit: 'km' },
      { title: '新建排水管网', num: pipe_new_drainage, unit: 'km' },
      { title: '污泥资源化能力', num: pipe_resource_ability, unit: '吨/天' }
    ]
    // this.pipeInfoList = [
    //   { title: '新建排水管网', num: pipe_new_drainage, unit: 'km' },
    //   { title: '管网修复', num: pipe_repair, unit: 'km' },
    //   { title: '河道治理长度', num: pipe_govern, unit: 'km' },
    //   { title: '污泥资源化能力', num: pipe_resource_ability, unit: '吨/天' }
    // ]
    // let data = { blockCode: 'ycepclist' }
    // let projectCode = this.projectCode
    // //获取全部数据
    // getRequestResult(data)
    //   .then((res: Array<any>) => {
    //     res = res.filter((item) => item.indexCode.indexOf(projectCode + '-') != -1)
    //     res = res.map((item) => {
    //       Object.keys(item).forEach((val) => (item[val] = item[val] || ''))
    //       return { ...item }
    //     })
    //     this.plantInfoList = this.plantInfoList.map((item, index) => {
    //       index = index * 2
    //       return {
    //         ...item,
    //         num: Number(res.find((e) => e.indexCode == projectCode + '-' + (index + 5)).indexValue) || 0,
    //         unit: res.find((e) => e.indexCode == projectCode + '-' + (index + 5)).unit,
    //         capacity: Number(res.find((e) => e.indexCode == projectCode + '-' + (index + 6)).indexValue) || 0,
    //         cunit: res.find((e) => e.indexCode == projectCode + '-' + (index + 6)).unit
    //       }
    //     })
    //     this.pipeInfoList = this.pipeInfoList.map((item, index) => {
    //       return {
    //         ...item,
    //         num: Number(res.find((e) => e.indexCode == projectCode + '-' + (index + 11)).indexValue) || 0,
    //         unit: res.find((e) => e.indexCode == projectCode + '-' + (index + 11)).unit
    //       }
    //     })
    //   })
    //   .catch((err) => {
    //     console.log(err)
    //   })
  }
}
</script>

<style lang="scss" scoped>
.animate__slideInLeft,
.animate__slideOutLeft {
  animation-duration: 3s; //动画持续时间
  animation-delay: 0s; //动画延迟时间
}
.widget-ProjectOverview {
  $size10: 0.052083rem /* 10/192 */;
  $size20: 0.104167rem /* 20/192 */;
  z-index: 2;
  //position
  top: 0.505208rem /* 97/192 */;
  margin-left: $size20 /* 20/192 */;
  position: absolute;
  //size
  height: 1.822917rem /* 350/192 */;
  width: 2.083333rem /* 400/192 */;
  color: #eee;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.24) 100%);
  .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;
      }
    }
  }
  .content-info {
    width: 100%;
    height: calc(100% - 0.166667rem);
    overflow: auto;
    padding: 2px;
    font-family: Source Han Sans CN-MEDIUM;
    .title {
      font-size: 0.072917rem /* 14/192 */;
      font-weight: 500;
      color: #84bde5;
    }
    .value {
      font-size: 0.083333rem /* 16/192 */;
      color: #ffffff;
    }
    .emphasis {
      font-family: Source Han Sans CN-HEAVY;
      font-weight: bold;
      background: linear-gradient(0deg, #ff5241 0%, #ffc573 100%);
      background-clip: text;
      -webkit-text-fill-color: transparent;
    }
    .sewage-plant-info {
      width: 100%;
      height: calc(100% - 0.104167rem /* 20/192 */);
      // height: 0.84375rem /* 162/192 */;
      margin-top: 0.104167rem /* 20/192 */;
      // background: rgba(14, 167, 255, 0.12);
      // display: flex;
      // flex-flow: column;
      .info-item {
        width: calc(100% - 36px);
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin: 0 0.09375rem /* 18/192 */ 0.052083rem /* 10/192 */ 0.09375rem /* 18/192 */;
        padding: 0.052083rem /* 10/192 */;
        border-bottom: 1px solid rgba(14, 167, 255, 0.26);
        font-family: Source Han Sans CN;
        .left,
        .right {
          display: flex;
          align-items: center;
          justify-content: center;
        }
      }
      .info-item:nth-child(1) {
        margin: 0.036458rem /* 7/192 */ 0.09375rem /* 18/192 */ 0.078125rem /* 15/192 */ 0.09375rem /* 18/192 */;
      }

      .info-item-short {
        width: 50%;
        float: left;
        // .wrap {
        //   display: flex;
        //   justify-content: space-between;
        //   align-items: center;
        // }
        .title,
        .value {
          padding: 0.026042rem /* 5/192 */;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
    }
    .drainage-pipe-info {
      height: calc(100% - 0.973958rem /* 187/192 */);
      margin-top: 0.026042rem /* 5/192 */;
      display: grid;
      grid-template-rows: repeat(2, 1fr);
      grid-template-columns: repeat(2, 1fr);
      // background: rgba(14, 167, 255, 0.12);
      .info-item {
        position: relative;
        .title,
        .value {
          padding: 0.041667rem /* 8/192 */;
          display: flex;
          justify-content: center;
          align-items: center;
        }
      }
      .info-item:first-of-type > .wrap::before,
      .info-item:nth-of-type(2) > .wrap::before {
        content: '';
        position: absolute;
        height: 0.005208rem /* 1/192 */;
        width: 0.9375rem /* 180/192 */;
        background: rgba(14, 167, 255, 0.26);
        margin: 0 auto;
        left: 0;
        right: 0;
        bottom: 0;
      }
      .info-item:first-of-type > .wrap::after,
      .info-item:nth-of-type(3) > .wrap::after {
        content: '';
        position: absolute;
        height: 0.239583rem /* 46/192 */;
        width: 0.005208rem /* 1/192 */;
        background: rgba(14, 167, 255, 0.26);
        margin: auto 0;
        top: 0;
        bottom: 0;
        right: 0;
      }
    }
  }
}
</style>