<template>
	<z-paging :refresher-enabled="false" :show-loading-more-when-reload="true" loading-more-default-text=""
		loading-more-loading-text="" loading-more-fail-text="" :empty-view-text="t('common.noData')"
		:show-loading-more-no-more-view="false" ref="paging" v-model="dataList" @query="queryList"
		class="max-w-[750px]">
		<h-dark :title="t('notice.title')"></h-dark>
		<view class="mx-[30rpx] mt-[20rpx]">
			<view class="mb-[20rpx] " v-for="item,index in dataList" :key="item.id"
				@click="handleJump('/pages/notice/detail?id='+item.id,index)">
				<view class="bg-[#2C326B] p-[30rpx] rounded-lg relative">
					<view class="text-[#E72A2A] absolute right-[30rpx] top-[30rpx]" v-if="item.read==0">
						●
					</view>
					<view class="font-bold mb-[30rpx]">
						{{item.title}}
					</view>
					<view class="content leading-normal mb-[30rpx] text-[#F7F7F7]" v-html="item.content">
					</view>

					<view class="text-[#F7F7F7]">
						{{item.create_time}}
					</view>
				</view>
			</view>
		</view>
	</z-paging>
</template>

<script lang="ts" setup>
	import { shallowRef, ref } from 'vue'
	import { getUserNoticeLists } from '@/api/user'
	import { t } from '@/utils/util'
	uni.setNavigationBarTitle({ title: t('notice.title') })

	const paging = shallowRef()
	const dataList = ref<any[]>([])

	const queryList = async (pageNo : number, pageSize : number) => {
		try {
			const data = await getUserNoticeLists({
				page_no: pageNo,
				page_size: pageSize,
			})
			paging.value.complete(data.lists)
		} catch (error) {
			paging.value.complete(false)
		}
	}
	const handleJump = async (val : string, index : number) => {
		dataList.value[index]['read'] = 1;
		uni.navigateTo({
			url: val
		})
	}
</script>

<style lang="scss">
	.content {
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 3;
		overflow: hidden;
		text-overflow: ellipsis;
	}
</style>