<template>
	<view class="container">
		<navBar title="绘本生成" :back="true" color="#333333" background="#FFFFFF" />

		<view class="topBox">
			<view class="left">
				<image :src="picBase+'upCamera.png'" mode="heightFix" class="aiIcon" @click="upload"></image>
			</view>
			<view class="right">
				<view class="label1">
					纯AI制作
				</view>
				<view class="label2">
					创作独一无二的绘本
				</view>
			</view>
		</view>
		<view class="mainBox">
			<view class="titleBox">
				上传一张故事主角的照片
			</view>
			<view class="uploadBox">
				<view class="tipBox">
					<image :src="picBase+'upCamera.png'" mode="heightFix" class="tipIcon" @click="upload"></image>
					绘本内容会根据您所上传的照片进行创作
				</view>

				<view class="selBox">
					<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
						:maxCount="1">
						<view class="myUpArea">
							<image :src="picBase+'upCamera.png'" mode="heightFix" class="upIcon">
							</image>
							上传图片
						</view>
					</u-upload>
				</view>
			</view>
		</view>

		<view class="parmasBox">
			<view class="titleBox">
				故事主角信息
			</view>
			<view class="inputBox">
				<view class="nickname">
					<input type="text" class="nackI" v-model="formData.nickName" placeholder="请输入昵称" />
					<image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
					</image>
				</view>

				<view class="otherBox">
					<view class="item" @click="show=true">
						<input type="text" class="nackI" disabled v-model="formData.sex" placeholder="选择性别" />
						<image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
						</image>
					</view>
					<view class="item" @click="show2=true">
						<input type="text" class="nackI" disabled v-model="formData.age" placeholder="选择年龄" />
						<image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
						</image>
					</view>
					<view class="item" @click="show3=true">
						<input type="text" class="nackI" disabled v-model="formData.star" placeholder="选择星座" />
						<image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
						</image>
					</view>
					<view class="item" @click="show4=true">
						<input type="text" class="nackI" disabled v-model="formData.class" placeholder="选择年级" />
						<image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
						</image>
					</view>
				</view>
			</view>
		</view>



		<view class="pos">
		</view>
		<view class="btnBox">
			<view class="left">
				<image :src="picBase+'kefu.png'" mode="heightFix" class="kfIcon">
				</image>
				客服
			</view>
			<view class="right">
				<view class="top">
					立即生成
				</view>
				<view class="bot">
					绘本生成剩余次数：8次
				</view>
			</view>
		</view>



		<!-- 性别弹框 -->
		<!-- <u-popup :show="show" @close="close" @open="open" :round="10">
			<view class="topBar">
				<view class="left">
					取消
				</view>
				<view class="mid">
					昵称选择
				</view>
				<view class="right">
					确定
				</view>
			</view>
			<view class="content">
				<text>出淤泥而不染，濯清涟而不妖</text>
			</view>
		</u-popup> -->
		<u-picker :show="show" title="性别选择" aColor="#007AFF" :columns="columns" confirmColor="#007AFF"
			@confirm="confirm1" @cancel="show=false"></u-picker>
		<u-picker :show="show2" title="年龄选择" aColor="#007AFF" :columns="columns2" confirmColor="#007AFF"
			@confirm="confirm2" @cancel="show2=false"></u-picker>
		<u-picker :show="show3" title="星座选择" aColor="#007AFF" :columns="columns3" confirmColor="#007AFF"
			@confirm="confirm3" @cancel="show3=false"></u-picker>
		<u-picker :show="show4" title="班级选择" aColor="#007AFF" :columns="columns4" confirmColor="#007AFF"
			@confirm="confirm4" @cancel="show4=false"></u-picker>
	</view>
</template>

<script>
	// import navBar from '@/components/navBar/index.vue'

	import uploadUrl from '@/common/config.js'
	export default {
		// components: {
		// 	navBar
		// },
		data() {
			return {
				picBase: this.$picBase2,
				fileList1: [],

				formData: {
					nickName: '',
					sex: '',
					age: '',
					star: '',
					class: ''
				},
				show: false,
				columns: [
					['男', '女']
				],
				show2: false,
				columns2: [
					['一岁', '两岁']
				],
				show3: false,
				columns3: [
					['金牛', '双子']
				],
				show4: false,
				columns4: [
					['蒙大一', '蒙大二', '蒙小一', '蒙小二', '蒙小三']
				],


			}
		},
		onLoad() {

		},
		methods: {
			confirm1(e) {
				console.log('e', e);
				this.formData.sex = e.value[0]
				this.show = false
			},
			confirm2(e) {
				console.log('e', e);
				this.formData.age = e.value[0]
				this.show2 = false
			},
			confirm3(e) {
				console.log('e', e);
				this.formData.star = e.value[0]
				this.show3 = false
			},
			confirm4(e) {
				console.log('e', e);
				this.formData.class = e.value[0]
				this.show4 = false
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						// url: 'http://192.168.2.21:7001/upload', // 仅为示例，非真实的接口地址
						url: uploadUrl.baseUrl + '/api/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test',
							'tag': 'lamp'
						},
						success: (res) => {

							console.log('uploadFilePromise返回值', res);
							setTimeout(() => {
								resolve(JSON.parse(res.data).file)
							}, 1000)
						}
					});
				})
			},
		}
	}
</script>

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