<template>
	<view class="content">
        <pcNav></pcNav>
        <view style="height: 72rpx;"></view>
		<view class="top">
			<view class="topline" @click="goIndex">首页</view>
			<view class="topjt">></view>
			<view class="topline" @click="goList()">{{topName}}</view>
			<view class="topjt" v-if="twoName">></view>
			<view class="topline" :class="{'c999':twoName}">{{twoName}}</view>
		</view>
		<view class="htmlBox">
			<view class="htmlTitle">{{detailData.name}}</view>
			<view class="time">{{detailData.publishTime}}</view>
			<view class="html" v-html="detailData.contents"></view>
		</view>
		<view class="itemArr" v-if="itemArr.length>0">
		  <view class="itemArrLine" v-for="(item,index) in itemArr">
			  <view class="itemArrLeft" >
				  <image src="../../static/pcimg/icon_fujian@2x.png" mode="" class="fileIcon"></image>
				  <view class="fileName" @click="gofile(item.fileUrl)">{{item.fileName}}</view>
			  </view>
			<!-- <view class="dload">
				  <a class="dloadbtn" :href="item.fileUrl" target='_blank' >下载</a>
			  </view> -->
		  </view>
		</view>
		<view class="lbel">
			<view class="topName">{{topName}}</view>
		</view>
        <view style="height: 100rpx;width: 1800rrpx;background-color: red;"></view>
	</view>
</template>

<script>
	import pcNav from '../../components/pcNav/pcNav.vue'
	export default {
        components: {
        	pcNav,
        },
		data() {
			return {
				id: '',
				detailData: {},
				couContent: '',
				itemArr: [],
				topName:'',
				twoName:'',
				comment:'',
				parentCode:'',
			}
		},
		onLoad(opt) {
			console.log('opt', opt);
			this.id = opt.id
            this.topName=opt.topName;
			this.twoName=opt.twoName;
			this.comment=opt.comment;
			this.parentCode=opt.parentCode
			this.getDetailData()
			// uni.setNavigationBarTitle({
			// 	title: this.topName
			// })
		},
		methods: {
			gofile(url){
				window.location.href=url
			},
			goList(){
				uni.navigateTo({
					url:'list?code='+this.parentCode+'&topName='+this.topName+'&comment='+this.comment
				})
			},
             goIndex(){
					uni.navigateTo({
						url:'index'
					}) 
			 },
			getDetailData() {
				uni.showLoading({
					title: '加载中'
				})
				let url = '/trainingOpenApi/articleDetail',
					params = {
						id: this.id,
					}
				this.$http(url, params, 'GET').then(res => {
					uni.hideLoading();
					var data = res.data
					// 处理 undefined和null转为空白字符串
					for (const key in data) {
						data[key] = this.$praseStrEmpty(data[key])
					}

					this.detailData = data;
					console.log()
					if (this.detailData.contents) {
						var replaceStr = "application/x-shockwave-flash"
					    this.detailData.contents=this.detailData.contents.replace(new RegExp(replaceStr,'gm'),'video/webm')//(/''/g,"video/webm")
					    this.detailData.contents=this.detailData.contents.replace(/<embed([\s\w"-=\/\.:;]+)/ig, '<embed style="width: 100%;height:500rpx;" $1');
					}

					 if (this.detailData.contents) {
						this.detailData.contents = this.detailData.contents.replace(
								/<p([\s\w"=\/\.:;]+)((?:(style="[^"]+")))/ig, '<p')
							.replace(/<p>/ig, '<p style="font-size: 15rpx; line-height: 25rpx;">')
							.replace(/<img([\s\w"-=\/\.:;]+)((?:(height="[^"]+")))/ig, '<img$1')
							.replace(/<img([\s\w"-=\/\.:;]+)((?:(width="[^"]+")))/ig, '<img$1')
							.replace(/<img([\s\w"-=\/\.:;]+)((?:(style="[^"]+")))/ig, '<img$1')
							.replace(/<img([\s\w"-=\/\.:;]+)((?:(alt="[^"]+")))/ig, '<img$1')
							.replace(/<img([\s\w"-=\/\.:;]+)/ig, '<img style="width: 100%;" $1');
					}

					this.itemArr = this.detailData.fileList 
                    console.log(this.itemArr)
				})
			},

			


			// }
		}
	}
</script>

<style scoped>
	.top{
		width: 1200rpx;
		margin: 0 auto;
		display: flex;
		padding: 30rpx 0;
		font-size: 14rpx;
	}
	.htmlBox{
		width: 720rpx;
		margin: 0 auto;
	}
	.topline{
		padding-right: 10rpx;
		cursor: pointer;
		color: #3C3C3C;
	}
	.topjt{
		color: #AAAAAA;
		padding-right: 10rpx;
	}
	.htmlTitle{
		font-size: 24rpx;
		font-weight: 500;
		color: #3C3C3C;
		line-height: 33rpx;
	}
	.time{
		font-size: 14rpx;
		padding-top: 16rpx;
		color: #999999;
		line-height: 20rpx;
		border-bottom: 1rpx solid #EEEEEE;
		padding-bottom: 19rpx;
	}
	.html{
		padding-top: 18rpx;
	}
	.fileIcon{
		width: 14rpx;
		height: 14rpx;
		margin-top: 4rpx;
		margin-right: 4rpx;
	}
	.itemArrLeft{
		display: flex;
	}
	.itemArrLine{
		display: flex;
		justify-content: space-between;
		padding: 16rpx 0;
		border-bottom: 1rpx solid #EEEEEE;
		color: #333333;
		line-height: 22rpx;
		font-size: 16rpx;
		width: 720rpx;
	}
	.itemArr{
		width: 720rpx;
		margin: 0 auto;
		margin-top: 30rpx;
		border-radius: 6rpx;
		border: 1rpx solid #EEEEEE;
		padding: 0 16rpx;
		
	}
	.dloadbtn{
		display: block;
		width: 68rpx;
		height: 28rpx;
		background: #3F90F7;
		border-radius: 6rpx;
		color: #FFFFFF;
		text-align: center;
		line-height:28rpx ;
		font-size: 14rpx;
		text-decoration:none;
	}
	.lbel{
		width: 720rpx;
		margin: 0 auto;
		margin-top: 30rpx;
		padding-bottom: 30rpx;
	}
	.topName{
		width: 84rpx;
		height: 24rpx;
		background: rgba(63, 144, 247, 0.1);
		border-radius: 14rpx;
		font-size: 12rpx;
		color: #3F90F7;
		line-height: 24rpx;
		text-align: center;
	}
	.fileName{
		text-decoration:underline;
		color: #3F90F7;
	}
	.c999{
		color: #999999;
	}
</style>
