<template>
  <dv-loading v-if="!showPage" style="width: 100%; height: 100%" class="the-loading">Loading...</dv-loading>
  <div v-else class="home">
    <div class="home-left" style="width: 30%">
      <div class="home-left-info" style="height: 40%">
        <item-title :title="'项目信息'"></item-title>
        <ul>
          <li>项目名称：哈尔滨市八区体育中心第九届亚冬会比赛场馆及配套设施提升改造工程</li>
          <li>建设单位：哈尔滨市体育局</li>
          <li>代建单位：哈尔滨市城市建设投资集团有限公司</li>
          <li>设计单位：哈尔滨市建筑设计院</li>
          <li>检测单位：黑龙江盛瑞盛建设工程质量检测有限公司</li>
          <li>监理单位：北京建宇建设管理有限公司</li>
          <li>施工单位：哈尔滨建工建设有限公司</li>
        </ul>
      </div>
      <div class="home-left-info" style="height: 28%; margin-top: 5px">
        <item-title :title="'项目地点'"></item-title>
        <ul>
          <li>项目地点：黑龙江省哈尔滨市道外区八区街22号</li>
          <li>建设规模：总建筑面积：32366.14平方米，其中比赛馆建筑面积：14902.56平方米；老训练馆建筑面积:2552.30平方米；新训练馆建筑面积：12044.04平方米；设备用房建筑面积：2867.24平方米。</li>
        </ul>
      </div>
      <div class="home-left-progress" style="width: 100%; height: 24%">
        <div class="home-left-progress__wavechart" style="width: 48%; height: 100%">
          <div class="wavechart" id="wavechart" style="width: 100%; height: 100%"></div>
        </div>
        <div class="home-left-progress__shengchan" style="width: 48%; height: 100%">
          <p class="shengchan-title">安全生产天数</p>
          <span class="shengchan-day">{{ diffDays }}</span>
          <span class="shengchan-date">开工日期 {{ startDay }}</span>
        </div>
      </div>
      <div class="home-left-days" style="width: 100%">
        <div>
          施工天数
          <span>{{ diffDays }}</span>
          天
        </div>
        <div>
          总工期
          <span>{{ totalDays }}</span>
          天
        </div>
      </div>
    </div>
    <div class="home-center" style="width: 38%">
      <!-- <div style="width: 100%; height: 95%" class="home-center__bg"></div> -->
      <iframe width="100%" height="95%" :src="mapUrl" frameborder="0" allowfullscreen></iframe>
    </div>
    <div class="home-right" style="width: 30%">
      <div class="home-right-ziyuan" style="height: 35%">
        <item-title :title="'人材机概况'"></item-title>
        <ul class="home-right-ziyuan__box">
          <li>
            <div>
              <span>45</span>
              <span>出勤人数</span>
            </div>
          </li>

          <li>
            <div>
              <span>23</span>
              <span>材料入库</span>
            </div>
          </li>
          <li>
            <div>
              <span>9</span>
              <span>材料出库</span>
            </div>
          </li>
          <li>
            <div>
              <span>24</span>
              <span>质量记录</span>
            </div>
          </li>
          <li>
            <div>
              <span>2</span>
              <span>安全记录</span>
            </div>
          </li>
        </ul>
      </div>

      <div class="home-right-rizhi" style="height: 65%">
        <item-title :title="'施工日志'"></item-title>
        <div class="home-right-rizhi__table">
          <dv-scroll-board :config="rizhi_config" style="width: 96%; height: 100%; margin: 12px auto" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import ItemTitle from '@/components/ItemTitle.vue'
import * as echarts from 'echarts'
import 'echarts-liquidfill'
import dayjs from 'dayjs'
import { jixieData, rizhiData } from './home'

