<template>
  <view class="live">
    <view class="flex live-header">
      <view>图片直播</view>
      <button class="flex btn" @click="showAll">
        <view>查看全部</view>
        <image class="img" src="@/static/image/icon-arrow-right.png" mode="widthFix"></image>
      </button>
    </view>
    <!-- <view class="live-content">
      <view class="live-item" v-for="item in list" :key="item.id">
        <image class="live-item-bg" :src="item.image" mode="aspectFill"></image>
        <view class="live-item-info">
          <view class="text-ellipsis live-item-info-title">{{ item.title }}</view>
          <view class="live-item-info-time">{{ item.time }}</view>
        </view>
      </view>
    </view> -->
		<view class="live-content">
			<swiper 
				class="swiper" 
				:current="current"
				:autoplay="true"
				:display-multiple-items="3.2"
			>
				<swiper-item v-for="item in list" :key="item.id" style="display: inline-block;">
					<view class="swiper-item">
						<view class="swiper-item-content" @click="jumpToLive(item.id, item.activityId)">
							<image class="live-item-bg" :src="item.url" mode="aspectFill"></image>
							<view class="live-item-info">
								<view class="text-ellipsis live-item-info-title">{{ item.title }}</view>
								<view class="live-item-info-time">{{ item.createTime }}</view>
							</view>
						</view>
					</view>
				</swiper-item>
			</swiper>
		</view>
  </view>
</template>

<script>
  export default {
		data() {
			return {
				list: [],
			}
		},
		created() {
      this.getData()
    },
    methods: {
      async getData() {
				try {
					this.list = (await this.$fetch('queryImageList', { pageNo: 1, pageSize: 8 }))?.records?.map(item => {
						const { id, image, activityId, activityId_dictText, createTime } = item

						const images = image?.split?.(',') || []

						return {
							id,
							activityId,
							url: images?.[0],
							images,
							title: activityId_dictText,
							createTime: this.$dayjs(createTime).format('YYYY-MM-DD'),
						}
					})
				} catch (err) {

				}
      },
			jumpToLive(id, activityId) {
        this.$store.commit('setLiveInfo', this.list.find(item => item.id === id))
				this.$utils.navigateTo(`/pages_order/live/index?imageId=${id}&activityId=${activityId}`)
			},
			showAll() {
				this.$utils.navigateTo(`/pages_order/live/list`)
			}
    },
  }
</script>

<style scoped lang="scss">

	.live {
		width: 100%;
		padding: 32rpx;
		box-sizing: border-box;
    background-image: linear-gradient(164deg,#DAF3FF, #FBFEFF , #FBFEFF);
		border: 2rpx solid #FFFFFF;
		border-radius: 32rpx;
		
		&-header {
			justify-content: space-between;
			font-size: 36rpx;
			font-weight: 500;
			color: #191919;

			.btn {
				column-gap: 4rpx;
				font-size: 24rpx;
				color: #8B8B8B;

				.img {
					width: 32rpx;
					height: auto;
				}
			}
		}
		
		&-content {
			margin-top: 16rpx;
			white-space: nowrap;
			width: 100%;
			overflow-x: auto;
			font-size: 0;
		}

		&-item {
			flex: none;
			display: inline-block;
			width: 180rpx;
			height: 240rpx;
			border-radius: 12rpx;
			overflow: hidden;
			position: relative;

			& + & {
				margin-left: 16rpx;
			}

			&-bg {
				width: 100%;
				height: 100%;
			}

			&-info {
				position: absolute;
				left: 0;
				bottom: 0;
				width: 100%;
				padding: 8rpx 12rpx;
				box-sizing: border-box;

				&-title {
					font-size: 26rpx;
					font-weight: 600;
					color: #FFFFFF;
				}

				&-time {
					font-size: 22rpx;
					color: #FFFFFF;
				}
			}
		}
	}

	.swiper {
		width: 100%;
		height: 240rpx;

		&-item {
			width: 180rpx;
			height: 240rpx;
			
			&-content {
				position: relative;
				width: 100%;
				height: 100%;
				border-radius: 12rpx;
				overflow: hidden;
			}
		}
	}
</style>