<template>
  <div class="page-content tabbar-list">
    <div class="home-top" :class="isNight ? 'night' : ''">
      <div class="title">{{ tips }}</div>
      <div class="top-content">
        <van-image class="banner" src="/img/home-banner.jpg" alt="" />
        <div class="name">第一上海</div>
        <div class="welcome">数据管理系统欢迎您</div>
      </div>
    </div>
    <van-grid :column-num="4" :border=false>
      <van-grid-item v-if="userInfo.roleId === '10' || userInfo.roleId === '1'" class="btn"
        @click="$router.push({ name: 'organization-list' })">
        <div class="icon-box organization"><van-icon name="newspaper-o" size="24" /></div>
        <span>机构</span>
      </van-grid-item>
      <van-grid-item class="btn" @click="$router.push({ name: 'meeting-list' })">
        <div class="icon-box meeting"><van-icon name="calendar-o" size="24" /></div>
        <span>会议</span>
      </van-grid-item>
      <van-grid-item class="btn" @click="$router.push({ name: 'communicate-list' })">
        <div class="icon-box communicate"><van-icon name="comment-o" size="24" /></div>
        <span>沟通</span>
      </van-grid-item>
      <van-grid-item class="btn" @click="$router.push({ name: 'comment-list' })">
        <div class="icon-box comment"><van-icon name="diamond-o" size="24" /></div>
        <span>点评</span>
      </van-grid-item>
      <van-grid-item class="btn" @click="$router.push({ name: 'report-list' })">
        <div class="icon-box report"><van-icon name="description-o" size="24" /></div>
        <span>报告</span>
      </van-grid-item>
      <van-grid-item class="btn" @click="$router.push({ name: 'target-table' })">
        <div class="icon-box cash"><van-icon name="guide-o" size="24" /></div>
        <span>指标</span>
      </van-grid-item>
    </van-grid>
    <div class="card">
      <div class="card-title">今日沟通</div>
      <communicate-item :list="communicateList" />
    </div>
    <tabbar />
  </div>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue'
import userInfoStore from '@/stores/userInfo'
const userInfo = userInfoStore()
const time = moment().hour()
const isNight = computed(() => time < 6 || time >= 22)
const tips = computed(() => {
  if (time < 6 || time >= 22) {
    return '夜深了，早点休息'
  } else if (time >= 19) {
    return `晚上好，${userInfo.realname}`
  } else if (time >= 12) {
    return `下午好，${userInfo.realname}`
  } else {
    return `早上好，${userInfo.realname}`
  }
})
import { cusLinkList } from '@/utils/api'
import { convertToUrl } from '@/utils'
import moment from 'moment'
const isLogin = computed(() => !!userInfo.token)
const communicateList = ref([])
const getCusLink = async () => {
  if (!isLogin.value) return
  const url = convertToUrl({
    limit: 3,
    curPage: 1,
    dateBegin: moment().format('YYYY-MM-DD')
  })
  const data = await cusLinkList(url)
  communicateList.value = data
}
getCusLink()
import { workMeetingList } from '@/utils/api'
const meetingList = ref<Array<any>>([])
const getMeetingList = async () => {
  if (!isLogin.value) return
  const url = convertToUrl({
    dateBegin: moment().format('YYYY-MM-DD'),
    dateEnd: moment().format('YYYY-MM-DD'),
    meetingType: '1,2,3,16,17,4,5,15,6,10,11,12,13,14,7'
  })
  const { data } = await workMeetingList(url)
  meetingList.value = data.slice(0, 3)
}
getMeetingList()
</script>

<style lang="scss" scoped>
.night {
  background-image: url('/img/night.png');
  background-repeat: no-repeat;
  padding-top: 30px;
  color: #fff;
}
.home-top {
  padding: 20px 10px 0;
  .top-content {
    height: 120px;
    z-index: 3;
    position: relative;
    @media screen and (min-width: 678px) {
      height: 160px;
    }
  }
  .title {
    font-size: 16px;
    margin-bottom: 20px;
    font-weight: 600;
  }
  .name {
    padding-top: 30px;
    font-size: 18px;
    color: #fff;
    margin-left: 20px;
  }
  .welcome {
    font-size: 14px;
    color: #eee;
    margin-left: 40px;
    margin-top: 10px;
  }
  .banner {
    border-radius: 6px;
    width: 100%;
    position: absolute;
    border-radius: 6px;
    overflow: hidden;
    z-index: -1;
    top: 0;
    bottom: 0;
    left: 0;
  }
  
}
.btn {
  text-align: center;
  font-size: 13px;
  transition: all 0.2s ease;
  &:active {
    transform: scale(0.95);
    opacity: 0.8;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  }
  
  .icon-box {
    width: 36px;
    height: 36px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    margin-bottom: 4px;
  }
  .organization {
    background-color: #ff8f00;
  }
  .meeting {
    background-color: #a3cf7d;
  }
  .communicate {
    background-color: #ffc700;
    padding-top: 2px;
  }
  .comment {
    background-color: #ff758f;
  }
  .report {
    background-color: #5bb1ff;
  }
  .cash {
    background-color: #f15b6c;
  }
}
.card {
  padding: 10px 0;
  // margin-top: 10px;
  margin: 10px 12px;
  .card-title {
    margin-left: 16px;
    padding: 0 4px;
    font-weight: 600;
    border-left: 4px solid #5bb1ff;
    margin-bottom: 10px;
    font-size: 16px;
  }
}
.empty {
  color: #808080;
  font-size: 14px;
  text-align: center;
}
:deep(.van-empty__image) {
  width: 80px;
  height: 80px;
}
</style>