<template>
	<view>
		<view class="xw_content" v-for="(item,index) in newsList" :key="index" @click="clickNews(item)">
			<u--image :src="imgUrl+item.cover" width="192rpx" height="122rpx" :lazy-load="true">
			</u--image>
			<view class="xw_right">
				<view class="xw_title">
					{{item.title}}
				</view>
				<view style="display: flex;">
					<text class="xw_time">
						{{item.pub_time_str}}
					</text>
					<text class="xw_time xw_place">
						{{item.pub_name}}
					</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		dateFormat
	} from '../../utills/date.js'
	export default {
		data() {
			return {
				imgUrl: '',
				newsList: [],
			}
		},
		created() {
			this.imgUrl = uni.getStorageSync('img_url')
			this.getNews()
		},
		methods: {
			getNews() {
				this.$apiServe.getNews({
					pageSize: 3,
					pageNum: 1
				}).then(res => {
					let newsData = res.data.data
					console.log('新闻', newsData);
					if (newsData) {
						for (const item of newsData) {
							item.pub_time_str = dateFormat(item.pub_time_str)
						}
						// newsData = newsData.slice(0, 3)
						this.newsList = newsData
					}

				}).finally(_ => {})
			},
			// 跳转到新闻详情页
			clickNews(item) {
				uni.navigateTo({
					url: '../../packageReport/newsDetail/newsDetail?id=' + item.id
				})
			},
		}
	}
</script>
