<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" :key="item.id" @tap="goDisplay(item)">
				<image class="img-photo" 
					:src="'https://oss.humengfilms.com/' + item.aiPhoto+'?x-oss-process=image/resize,m_lfit,h_800,w_800'" 
					mode="aspectFill" />
				<view class="img-time">{{item.createTime}}</view>
				<view class="img-state">{{item.aiPhoto!=null?'生成完成':'生成中'}}</view>
				<image class="img-icon" 
					src="https://humeng-res.oss-cn-beijing.aliyuncs.com/hm_aigc/applet/right.png" />
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				uniMenuInfo: {},
				imgUrlList: [],
			}
		},
		onLoad() {
			uni.showLoading({
				title: '正在加载...',
				mask: true
			});
			this.uniMenuInfo = uni.getStorageSync('uniMenuInfo');
		},
		onShow() {
			this.initializeLoading();
		},
		methods: {
			goDisplay(record) {
				console.log(record)
				let myPhoto = record.aiPhoto == null?2:1
				uni.setStorageSync('record', record)
				uni.navigateTo({
					url: "../display/display?code=" + record.code + "&templateId=" + record.templateId
						+ "&mchId=" + record.mchId +"&buyType=" + record.buyType + "&templateSetId=" + record.templateSetId
						+ "&myPhoto=" + myPhoto,
					success() {
						uni.hideLoading();
					}
				})
			},
			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,
						type: 2
					},
					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>
