<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: 27%">
        <item-title :title="'项目信息'"></item-title>
        <ul>
          <li>项目名称：黑龙江省哈尔滨市2024年老旧小区改造项目 EPC工程总承包（七标段）——黑大片区</li>
          <li>建设单位：哈尔滨市南岗区住房和城乡建设局</li>
          <li>监理单位：哈尔滨市工程建设监理有限公司</li>
          <li>施工单位：哈尔滨建工建设有限公司</li>
        </ul>
      </div>
      <div class="home-left-info" style="height: 41%; margin-top: 5px">
        <item-title :title="'今日人材机概况'"></item-title>

        <ul class="home-right-ziyuan__box">
          <li>
            <div @click="handleJumpToPersonnel">
              <span>162<span class="unit_l">人</span></span>
              <span>出勤人数</span>
            </div>
          </li>

          <li>
            <div @click="handleJumpToMaterial">
              <span>12<span class="unit_l">项</span></span>
              <span>材料入库</span>
            </div>
          </li>
          <li>
            <div @click="handleJumpToMaterial">
              <span>12<span class="unit_l">项</span></span>
              <span>材料出库</span>
            </div>
          </li>
          <li>
            <div @click="handleJumpToQuality">
              <span>2<span class="unit_l">条</span></span>
              <span>质量记录</span>
            </div>
          </li>
          <li>
            <div @click="handleJumpToSafety">
              <span>2<span class="unit_l">条</span></span>
              <span>安全记录</span>
            </div>
          </li>
        </ul>
      </div>
      <div class="home-left-progress" style="width: 100%; height: 29%">
        <div class="home-left-progress__wavechart" style="width: 48%; height: 100%">
          <div class="wavechart" id="wavechart" style="width: 100%; height: 110%"></div>
          <!-- <div style="text-align: center">
            <div>
              施工天数
              <span>{{ diffDays }}</span>
              天
            </div>
            <div>
              总工期
              <span>{{ totalDays }}</span>
              天
            </div>
          </div> -->
        </div>
        <div class="home-left-progress__wavechart" style="width: 48%; height: 100%">
          <div class="wavechart" id="chanzhichart" style="width: 100%; height: 110%"></div>
          <!-- <div style="text-align: center">
            <div>
              当前完成产值
              <span>{{ currentChanzhi }}</span>
              万元
            </div>
            <div>
              总产值
              <span>{{ totalChanzhi }}</span>
              万元
            </div>
          </div> -->
        </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-rizhi" style="height: 50%; overflow-y: auto">
        <item-title :title="'项目概况'"></item-title>
        <ul>
          <li><strong style="color: #02d1c5">项目共计178栋，13974户，111.07万㎡。</strong></li>
          <li><strong style="color: #02d1c5"> ①黑龙江省哈尔滨市南岗区哈西街道小区改造配套基础设施建设项目276645.92㎡，57栋楼，3233户。</strong></li>
          <li>②黑龙江省哈尔滨市南岗区七政街道国泰社区小区改造配套基础设施建设项目，252271.46㎡，35栋楼，3027户；</li>
          <li>③黑龙江省哈尔滨市南岗区七政、通达街道小区改造配套基础设施建设项目153680.01㎡，24栋楼，2240户；</li>
          <li>④黑龙江省哈尔滨市南岗区七政街道元士、国脉社区小区改造配套基础设施建设项目252302.02㎡，34栋楼，3342户；</li>
          <li>⑤黑龙江省哈尔滨市南岗区曲线街道小区改造配套基础设施建设项目87365.24㎡，12栋楼，948户；</li>
          <li>⑥黑龙江省哈尔滨市南岗区松花江街道铁路街西大直街公司街红军街围合区域改造配套基础设施建设项目53744.19㎡，10栋楼，691户；</li>
          <li>⑦黑龙江省哈尔滨市南岗区松花江街道铁路街西大直街教化街公司街合围区域改造配套基础设施建设项目34757.67㎡，6栋楼，493户；</li>
        </ul>
      </div>
      <div class="home-right-rizhi" style="height: 50%">
        <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-04-30',
      totalDays: 199,
      currentChanzhi: 2981.9,
      totalChanzhi: 9318.4,
      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 = {
        tooltip: {
          show: true,
          trigger: 'item', // tooltip 触发方式，item 表示数据项触发
          formatter: function (params) {
            // params 是 tooltip 的参数，包含了数据项的信息
            return '施工天数 <strong style="color: #294d99;">78</strong> 天<br/>总工期 <strong style="color: #294d99;">199</strong> 天';
          },
          position: function (point, params, dom, rect, size) {
            // point 是鼠标当前的位置
            // params 是 tooltip 的参数
            // dom 是 tooltip 的 dom 对象
            // rect 是包含图表的 dom 节点的矩形区域
            // size 是 tooltip dom 的大小

            // 使用数组形式设置绝对位置
            return [point[0] + 10, point[1] - 10];

            // 或者使用相对位置字符串
            // return 'right'; // tooltip 将出现在鼠标位置的右侧
          },
        },
        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)

      const percentageChanzhi = (this.currentChanzhi / this.totalChanzhi).toFixed(2)

      const optionChanzhi = {
        tooltip: {
          show: true,
          trigger: 'item', // tooltip 触发方式，item 表示数据项触发
          formatter: function (params) {
            // params 是 tooltip 的参数，包含了数据项的信息
            return '当前完成产值 <strong style="color: #294d99;">2981.9</strong> 万元<br/>总产值 <strong style="color: #294d99;">9318.4</strong> 万元';
          },
          position: function (point, params, dom, rect, size) {
            // point 是鼠标当前的位置
            // params 是 tooltip 的参数
            // dom 是 tooltip 的 dom 对象
            // rect 是包含图表的 dom 节点的矩形区域
            // size 是 tooltip dom 的大小

            // 使用数组形式设置绝对位置
            return [point[0] + 10, point[1] - 10];

            // 或者使用相对位置字符串
            // return 'right'; // tooltip 将出现在鼠标位置的右侧
          },
        },
        title: {
          text: '产值进度',
          left: 'center',
          textStyle: {
            color: '#fff'
          }
        },
        series: [
          {
            type: 'liquidFill',
            data: [percentageChanzhi],
            label: {
              textStyle: {
                fontSize: 24
              }
            }
          }
        ]
      }
      const chanzhichart = echarts.init(document.getElementById('chanzhichart'))
      window.onresize = chanzhichart.resize //在窗口大小改变时，相应的元素能够适应新的窗口尺寸。
      chanzhichart.setOption(optionChanzhi)
    },
    handleJumpToMaterial() {
      this.$router.push({ path: '/material' })
    },
    handleJumpToPersonnel() {
      this.$router.push({ path: '/personnel' })
    },
    handleJumpToSafety() {
      this.$router.push({ path: '/security' })
    },
    handleJumpToQuality() {
      this.$router.push({ path: '/quality' })
    }
  },

  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-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-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/home.png) no-repeat;
      background-position: 45% 100%;
      background-size: cover;
    }
  }

  .unit_l {
    font-size: 0.4rem !important;
  }

  .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);
    }

    .home-right-rizhi {
      ul {
        padding: 2% 10%;

        li {
          font-size: px2rem(16);
          line-height: px2rem(32);
        }
      }
    }
  }
}
</style>
