<template>
	<view style="background-color: #fff;">
		<ujp-navbar title="文章详情"></ujp-navbar>
		<view class="main">
			<view class="new-title oldTextjp" oldstyle="font-size: 22px;">
				{{newsDetail.title}}
			</view>
			<view class="time">
				<view class="time-left">
					{{newsDetail.createTime}}
				</view>
				<view class="time-tight">
					<text class="iconfont">&#xe612;</text><text class="num">{{newsDetail.readNum}}</text>
				</view>
			</view>
			<view class="news-content" v-html="newsDetail.content"></view>
		</view>
	</view>
</template>

<script>
	import * as newsApi from '@/apis/news.js'
	
	export default {
		data() {
			return {
				id: '',
				newsDetail: {},
				elderStatus: false,
				myFontSize: 0,
			}
		},
		onLoad(op) {
			if(this.carhelp.get("getElderModeClass") == "长辈模式") {
				this.elderStatus = true;
			} else {
				this.elderStatus = false;
			}
			
			this.id =op.id;
			this.getNewsInfoDetail();
		},
		methods: {
			getNewsInfoDetail() {
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				
				newsApi.newsInfoDetail(this.id).then((res) => {
					uni.hideLoading()					
					this.newsDetail = res.data;
					
					if(this.elderStatus) {
					
						this.myFontSize=16;
						
						var key1="font-size"
						var key2="font-size:"+this.myFontSize+"px  ; "
						
						var reg=new RegExp(key1,'gi')
						var content=this.newsDetail.content.replace(reg,key2)
						
						this.newsDetail.content=content;
												
					}
					
					
					this.$nextTick(()=>{
					    var list =document.getElementsByClassName("news-content")[0].getElementsByTagName("img");
					    for(var i=0;i<list.length;i++){
					        list[i].style='width: 100%;height: 100%;'
					    } 
					})
				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
			}
		}
	}	
</script>

<style lang="scss" scoped>
	
	
	.main{
		
		margin: 0px 16px ;
		padding-bottom: 34px;
		.new-title{
			color: #101010;
			font-size: 18px;
			height: 48px;
			margin: 16px 0 35px;
		}
		.time{
			display: flex;
			justify-content: space-between;
			color: #888888;
			.num{
				margin-left: 4px;
			}
			
		}
		.news-content{
			// margin-top: 13px;
			// font-size: 14px;
			padding-top: 8rpx;
			::v-deep  img{
				//	margin: -6rpx auto;
					 display: block;
			}
		
			// color: #101010;
		}
	}
</style>