<template>
	<view class="page flex-col">
		<view class="title" :style="{'top': uniMenuInfo.top + 6 + 'px'}">我的写真</view>
		<view class="back" @tap="goBack()" :style="{'top' : uniMenuInfo.top - 12 + 'px'}"></view>
		<view class="center" v-if="uniMenuInfo.bottom"
			:style="{'height': 'calc(100vh - ' + (uniMenuInfo.bottom + 10) + 'px)', 'top': uniMenuInfo.top + 35 + 'px'}">
			<view class="img" v-for="(item, idx) in imgUrlList" @tap="previewImage(item.aiPhoto)" :key="item.id">
				<image :src="item.aiPhoto+'?x-oss-process=image/resize,m_lfit,h_800,w_800'" mode="aspectFill" />
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				uniMenuInfo: {},
				imgUrlList: [],
			}
		},
		onLoad() {
			uni.showLoading({
				title: '正在加载...',
				mask: true
			});
			this.uniMenuInfo = uni.getStorageSync('uniMenuInfo');
			this.initializeLoading();
		},
		methods: {
			previewImage(url) {
				let previewImageList = [];
				previewImageList.push(url);
				uni.previewImage({
					urls: previewImageList,
				});
			},
			goBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			initializeLoading() {
				var _this = this;
				uni.request({
					url: _this.java_http_url + '/applet/smart_camera/getMyAiPhoto',
					method: 'POST',
					data: {
						userId: uni.getStorageSync('userInfo').id
					},
					success(res) {
						console.log('用户生成ai照片', res)
						if(res.data.code == 200) {
							_this.imgUrlList = res.data.data;
							_this.imgUrlList.forEach((el, idx)=> {
								el.aiPhoto = 'https://oss.humengfilms.com/' + el.aiPhoto
							})
						}
					},
					complete() {
						uni.hideLoading();
					}
				})
			}
		}
	}
</script>

<style>
@import url("@/pages/myPhoto/index.css");
@import url("@/css/common.css");
</style>
