<template>
  <div class="container-box" ref="editor">
    <div class="top">
      <div class="logo">
        <div>
          <img
            src="@/assets/img2/综合总览/编组.png"
            alt=""
            class="mt-20px ml-36px"
          />
        </div>
        <div>
          <img
            src="@/assets/img2/综合总览/编组 23备份.png"
            alt=""
            class="ml-36px"
          />
        </div>
      </div>
      <div class="tabsBox mt-36px ml-50px">
        <div class="tabs">
          <div
            :class="[`tab-item`, { cur: index === tabs.index }]"
            :key="item"
            @click="tabs.index = index"
            v-for="(item, index) in tabs.list"
          >
            {{ item }}
          </div>
        </div>
      </div>
      <div class="tipsBox">
        <div class="dateBox center">
          <div class="time font-size-22px">{{ dateBox.time }}</div>
          <div class="date font-size-16px">{{ dateBox.date }}</div>
        </div>
        <div class="line"></div>
        <div class="weather">
          <i :class="[`iconfont`, weather.天气图标]"></i>
        </div>
        <div class="temperature">
          <img class="pl-20px" src="@/assets/img2/综合总览/编组 6.png" alt="" />
          <span class="font-size-30px pl-20px">{{ weather.温度 }}</span>
          <img src="@/assets/img2/综合总览/编组 8.png" alt="" />
        </div>
        <div class="line"></div>
        <div class="headPortrait">
          <img src="@/assets/img2/综合总览/编组 58.png" class="w-44px" alt="" />
        </div>
      </div>
    </div>
    <div class="box">
      <slot>&nbsp;</slot>
    </div>
    <div :class="[`bg`, bgType]"></div>
  </div>
</template>

<script>
import { screenSize, getWeather } from '@/assets/js/utils'
import dayjs from 'dayjs'

export default {
  components: {},
  data() {
    return {
      tabs: {
        index: this.$props.tabIndex,
        list: [`综合总览`, `移栽分析`],
      },
      dateBox: {
        time: ``,
        date: ``,
      },
      weather: {
        温度: ``,
        天气: ``,
        天气图标: ``,
      },
    }
  },
  props: {
    tabChange: {
      type: Function,
      default: undefined,
    },
    tabIndex: {
      type: Number,
      default: 0,
    },
    bgType: {
      type: String,
      default: `g-bg1`,
    },
  },
  watch: {
    'tabs.index'(val) {
      this.tabChange && this.tabChange(val)
    },
  },
  computed: {},
  created() {
    this.$util.autoVueFn(
      [
        {
          time: 1000,
          fn: this.currentTime,
        },
        {
          time: 1000 * 900,
          fn: this.currentWeather,
        },
      ],
      this
    )
  },
  mounted() {
    screenSize(this.$refs.editor)
  },
  methods: {
    async currentWeather() {
      const data = await this.$http.get(`/api/currentWeather`, {
        params: {
          adcode: `520600`,
        },
      })
      const item = getWeather(data.天气)
      this.weather = data
      this.weather.天气图标 = item.icon || `icon-duoyun`
    },
    async currentTime() {
      const data = {
        date: dayjs(Date.now()).format(`YYYY/MM/DD`),
        time: dayjs(Date.now()).format(`HH:mm:ss`),
      }
      this.dateBox = data
    },
  },
}
</script>

<style lang="less" scoped>
.container-box {
  width: 1920px;
  height: 1080px;
  transform-origin: 0 0 0;
  position: relative;
  color: #fff;
  font-family: PingFang SC, PingFang SC-Regular;
  .top {
    position: absolute;
    display: flex;
    width: 100%;
    z-index: 10;
    .line {
      width: 0px;
      height: 41px;
      margin: 0 20px;
      border: 1px solid rgba(255, 255, 255, 0.3);
    }
    .tabs {
      font-size: 25px;
      text-align: center;
      display: flex;
      background-image: url('~@/assets/img2/综合总览/编组 9.png');
      background-repeat: no-repeat;
      background-position: center bottom;
      width: 766px;
      .tab-item {
        line-height: 56px;
        margin-right: 32px;
        color: rgba(255, 255, 255, 0.6);
        position: relative;
        cursor: pointer;
        &.cur {
          color: #fbfdff;
          &::before {
            content: '';
            display: block;
            position: absolute;
            width: 100%;
            height: 4px;
            background: linear-gradient(333deg, #158d8c 11%, #29f0f0 90%);
            bottom: 0px;
          }
        }
        &:first-child {
          margin-left: 40px;
        }
        &:not(:last-child)::after {
          content: '';
          display: block;
          width: 2px;
          height: 25px;
          background-color: rgba(255, 255, 255, 0.3);
          position: absolute;
          top: 28%;
          right: -16px;
        }
      }
    }
    .tipsBox {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      width: 100%;
      padding-right: 77px;
      .dateBox {
        .date {
          color: rgba(255, 255, 255, 0.6);
        }
      }
      .weather {
        i {
          font-size: 44px;
        }
      }
      .temperature {
        // img {
        //   padding: 0 20px;
        // }
      }
      .headPortrait {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        overflow: hidden;
        cursor: pointer;
      }
    }
  }
  .bg {
    pointer-events: none;
  }
  & > .box {
    transform-origin: 0 0 0;
    position: absolute;
    top: 90px;
    width: 100%;
    box-sizing: border-box;
    padding: 40px;
    left: 0;
    top: 0;
    padding: 0;
    z-index: 9;
  }
}
</style>
