<template>
	<view class="news" :style="{ 'height': setHeight + 'px' }">
		<view class="title">{{news.title}}</view>
		<view class="time">{{news.time | formatDate}}</view>
		<rich-text :nodes="news.content"></rich-text>
	</view>
</template>

<script>
	import {
		newsDetail
	} from '@/api/api.js';
	export default {
		data() {
			return {
				id: 0,
				news: {},
				setHeight: 0
			}
		},
		//时间戳的处理
		filters: {
			formatDate: function(value) {
				var date = new Date();
				var month = date.getMonth() + 1;
				var hours = date.getHours();
				if (hours < 10)
					hours = "0" + hours;
				var minutes = date.getMinutes();
				if (minutes < 10)
					minutes = "0" + minutes;
				var time = date.getFullYear() + "-" + month + "-" + date.getDate() +
					" " + hours + ":" + minutes;
				return time;
			}	 
		},
		mounted() {
		    let that = this
		    uni.getSystemInfo({
				success: function (res) {
					that.setHeight = res.windowHeight
				}
		    })
		},
		onLoad(options) {
			this.id = options.id;
			this.getNewsDetail();
		},
		methods: {
			getNewsDetail: function() {
				let that = this;
				newsDetail({id:that.id}).then(res => {
					that.news = res.data;
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.news{
		background: #fff;
		padding: 30rpx;
		color:#333;
	}
	.title{
		font-size: 32rpx;
		margin-bottom: 10rpx;
		font-weight: bolder;
	}
	.time{
		color:#999;
		margin-bottom: 20rpx;
	}
</style>