<template>
	<view class="main">
		<view class="one" v-if="info.file.length>0">
			<swiper class="swiper" circular :indicator-dots="true" indicator-color="#F5F5F5"
				indicator-active-color="#ffffff" :autoplay="false" :interval="3000" :duration="1000">
				<swiper-item class="list" v-for="(item,index) in imgList" :key="index">
					<image class="image"
						v-if="item.url.indexOf('gif') != -1 || item.url.indexOf('jpg') != -1 || item.url.indexOf('png') != -1 || item.url.indexOf('jpeg') !=-1"
						:src="item.url" mode=""></image>
					<video class="image" :autoplay='true' :show-fullscreen-btn="false" :loop="true" controls v-else
						:src="item.url"></video>
				</swiper-item>
			</swiper>
		</view>
		<view class="bottom">
			<view class="two">
				<view class="two_1">{{info.name||'暂无'}}</view>
				<view class="two_2">{{info.open_time||'暂无'}}</view>
			</view>
			<view class="thr">
				<view class="thr_1">
					<view class="left">地址：</view>
					<view class="right"><text :user-select='true'>{{info.address||'暂无'}}</text></view>
				</view>
				<view class="thr_1">
					<view class="left">状态：</view>
					<view class="right">
						<text :class="[info.status=='0'?'text_1':'text_2']">{{info.zhStatus}}</text>
					</view>
				</view>
				<view class="thr_1">
					<view class="left">官方电话：</view>
					<view class="right"><text :user-select='true'>{{info.phone||'暂无'}}</text></view>
				</view>
			</view>
			<view class="four" v-if="info.policy">
				<view class="four_1">优待政策</view>
				<rich-text :nodes="formatRichText(info.policy)"></rich-text>
			</view>
			<view class="four">
				<view class="four_1">简介</view>
				<rich-text :nodes="formatRichText(info.brief)"></rich-text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {},
				// 轮播图
				imgList: [],
				info: {
					file: []
				},
				// 字典表
				statusList: []
			}
		},
		onLoad: async function(e) {
			const that = this;
			await that.searchOther();
			that.searchToken();
			that.search();
		},
		methods: {
			searchToken() {
				const that = this;
				try {
					const res = uni.getStorageSync('token');
					if (res) {
						that.$set(that, `user`, res);
					}
				} catch (e) {
					uni.showToast({
						title: err.errmsg,
						icon: 'error',
						duration: 2000
					});
				}
			},
			async search() {
				const that = this;
				const res = await that.$api(`/config`, 'GET', {})
				if (res.errcode == '0') {
					const status = that.statusList.find(i => i.value == res.data.status)
					if (status) res.data.zhStatus = status.label
					that.$set(that, `imgList`, [...res.data.video, ...res.data.file]);
					that.$set(that, `info`, res.data)
				} else {
					uni.showToast({
						title: res.errmsg,
					});
				}
			},
			// 处理富文本
			formatRichText(html) {
				if (html) {
					// 富文本内容格式化
					return html && html.replace(/<img[^>]*>/gi, function(match, capture) {
						// 查找所有的 img 元素
						return match.replace(/style=".*"/gi, '').replace(/style='.*'/gi,
							'')
						// 删除找到的所有 img 元素中的 style 属性
					}).replace(/\<img/gi, '<img style="width:100%;"') // 对 img 元素增加 style 属性，并设置宽度为 100%
				}
			},
			// 查询其他信息
			async searchOther() {
				const that = this;
				let res;
				// 查询类型
				res = await that.$api(`/dictData`, 'GET', {
					type: 'config_status',
					is_use: '0',
				})
				if (res.errcode == '0') that.$set(that, `statusList`, res.data);
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		.one {
			.swiper {
				height: 70vw;

				.list {
					.image {
						width: 100%;
						height: 100%;
					}
				}
			}
		}

		.bottom {
			position: absolute;
			top: 65vw;
			left: 0;
			right: 0;
			background-color: var(--mainColor);
			border-radius: 20px;
			padding: 2vw 0 0 0;

			.two {
				padding: 4vw 2vw;
				text-align: center;

				.two_1 {
					padding: 1vw 0;
					font-weight: bold;
					font-size: var(--font16Size);
				}

				.two_2 {
					color: var(--f85Color);
					font-size: var(--font12Size);
				}

			}

			.thr {
				padding: 2vw;

				.thr_1 {
					display: flex;
					font-size: var(--font14Size);
					padding: 0 0 1vw 0;

					.left {
						padding: 0 1vw 0 0;
						font-weight: bold;
					}

					.right {
						color: var(--f85Color);

						.text_1 {
							font-size: var(--font12Size);
							padding: 3px 5px;
							color: var(--mainColor);
							border-radius: 5px;
							background-color: mediumseagreen;
						}

						.text_2 {
							font-size: var(--font12Size);
							padding: 3px 5px;
							color: var(--mainColor);
							border-radius: 5px;
							background-color: red;
						}
					}
				}
			}

			.four {
				padding: 2vw;

				.four_1 {
					font-weight: bold;
					font-size: var(--font16Size);
					padding: 0 0 1vw 0;
				}
			}
		}
	}
</style>