<template>

  <!-- <div class="noticTitle" v-if="noticData.length > 0">
    <div style="display: flex;" @click="handleNotic">
      <el-icon style="margin-top: 7px;">
        <Bell />
      </el-icon>
      <div style="padding-left: 8px;">{{noticTitleValue}}</div> 
    </div>
  </div> -->
  <div>
    <jssip-miao/> 
    <service-report v-if="showRoles === 2"></service-report>
    <follow-up-report v-if="showRoles === 1"></follow-up-report>
  </div>
  <el-dialog v-model="dialogVisible" @close="handleClose" title="公告详情" width="50%">
    <div style="width: 90%; margin: 0 auto;">
      <div style="text-align: center; font-size: 22px; margin: 15px 0px;">{{noticObj.noticeTitle}}</div>
      <div style="text-align: center; font-size: 14px; margin: 15px 0px;">创建时间：2024-04-16 00:00:00</div>
      <div style="text-indent: 2em; font-size: 16px; margin: 15px 0px;" v-html="noticObj.noticeContent"></div>
    </div>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="dialogVisible = false">
          确定
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
  import { onMounted, ref } from 'vue'
  import serviceReport from './cpns/serviceReport'; // 话务报表
  import followUpReport from './cpns/followUpReport'; // 随访报表
  import { getIndexData, getEchatsData } from '@/api/main/system/menu'
  import moment from 'moment' 
  import useUserStore from '@/store/modules/user'
  import useSystemStore from '@/store/main/system/system'
  import { createPageData,getPageListData } from '@/api/main/system/system';

  const { proxy } = getCurrentInstance();
  const userStore = useUserStore()
  const configStore = useSystemStore()
  const showRoles = ref(2)
  
  if (configStore && configStore.systemConfig) {
    const roles = (configStore.systemConfig['sys.home.config'] || {}).configValue;
    if (roles && roles.split(';').some(item => userStore.roles.includes(item))) showRoles.value = 1;
  }
  // if (useUserStore === 'bmzg')

  const dialogVisible = ref(false)
 

  onMounted(() => {
    getIndexnoticelist()
  })
  // 公告
  const noticData = ref([])
  const noticTitleValue = ref('公告')
  const noticObj = ref({})
  const noticNum = ref(0)
  let noticSetInterval
  function handleClose() {
    noticCarousel()
  }
  function handleNotic() {
    dialogVisible.value = true
    readlist()
    if (noticSetInterval) {
      clearInterval(noticSetInterval)
    }
  }
  function readlist() {
    const params = {
      noticeId : noticObj.value.noticeId,
      noticeType : noticObj.value.noticeType,
    }
    createPageData('/system/readlist',params).then((data) => {
            proxy.$modal.msgSuccess('已读');
      })
  }
  function noticCarousel() {
    if (noticSetInterval) {
      clearInterval(noticSetInterval)
    }
    noticSetInterval = setInterval(() => {
      noticNum.value ++
      if (noticNum.value >= noticData.value.length) {
        noticNum.value = 0
      }
      noticTitleValue.value = noticData.value[noticNum.value].noticeTitle
      noticObj.value = noticData.value[noticNum.value]
    }, 3000)
  }
  
  // 公告列表
  function getIndexnoticelist() {
    getPageListData("/system/notice/indexnoticelist").then((res) => {
      noticData.value = []
      if (res.data.length>0) {
        noticData.value = res.data
        noticTitleValue.value = noticData.value[0].noticeTitle
        noticObj.value = noticData.value[0]
        noticCarousel()
      }
    })
  }
  // 公告结束



</script>

<style scoped lang="scss">
  .noticTitle {
    height: 30px;
    margin: 20px 20px 20px 20px;
    line-height: 30px;
    padding-left: 15px;
    background: #faecd8;
    color: #b88230;
    border-radius: 5px;
  }

  .login {
    margin: 10px;
    padding: 10px;

    width: calc(100% - 20px);
    height: calc(100vh - 84px - 20px);
    background-image: url('@/assets/images/login-background.png');
    background-size: cover;
    border-radius: 10px;
  }

  .index {
    margin: 10px;
    padding: 10px;

    width: calc(100% - 20px);
    height: calc(100vh - 84px - 20px - 70px);
    background-color: rgb(210, 217, 231);
    border-radius: 10px;

    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1px 1fr 2fr;
    row-gap: 10px;
    grid-auto-flow: column;



    >div:nth-child(1) {
      font-size: 25px;
      line-height: 40px;
    }

    >div:nth-child(n + 2) {
      background-color: #fff;
      border-radius: 5px;
    }

    >div:nth-child(1) {
      grid-column: span 2;
    }

    >div:nth-child(2) {
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      place-items: center;
      column-gap: 5px;

      >div {
        justify-self: stretch;
        text-align: center;

        >div {
          margin-bottom: 20px;
        }

        >div:nth-child(1) {
          font-size: 20px;
          font-weight: 700;
          font-family: sans-serif;
          color: #3f3f3f;
        }

        >div:nth-child(2) {
          font-size: 50px;
          font-weight: 700;
          font-family: sans-serif;
        }

        >div:nth-child(3) {
          margin-top: 35px;
          font-size: 13px;
          color: #a4a4a4;
        }
      }
    }

    >div:nth-child(3) {
      box-sizing: border-box;

      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
</style>