<template>
  <div class="headview">
    <div class="dierjibie">
      <img :src="[img0, img1, img2][swindex]" alt="" srcset="" />
      <div class="asleft">
        <div class="jajajaj" v-if="tianqi">
          {{
            tianqi.result.city
              ? `${tianqi.result.city} ：${tianqi.result.weather || ''} ${tianqi.result.templow || ''}℃ ~${
                  tianqi.result.temphigh || ''
                }℃`
              : ''
          }}
        </div>
      </div>
      <div class="aszhongjian">
        <template v-if="userInfo.type == 1">{{ userInfo.companyName }}</template>
        <template v-else-if="userInfo.type == 2">{{ '平台管理员' }}</template>
        <el-carousel v-else-if="userInfo && userInfo.adminWebsits">
          <el-carousel-item v-for="(item, index) in userInfo.adminWebsits.map(item => item.name)" :key="index">
            <div class="aszhongjianText">{{ item }}</div>
          </el-carousel-item>
        </el-carousel>
      </div>
      <div class="asright">{{ timeStr }}</div>
    </div>
  </div>
</template>

<script>
import { dateFormat2 } from '@/utils/util.js'
import img0 from '@/assets/head8.png'
import img1 from '@/assets/head1.png'
import img2 from '@/assets/head2.png'
import { bigWaterGet } from '@/api/common.js'
export default {
  props: {
    swindex: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      img0,
      img1,
      img2,
      timeStr: '',
      timeId: null,
      info: {},
      tianqi: null
    }
  },
  computed: {
    // 用户信息
    userInfo() {
      return JSON.parse(localStorage.getItem('greemall_user'))
    }
  },
  watch: {
    $IpAdd: {
      handler(newVal, oldVal) {
        if (newVal?.city) {
          bigWaterGet({
            city: newVal.city
          }).then(res => {
            this.tianqi = res.data
            console.log(res.data)
          })
        }
      },
      deep: true,
      immediate: true
    }
  },
  mounted() {
    this.jishikaishi()
  },
  beforeUnmount() {
    this.timeId && clearInterval(this.timeId)
  },
  methods: {
    jishikaishi() {
      let date = new Date()
      this.timeStr = dateFormat2('YYYY-mm-dd HH:MM:SS WWW', date)
      this.timeId = setTimeout(this.jishikaishi, 1000)
    }
  }
}
</script>

<style scoped lang="scss">
::v-deep .el-carousel__arrow {
  display: none !important;
}
::v-deep .el-carousel__indicators {
  display: none !important;
}

.jajajaj {
  height: 24px;
  line-height: 24px;
  font-size: 20px;
  font-family: Source Han Sans CN, Source Han Sans CN-Regular;
  font-weight: 400;
  text-align: left;
  color: #34c7ff;
}

::v-deep .dv-scroll-board {
  background: none !important;

  .row,
  .row-item {
    background: none !important;
    height: 24px !important;
  }
}

.headview {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;

  .dierjibie {
    width: 100%;
    min-width: 1600px;
    height: 100%;
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
  }

  img {
    position: absolute;
    bottom: 0;
    width: 100%;
    min-width: 1600px;
    height: 58px;
  }

  .aszhongjianText {
    width: 400px;
    height: 35px;
    font-family: Source Han Sans CN;
    font-weight: 500 !important;
    font-size: 30px !important;
    color: #ffffff !important;
    line-height: 35px !important;
    text-align: center !important;
    z-index: 9999999999999999999;
  }
  .aszhongjian {
    text-align: center;
    width: 400px;
    height: 35px;
    background: linear-gradient(0deg, #ffffff 0%, #b0d7ff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    font-family: Source Han Sans CN;
    font-weight: 500 !important;
    font-size: 30px !important;
    color: #ffffff !important;
    line-height: 35px !important;
    text-align: center !important;
    z-index: 9999999999999999999;
  }

  .asleft {
    height: 24px;
    overflow: hidden;
    position: absolute;
    bottom: 12px;
    left: 160px;
  }

  .asright {
    font-size: 20px;
    font-family: Source Han Sans CN, Source Han Sans CN-Regular;
    font-weight: 400;
    text-align: left;
    color: #34c7ff;
    position: absolute;
    bottom: 12px;
    right: 160px;
  }
}
</style>
