<template>
	<view>
		<view class="content photo_back" style="background-color: #000;">
			<custom_navbar :title="navbar_title" @getNavHeight="getNavHeight" theme="light" />
			<view class="photo_main" :style="'margin-top:'+margin_top+'px'" style="width:100%;margin-left: 0;">
				<view class="photo_cartoon_2">
					<image
						:src="root+users_image"
						mode="aspectFill" />
				</view>
				
				<view class="photo_cartoon_3_2">
					<view class="photo_cartoon_3_2_1 photo_full_blue_btn" @click="submit">提交生成</view>
					<view class="photo_cartoon_3_2_2">剩余生成次数 <text style="color: #7A74F0;">{{cartoon_has}}</text>/{{all}}</view>
				</view>

			</view>

		</view>


	</view>
</template>

<script>
	import custom_navbar from "./components/photo_header.vue";
	export default {
		components: {
			custom_navbar

		},
		data() {
			return {
				navbar_title: '卡通画风',
				margin_top: 0,
				root:this.$api.getOssurl(),
				//参数
				cartoon_id:0,
				users_image:'',
				
				//统计
				cartoon_has:0, //已生成
				all:0,//可生成总数
			}
		},
		onShow() {
			var _this = this;
			var sceneList = _this.$user.session('sceneList');
			var all = sceneList[3].number;
			console.log(all);
			_this.all = all;
		},
		onLoad(options) {
			var _this =this;
			console.log('options',options);
			_this.cartoon_id = options.cartoon_id;
			_this.users_image = decodeURIComponent(options.users_image);
			_this.getUserInfo();
		},
		methods: {

			getNavHeight(e) {
				this.margin_top += e;
			},
			///api/userInfo
			getUserInfo(){
				
				var  _this = this;
				_this.$api.get('/api/userInfo',{},function(res){
					_this.cartoon_has = res.attach.photo.cartoon_number;
					
				});
			},
			submit(){
				
				var _this = this;
				var cartoon_id = _this.cartoon_id;
				var users_image  = _this.users_image;
				var post = {
					cartoon_id:cartoon_id,
					users_image:users_image,
				};
				_this.$com.showLoading('保存图片中');
				_this.$api.post('api/cartoon/append', post,function(rs){
						console.log(rs);
						_this.$com.hideLoading();
						uni.navigateTo({
							url:"/pagesA/merge/success"
						});
						
				});
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	@import './this.scss';
</style>