export default {
  name: 'home',

  components: {
    ItemTitle
  },

  data() {
    return {
      showPage: true,
      mapUrl: 'http://static.harbinxiaoshi.cn/daping/' + process.env.VUE_APP_TITLE + '/html/map.html',
      startDay: '2024-01-21',
      totalDays: 193,

      tableData: [
        {
          date: '--',
          name: '--',
          address: '--'
        }
      ],

      jixie_config: {
        oddRowBGC: 'rgba(4, 24, 45,0.4)',
        evenRowBGC: '#0d1732',
        waitTime: 5000,
        align: ['center', 'center', 'center'],
        headerBGC: '#0b375d',
        header: ['日期', '设备名称', '型号'],
        headerHeight: 45,
        data: jixieData
      },
      rizhi_config: {
        oddRowBGC: 'rgba(4, 24, 45,0.4)',
        evenRowBGC: '#0d1732',
        waitTime: 5000,
        align: ['center', 'center'],
        headerBGC: '#0b375d',
        header: ['施工内容', '施工日期'],
        headerHeight: 45,
        rowNum: 7,
        data: rizhiData
      }
    }
  },

  computed: {
    diffDays() {
      const today = dayjs()
      const dateToCompare = dayjs(this.startDay)

      const diffInDays = today.diff(dateToCompare, 'day')

      return diffInDays
    }
  },

  methods: {
    initChart() {
      const percentage = (this.diffDays / this.totalDays).toFixed(2)

      const option = {
        title: {
          text: '总体进度',
          left: 'center',
          textStyle: {
            color: '#fff'
          }
        },
        series: [
          {
            type: 'liquidFill',
            data: [percentage],
            label: {
              textStyle: {
                fontSize: 24
              }
            }
          }
        ]
      }
      const wavechart = echarts.init(document.getElementById('wavechart'))
      window.onresize = wavechart.resize //在窗口大小改变时，相应的元素能够适应新的窗口尺寸。
      wavechart.setOption(option)
    }
  },

  mounted() {
    this.initChart()
  }
}
</script>

<style lang="scss" scoped>
.home {
  width: 100%;
  flex: 1;
  display: flex;
  justify-content: space-between;
  padding: 10px 20px;
  height: calc(100% - #{px2rem(58+78 + 20)});
  .home-left {
    height: 100%;
    // background: pink;
    .home-left-info {
      ul {
        padding: 2% 10%;
        li {
          font-size: px2rem(16);
          line-height: px2rem(32);
        }
      }
    }
    .home-left-progress {
      display: flex;
      justify-content: space-around;
      .home-left-progress__wavechart,
      .home-left-progress__shengchan {
        border: 1px solid #0780cf;
        padding: px2rem(8) 0;
      }
      .home-left-progress__shengchan {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        align-items: center;
        padding: px2rem(24) 0;
        .shengchan-title {
          font-size: px2rem(18);
        }
        .shengchan-day {
          font-size: px2rem(30);
          color: #fff2ac;
          font-weight: bold;
        }
        .shengchan-date {
          font-size: px2rem(18);
        }
      }
    }
    .home-left-days {
      display: flex;
      justify-content: space-around;
      height: px2rem(50);
      font-size: px2rem(18);
      & > div {
        width: 48%;
        height: 100%;
        line-height: px2rem(50);
        text-align: center;
        span {
          color: #fff2ac;
          margin: 0 10px;
        }
      }
    }
  }
  .home-center {
    height: 100%;
    // background: palegoldenrod;
    .home-center__bg {
      background: url(../../assets/image/zhiliang/3.jpg) no-repeat;
      background-position: 45% 100%;
      background-size: cover;
    }
  }
  .home-right {
    height: 100%;
    // background: palegreen;
    .home-right-ziyuan__box {
      display: flex;
      flex-wrap: wrap;
      height: 84%;
      & > li {
        width: 33%;
        height: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        div {
          width: 80%;
          height: 80%;
          display: flex;
          flex-direction: column;
          align-items: center;
          justify-content: space-around;
          background: url(../../assets/image/home-border.png) no-repeat;
          background-size: 100% 100%;
          padding: px2rem(15) 0;
          span:nth-child(1) {
            color: #4e81bb;
            font-size: px2rem(20);
          }
          span:nth-child(2) {
            font-size: px2rem(16);
          }
        }
      }
    }

    .home-right-jixie__table {
      width: 100%;
      margin-top: px2rem(10);
      height: calc(100% - #{px2rem(60)});

      ::v-deep .row-item {
        cursor: pointer;
      }
    }
    .home-right-rizhi__table {
      width: 100%;
      height: calc(100% - #{px2rem(80)});
      margin-top: px2rem(10);

      ::v-deep .row-item {
        cursor: pointer;
      }
    }

    ::v-deep .dv-scroll-board .rows .ceil {
      font-size: px2rem(12);
    }
  }
}
</style>
