<template>
  <div>
    <div class="textBox">
      <transition name="slide">
        <p class="text" :key="text.id" @click="hreftwo">{{(text.val)}}</p>
      </transition>
    </div>
  </div>
</template>

<script>
import './index.less'
import { releaseNoticeList } from '@/api/mainv3'
export default {
  name: 'TransitionNotice',
  components: {
  },
  props: {
    noticeList: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data () {
    return {
      number: 0,
      textArr: []
    }
  },
  computed: {
    text () {
      return {
        id: this.number,
        val: this.textArr[this.number]
      }
    }
  },
  methods: {
    hreftwo () {
      this.$router.push({ path: '/message' })
    },
    startMove () {
      // eslint-disable-next-line
      let timer = setTimeout(() => {
        if (this.number === this.textArr.length) {
          this.number = 0
        } else {
          this.number += 1
        }
        this.startMove()
      }, 2500) // 滚动不需要停顿则将2000改成动画持续时间
    },
    getNoticeList () {
      this.textArr = []
      releaseNoticeList({}).then(res => {
        if (res.data.errcode === 0) {
          this.adList = []
          for (var i = 0; i < res.data.data.length; i++) {
            this.textArr.push('公告：' + res.data.data[i].title)
          }
        } else {
          this.$Notice.error({ title: '获取公告列表失败', desc: res.data.errmsg })
        }
      })
    }
  },
  mounted () {
    this.startMove()
    this.getNoticeList()
  }
}
</script>
