<template>
	<view class="content">
		<view class="newshead">{{ newsInfo.title }}</view>
		<text class="time textgrey">{{ newsInfo.create_time }}</text>
		<view v-if="type == 20" class="u-content">
			<view @click="down(item)" class="dffd" v-for="(item, ind) in newsInfo.files_url" :key="ind">{{ item }}</view>
			<image :src="newsInfo.img" mode="widthFix"></image>
		</view> 
		<view class="newsCon"><u-parse :content="newsInfo.content"></u-parse></view>
		<view v-if="type == 10" class="u-content"><u-parse :content="newsInfo.hide"></u-parse></view>
		<view v-if="type == 11" class="u-content"><u-parse :content="newsInfo.service"></u-parse></view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			id: '',
			type: '', //
			newsInfo: {},
			talkList: [], //图文分享老师点评
			fbText: ''
		};
	},
	onLoad(opt) {
		this.id = opt.id;
		this.type = opt.type; // 10.隐私，11服务协议 1=新闻信息 2公告详情  20联盟课件 30图文分享
		if (this.type == 10) {
			uni.setNavigationBarTitle({
				title: '隐私协议'
			});
		} else if (this.type == 11) {
			uni.setNavigationBarTitle({
				title: '服务政策'
			});
		} else if (this.type == 2) {
			uni.setNavigationBarTitle({
				title: '公告详情'
			});
		} else if (this.type == 20) {
			uni.setNavigationBarTitle({
				title: '课件详情'
			});
		} else if (this.type == 30) {
			uni.setNavigationBarTitle({
				title: '图文分享详情'
			});
		}
		this.loading(this.id);
	},
	onShow() {},
	methods: {
		toFuba() {
			if (!this.fbText) return this.$api.toast('请输入发布内容');
			this.$api
				.request('study/evaluate', {
					login_token: this.token(),
					id: this.id,
					content: this.fbText
				})
				.then(data => {
					this.fbText = '';
					if (data.code == 200) {
						this.$api.toast(data.msg);
						setTimeout(res => {
							this.loading();
						}, 600);
					} else {
						this.$api.toast(data.msg);
					}
				})
		},
		loading() {
			let url = '';
			let data = {};
			if (this.type == 10 || this.type == 11) {
				url = 'common/getAgreement';
			} else if (this.type == 1) {
				url = 'news/getNewsInfo';
				data = { 
					id: this.id
				};
			} else if (this.type == 2) {
				url = 'index/noticeInfo';
				data = { 
					id: this.id
				};
			}
			this.$api
				.request(url, data )
				.then(data => {
					if (data.code == 200) {
						// if (this.type == 1||this.type == 2) {
						// 	let content = data.data.content.replace(/<img [^>]*src=['"]/g, '<img style="width:100%;height:auto;max-width:750rpx;border-radius: 6rpx" src="' + this.$api.imgurl());
						// 	data.data.content = content;
						// }
						this.newsInfo = data.data;
					} else {
						this.$api.toast(data.msg);
					}
				})
		}
	}
};
</script>

<style lang="scss">
.content {
	min-height: 100vh;
	padding: 32rpx 30rpx 120rpx;
	background-color: #fff;
	.newshead {
		font-size: 36rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 600;
		line-height: 58rpx;
		margin-bottom: 8rpx;
	}
	.time {
		line-height: 40rpx;
	}
	.newsCon {
		margin-top: 30rpx;
		line-height: 42rpx;
		font-size: 30rpx;
	}
	.talkBox {
		border-top: 1rpx solid #ececec;
		margin-top: 30rpx;
		padding: 30rpx 0 0;
		.title {
			font-size: 28rpx;
		}
		.leRiBox {
			.left {
				width: 76rpx;
				height: 76rpx;
				margin-right: 24rpx;
				border-radius: 50%;
			}
			.right {
				padding: 30rpx 0;
				flex: 1;
				.tigTop {
					font-family: PingFangSC-Semibold, PingFang SC;
					font-weight: 600;
					line-height: 44rpx;
					text {
						font-size: 26rpx;
						color: #999999;
						line-height: 36rpx;
						flex: 1;
						font-weight: 400;
						margin: 0 20rpx;
					}
					image {
						width: 44rpx;
						height: 44rpx;
					}
				}
				.cont {
					margin-top: 12rpx;
					font-size: 28rpx;
					color: #333333;
					line-height: 40rpx;
				}
			}
		}
	}
	.fixBox {
		.editicon {
			position: absolute;
			left: 60rpx;
			width: 40rpx;
			height: 40rpx;
			padding: 3rpx;
		}
		input {
			flex: 1;
			font-size: 28rpx;
			height: 76rpx;
			background: #f6f6f6;
			border-radius: 38rpx;
			padding: 0 30rpx 0 78rpx;
		}
		.share {
			margin-left: 30rpx;
			width: 40rpx;
			height: 40rpx;
		}
	}
}
</style>
