<!-- +----------------------------------------------------------------------
| 麦沃德科技赋能开发者，助力商协会发展
+----------------------------------------------------------------------
| Copyright (c) 2017～2024  www.wdsxh.cn    All rights reserved.
+----------------------------------------------------------------------
| 沃德商协会系统并不是自由软件，不加密，并不代表开源，未经许可不可自由转售和商用
+----------------------------------------------------------------------
| Author: MY WORLD Team <bd@maiwd.cn>   www.maiwd.cn
+----------------------------------------------------------------------
| 组件-相册列表 开发者: 麦沃德科技-半夏
+---------------------------------------------------------------------- -->

<template>
	<view class="component-album" :style="{'--theme-color': themeColor}">
		<view class="album-item" v-for="item in showData" :key="item.id" @click="toDetails(item.id)">
			<view class="item-date">{{item.release_date}}</view>
			<view class="item-title">{{item.name}}</view>
			<view class="item-content flex" v-if="item.files">
				<view class="content-timeline">
					<view class="timeline-point"></view>
					<view class="timeline-line"></view>
				</view>
				<view class="content-box flex-item">
					<block v-if="item.type == 1">
						<view class="box-single" v-if="splitImages(item.files).length == 1">
							<image class="image" :src="item.files" mode="aspectFill"></image>
						</view>
						<view class="box-multiple" v-else-if="item.files.length">
							<view class="multiple-image" v-for="(img, index) in splitImages(item.files)" :key="index">
								<image class="image" :src="img" mode="aspectFill"></image>
							</view>
						</view>
					</block>
					<view class="box-cover" v-else-if="item.type == 2">
						<image class="cover-image" :src="item.image" mode="aspectFill"></image>
						<image class="cover-play" src="/static/play.png" mode="aspectFit"></image>
						<view class="cover-mask"></view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { mapState } from "vuex"
	export default {
		name: "componentAlbum",
		props: ["showData"],
		computed: {
			...mapState({
				themeColor: state => state.app.themeColor,
			})
		},
		methods: {
			// 字符串转数组格式图片
			splitImages(images) {
				try {
					if (images) return images.split(',');
					else return []
				} catch (error) {
					return [];
				}
			},
			// 去详情
			toDetails(id) {
				this.$util.toPage({
					mode: 1,
					path: "/pagesTools/album/details?id=" + id
				})
			}
		},
	}
</script>

<style lang="scss">
	.component-album {
		.album-item {
			margin-top: 32rpx;

			&:first-child {
				margin-top: 0;
			}

			.item-date {
				color: #5A5B6E;
				font-size: 28rpx;
				font-weight: 600;
				line-height: 32rpx;
			}

			.item-title {
				margin-top: 16rpx;
				color: #8D929C;
				font-size: 28rpx;
				line-height: 40rpx;
			}

			.item-content {
				margin-top: 16rpx;

				.content-timeline {
					display: flex;
					flex-direction: column;

					.timeline-point {
						width: 20rpx;
						height: 20rpx;
						border-radius: 4rpx;
						background: var(--theme-color);
					}

					.timeline-line {
						width: 2rpx;
						height: 100%;
						flex: 1;
						background: #F0F0F0;
					}
				}

				.content-box {
					margin-left: 64rpx;

					.box-single {
						width: 100%;
						height: 240rpx;
						border-radius: 16rpx;
						overflow: hidden;
					}

					.box-multiple {
						display: flex;
						flex-wrap: wrap;
						column-gap: 2%;
						row-gap: 16rpx;

						.multiple-image {
							width: 32%;
							height: 0;
							padding-top: 32%;
							border-radius: 16rpx;
							overflow: hidden;
							position: relative;

							.image {
								position: absolute;
								top: 0;
								left: 0;
								width: 100%;
								height: 100%;
							}
						}
					}

					.box-cover {
						width: 100%;
						height: 240rpx;
						background: rgba(0, 0, 0, 0.3);
						border-radius: 16rpx;
						overflow: hidden;
						position: relative;

						.cover-image {
							width: 100%;
							height: 100%;
						}

						.cover-play {
							position: absolute;
							top: 50%;
							left: 50%;
							transform: translate(-50%, -50%);
							width: 64rpx;
							height: 64rpx;
							border-radius: 50%;
						}

						.cover-mask {
							position: absolute;
							top: 0;
							right: 0;
							bottom: 0;
							left: 0;
							background: rgba(0, 0, 0, 0.3);
						}
					}
				}
			}
		}
	}
</style>