<template>
	<view>
		<view class="lf-m-l-32 lf-m-r-32">
			<view>
				<view class="lf-font-32 lf-color-333 lf-m-t-30 lf-m-b-20">
					{{title_content.title}}
				</view>
				<view class="lf-flex lf-m-b-24">
					<view class="lf-color-999 lf-font-24" v-if="title_content.updated_at">
						发布于<text class="lf-m-l-10">{{title_content.updated_at}}</text>
					</view>
					<view class="lf-color-999 lf-font-24 lf-m-l-30" v-if="title_content.author">
						作者<text class="lf-m-l-10">{{title_content.author}}</text>
					</view>
				</view>
			</view>
			<rich-text :nodes="formatRichText(content)" v-if="content"></rich-text>
			<lf-nocontent v-else></lf-nocontent>
		</view>
		<!-- 活动列表 -->
		<view class="content" v-if="list">
			<view class="item" v-for="(item,index) in list" :key="index" @click="$url('/pages/goodsDetail/index?goods_id='+item.id)">
				<view class="cover">
					<image :src="item.picture" class="lf-w-100 lf-h-100" mode="aspectFill"></image>
				</view>
				<view style="width: 420rpx;">
					<view class="lf-font-28 lf-color-333 lf-line-2" style="height: 78rpx;">{{item.title}}</view>
					<view class="lf-font-24 lf-color-gray lf-line-2" style="height: 64rpx;">本套票只包含两个成人不可带小孩本套票只包含两个成人不可带小孩本套票只包含两个成人不可带小孩</view>
					<view class="lf-flex lf-m-t-25">
						<lf-price :price="item.price"></lf-price>
						<text class="lf-font-24 lf-color-gray lf-line-through lf-m-l-15">¥{{item.original_price}}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 加载 -->
		<view class="loading-more">
			<!-- <text v-if="list.length" :class="{'loading-more-text': loadingClass}">{{ loadingText }}</text> -->
		</view>
		<u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}"></u-back-top>
	</view>
</template>

<script>
	export default {
		data(){
			return {
				content: '',
				article_id: 0,
				title_content: '',
				list: [],
				loadingClass: false,
				loadingText: '已加载全部数据~',
				page: 1,
				isPage: true,
				pageSize: 20,
			}
		},
		onLoad(e){
			this.article_id = e.article_id
			if(this.article_id) {
				this.getData();
			}
		},
		methods: {
			// 富文本处理
			formatRichText(richText){
			  if(richText != null){
					let newRichText= richText.replace(/<img[^>]*>/gi, function(match, capture){
						match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
						match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
						match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
						return match;
					});
					newRichText = newRichText.replace(/style="[^"]+"/gi,function(match, capture){
						match = match.replace(/width:[^;]+;/gi, 'width:100%;').replace(/width:[^;]+;/gi, 'width:100%;');
						return match;
					});
					newRichText = newRichText.replace(/<br[^>]*\/>/gi, '');
					newRichText = newRichText.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;margin:10px 0;"');
					return newRichText;
				}else{
					return null;
				}
			},
			getData(){
				this.$http(this.API.API_FINDARTICLEDETAILS,{id: this.article_id}).then(res => {
					this.content = res.data?.content;
					this.title_content = res.data
					this.list = res.data?.product
					console.log(this.content)
				})
			}
		}
	}
</script>

<style lang="scss" scoped="scoped">
	.content{
		padding: 0 32rpx;
		box-sizing: border-box;
		width: 750rpx;
		height: max-content;
		margin-top: 30rpx;
		.item{
			width: 100%;
			height: auto;
			border-bottom: 1rpx solid #E5E5E5;
			padding: 30rpx 0;
			display: flex;
			&:last-child{
				border-bottom: none;
			}
			.cover{
				width: 250rpx;
				height: 210rpx;
				border-radius: 20rpx;
				overflow: hidden;
				margin-right: 15rpx;
			}
		}
	}
</style>
