<template>
  <view
    class="Mall4j message-play component-notice"
    @tap="onNewsPage"
  >
    <image
      src="@/static/images/horn.png"
      class="hornpng"
    />
    <swiper
      vertical="true"
      autoplay="true"
      duration="1000"
      circular="true"
      class="swiper-cont"
    >
      <block
        v-for="(item, id) in news"
        :key="id"
      >
        <swiper-item class="items">
          {{ item.title }}
        </swiper-item>
      </block>
    </swiper>
    <text class="arrow" />
  </view>
</template>

<script setup>
import util from '@/utils/util'

const props = defineProps({
  fieldData: {
    type: Object,
    default: () => ({})
  },
  shopId: {
    type: [Number, String],
    default: 0
  },
  will: {
    // 需要获取的类型 默认首页
    type: String,
    default: 'home' // home 首页 ，feature 微页面  传 化名ID , goods 商品详情页，传商品ID ,ad 公共广告
  }
})

const news = ref([])

onMounted(() => {
  getNoticeList()
})

const getNoticeList = () => {
  // 加载公告
  http.request({
    url: '/tmerclub_admin/ma/notice',
    method: 'GET',
    data: {
      shopId: props.shopId,
      pageNum: 1,
      pageSize: 10
    }
  }).then((res) => {
    for (let i = 0; i < res.list.length; i++) {
      const element = res.list[i]
      element.content = util.formatHtml(element.content)
    }
    news.value = res.list
  })
}

// 跳转公告列表页面
const onNewsPage = () => {
  uni.navigateTo({
    url: props.shopId === 0 ? '/pages/message-platform/message-platform?tabType=1&ishiddenTab=1' : `/package-shop/shop-page/notice-list/notice-list?shopId=${props.shopId}`
  })
}

</script>
<style lang="scss" scoped>
@use "index";
</style>
