<template>
	<view class="pc-home">
		<view class="main-content" :style="{backgroundImage: `url(${staticIp+backgroundImage})`}">
			<view class="mc-left">
				<view class="mcl-out">
					<view class="mcl-top">
						自由的Ai图像重绘服务
						<br />
						图像识别与替换
					</view>
					<view class="mcl-bottom">
						自由绘制 | 自动识别 | 无限扩展
					</view>
				</view>
			</view>
			<view class="mc-right">
				<view class="mcr-card">
					<el-upload class="mcr-upload" drag action="#" :auto-upload="false" ref="uploadCover" 
					:multiple="false" accept="image/*" list-type="picture" :on-change="uploadFile">
					  <image src="/static/upload-image.png"></image>
					</el-upload>
					<view class="mcr-tip">点击或拖拽图片到这里</view>
					<view class="mcr-show">
						<view class="mcrs-item" v-for="(item,index) in defaultWorkList" :key="index"
						:title="item.serviceName||'暂无'">
							<el-image class="work-module" :src="getImagePath(item.path)"
							:preview-src-list="[getImagePath(item.path)]"></el-image>
							<view class="work-todo" @click.stop="$emit('changeService',item.serviceId)">
								<image :src="fileUrl+magicWand"></image>
								<text>做同款</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="second-content">
			<Second @showToast="showToast" @handleChangeService="handleChangeService"/>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
import Second from './components/second.vue';
import configService from '@/common/config.service.js';
export default {
	components:{
		Second
	},
	data(){
		return{
			// 基础路径
			staticIp: configService.ip,
			fileUrl: configService.fileUrl + 'pixel/home/',
			// 背景图片
			backgroundImage: 'static/pixel/pc/home/background.png',
			// 默认推荐作品
			defaultWorkList: [
				{
					path: "http://guojunjie.oss-cn-hangzhou.aliyuncs.com/20241227/173529161311570.jpg",
					serviceName: '更换图片风格',
					serviceId : 3
				},
				{
					path: "https://guojunjie.oss-cn-hangzhou.aliyuncs.com/upload/sample/1734970091260.jpg",
					serviceName: '换衣试衣',
					serviceId : 5
				},
				{
					path: "https://guojunjie.oss-cn-hangzhou.aliyuncs.com/upload/sample/1734970072585.jpg",
					serviceName: '换衣试衣',
					serviceId : 5,
				},
				{
					path: "http://guojunjie.oss-cn-hangzhou.aliyuncs.com/20241227/1735277872644388.jpg",
					serviceName: '换衣试衣',
					serviceId : 5
				},
			],
			// 魔术棒
			magicWand: 'magic-wand.png',
		}
	},
	methods:{
		// 初始化
		init(){
			// this.recommendForm = {current: 1,size: 10,isFinish: false,total: 0,isBackend: 0};
		},
		// 图片地址格式化
		getImagePath(path){
			if(path){
				return path.includes("://") ? path : encodeURI(this.staticIp+path);
			}else{
				return '';
			}
		},
		// 服务跳转
		handleChangeService(id){
			this.$emit('changeService',id)
		},
		// 首页上传文件
		uploadFile(file, fileList){
			this.$refs.uploadCover.clearFiles();
			const size = file.size / 1024; // 计算文件大小
			if(size<5 || (size/1024)>5){
				this.$refs.uToast.show({type: 'warning',title: "请上传大小为5KB~5MB的图片!"});
				return;
			}
			let isAccept = new RegExp('image/*').test(file.raw.type)
			if (!isAccept) {
			    this.$refs.uToast.show({type: 'warning',title: "图片上传格式错误!"});
			    return;
			}
			// this.form.coverPath = file;
			// this.fileList[0] = file;
		},
		// 提示语弹窗
		showToast({type,title}){
			this.$refs.uToast.show({type: type, title: title});
		}
	},
	mounted() {
		this.init();
	}
}
</script>

<style scoped lang="scss">
.pc-home{
	.main-content {
		width: 100%;
		min-height: 73.5em;
		background-size: cover;
		background-repeat: no-repeat;
		display: flex;
		aspect-ratio: 16/9 !important;
		
		.mc-left {
			margin-top: 15%;
			flex: 1;
			height: 60%;
			display: flex;
	
			.mcl-out {
				margin-left: 40%;
				display: flex;
				flex-direction: column;
	
				// width: 740rpx;
				.mcl-top {
					color: #12121f;
					font-weight: 500;
					font-size: 100rpx;
					line-height: 150rpx;
				}
	
				.mcl-bottom {
					margin-top: 48rpx;
					color: #959ba6;
					font-size: 38rpx;
					font-family: fangsong;
				}
			}
		}
	
		.mc-right {
			margin-top: 13%;
			flex: 1;
	
			.mcr-card {
				overflow: hidden;
				border-radius: 30rpx;
				margin-left: 5%;
				min-height: 1100rpx;
				width: 1400rpx;
				background-color: #fff;
				aspect-ratio: 23/18;
				box-shadow: 0 5rpx 10rpx 0 #dcdae4;
				display: flex;
				flex-direction: column;
				align-items: center;
				&:hover{
					box-shadow: 0 0 25rpx #eee;
				}
				.mcr-upload{
					margin-top: 120rpx;
					::v-deep .el-upload-dragger{
						width: 450rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						background-color: #f5f6f9;
						border-radius: 30rpx;
						&:hover{
							border-color: #959ba6;
							image{
								width: 160rpx;
								height: 128rpx;
							}
						}
						&:active{
							border-color: #959ba6;
						}
					}
					image{
						transition: 0.5s;
						width: 140rpx;
						height: 112rpx;
					}
				}
				.mcr-tip{
					font-size: 58rpx;
					margin: 50rpx;
				}
				.mcr-show{
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: center;
					.mcrs-item{
						overflow: hidden;
						position: relative;
						margin: 10rpx 40rpx;
						border-radius: 12rpx;
						.work-module{
							width: 240rpx;
							height: 330rpx;
							border-radius: 12rpx;
							box-shadow: 0 0 10rpx #959ba6;
							opacity: 0.85;
						}
						.work-todo{
							width: 240rpx;
							height: 80rpx;
							padding-left: 34rpx;
							position: absolute;
							z-index: 1;
							border-radius: 8rpx 8rpx 12rpx 12rpx;
							bottom: -80rpx;
							left: 0;
							background-color: rgba(0, 0, 0, 0.3);
							display: flex;
							align-items: center;
							font-size: 35rpx;
							transition: 0.5s;
							cursor: pointer;
							text{
								font-weight: bold;
								background-image: linear-gradient(to right, #cdfbf2 0%, #a3d4ff 100%);
								background-clip: text;
								-webkit-background-clip: text;
								-webkit-text-fill-color: transparent;
							}
							image{
								margin-right: 10rpx;
								width: 40rpx;
								height: 40rpx;
							}
							&:hover{
								opacity: 0.8;
							}
							&:active{
								opacity: 0.6;
							}
						}
						&:hover{
							.work-todo{
								bottom: 6rpx;
							}
							.work-module{
								opacity: 1;
							}
						}
					}
				}
			}
		}
	}
}
</style>