<template>
	<view class="content">

		<!-- 导航 -->
		<view class="nav">
			<view class="leftView" @click="back">
				<image src="../../static/mobile/backBtn.png" mode=""
					style="width: 22rpx; height: 40rpx; padding-left: 24rpx;"></image>
			</view>
			<view class="navTitle">详情</view>
			<view class="rightView">

			</view>
		</view>

		<!-- content -->

		<view class="top">{{detailData.title}}</view>
		<view class="time">{{detailData.createTime}}</view>




		<!-- <rich-text :nodes="couContent"></rich-text> -->

		<view class="html" v-html="detailData.contents"></view>

		
		<!-- item -->

		<view class="itemBg" v-if="itemArr.length != 0">
			<view v-for="(item,index) in itemArr" :key="index" class="twoItem"
				:class="{grayLine:index < itemArr.length-1}">
				<view class="itemLeftView">
					<image src="../../static/mobile/icon_fujian.png" mode="" class="img2"></image>
					<view class="title" @click="goUrl(item.fileUrl)" >{{item.fileName}}</view>
					<!-- <a class="title" :href='item.fileUrl'>{{item.fileName}}</a> -->
				</view>


				
				
			</view>
		</view>

		<view style="display: flex;">
			<view class="category">{{detailData.parentName}}</view>
		</view>


		<view class="gotop" @click="gotoTop">
			<image src="../../static/pcimg/btn_top@2x.png" mode="" class="gotopImg"></image>
		</view>

	</view>
</template>

<script>
	
	export default {
		
		data() {
			return {
				id: '',
				detailData: {},
				couContent: '',
				itemArr: [],
				
			}
		},
		onLoad(opt) {
			console.log('opt', opt);
			this.id = opt.id

			this.getDetailData()
			// uni.setNavigationBarTitle({
			// 	title: this.topName
			// })
			
		},
		methods: {
			goUrl(url){
				console.log('url',url);
				window.location.href = url

			},
			
			gotoTop() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 300
				});
			},
			

			
			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('contents1111',this.detailData.contents);
					
					if (this.detailData.contents) {
						var replaceStr = "application/x-shockwave-flash"
						this.detailData.contents = this.detailData.contents.replace(new RegExp(replaceStr, 'gm'),
							'iframe') //(/''/g,"video/webm")
						this.detailData.contents = this.detailData.contents.replace(/<embed([\s\w"-=\/\.:;]+)/ig,
							'<iframe style="width: 100%;height:300px;" $1');
							
						this.detailData.contents = this.detailData.contents.replace(/<iframe([\s\w"-=\/\.:;]+)/ig,
							'<iframe style="width: 100%;height:300px;" $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: 15px; line-height: 25px;">')
							.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');
					}

				console.log('contents',this.detailData.contents);
					this.itemArr = this.detailData.fileList

				})
			},

			back() {
				uni.navigateBack({

				})
			},




			// // 下拉刷新 上拉加载更多
			// onPullDownRefresh() {
			// 	this.page = 1;
			// 	this.getItemData()

			// 	this.getDetailData()
			// 	setTimeout(function() {
			// 		uni.stopPullDownRefresh();
			// 	}, 1000);
			// },
			// onReachBottom() {
			// 	this.page++;

			// 	this.getItemData()

			// }
		}
	}
</script>

<style scoped>
	.content {
		min-height: 100vh;
		background-color: #FFFFFF;
		padding-top: 88rpx;
		padding-bottom: 10rpx;
		margin: 0 24rpx;
	}

	.nav {
		position: fixed;
		left: 0;
		top: 0;
		width: 100vw;
		height: 88rpx;
		background-color: #FFFFFF;
		display: flex;
		justify-content: space-between;
		align-items: center;
		z-index: 999;
		border-bottom: #eeeeee 2rpx solid;
	}

	.navTitle {
		font-size: 36rpx;
		font-weight: bold;
		color: #3c3c3c;
		text-align: center;
	}

	.leftView {
		width: 30%;
	}


	.rightView {
		width: 30%;
		display: flex;
		justify-content: flex-end;
		padding-right: 24rpx;
	}

	.rightImg {
		width: 40rpx;
		height: 40rpx;

	}



	.top {
		background-color: #FFFFFF;

		padding-top: 40rpx;

		font-weight: bold;
		color: #3c3c3c;
		font-size: 32rpx;
		text-align: left;

	}

	.time {

		font-size: 24rpx;
		color: #999999;


		padding-top: 15rpx;
		padding-bottom: 30rpx;
		border-bottom: #EEEEEE 2rpx solid;
	}


	.html {
		padding-top: 18px;
	}

	.html img {
		width: 100% !important;
	}

	.itemBg {

		background-color: #FFFFFF;
		border-radius: 10rpx;
		border: #eeeeee 1rpx solid;
	}

	.twoItem {
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #FFFFFF;
		margin: 0 15rpx;
		padding-top: 24rpx;
		padding-bottom: 30rpx;

	}

	.grayLine {
		border-bottom: #EEEEEE 1rpx solid;
	}

	.itemLeftView {
		display: flex;
		align-items: center;
		width: 100%;
	}

	.title {
		font-size: 28rpx;
		color: #333333;
		width: 100%;
		word-break: break-all;
	}

	.title2 {

		background-color: #3F90F7;
		border-radius: 6rpx;
		width: 90rpx;
		height: 52rpx;
		line-height: 52rpx;
		text-align: center;
		margin-right: 15rpx;

	}

	.table-btn {
		color: #FFFFFF;
		font-size: 26rpx;
		text-decoration: none;
	}


	.img2 {
		width: 28rpx;
		height: 28rpx;
		margin-right: 6rpx;
	}

	.category {
		background: rgba(63, 144, 247, 0.1);
		font-size: 22rpx;
		color: #3F90F7;
		height: 36rpx;
		line-height: 36rpx;
		border-radius: 18rpx;
		padding: 3rpx 14rpx;
		min-width: 0;
		max-width: 138rpx;
		margin-bottom: 10rpx;
		text-align: center;
		margin: 30rpx 0;
		/* 隐藏文字显示 ...不换行 */
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.gotopImg {
		width: 100rpx;
		height: 100rpx;
	}

	.gotop {
		position: fixed;
		right: 15rpx;
		bottom: 50rpx;
		cursor: pointer;
		z-index: 999;
	}
</style>
