<template>
	<view class="outer">
		<view style="color: #fff;">
			<tn-nav-bar backgroundColor="#207CF7" :bottomShadow="false">AI绘图</tn-nav-bar>
			<view :style="{ height: tobheight + 'px' }"></view>
		</view>
		<!-- 绘画引导界面 -->
		<view class="addmask" v-if="showHuiHuaLead">
			<view class="leadBg">
				<view class="leadBox1" v-if="showLead1"
					:style="{'background-image': `url(${leadBaseUrl}hh_lead1.png)`}">
					<view class="nextBtn" @click="nextLead">
					</view>
				</view>
				<view class="leadBox2" v-if="showLead2"
					:style="{'background-image': `url(${leadBaseUrl}hh_lead_2.png)`}">
					<view class="nextBtn" @click="finishLead">
					</view>
				</view>
			</view>
		</view>
		<u-notice-bar bgColor='#C6D6E4' color='#3F5465' :text="noticebar" step speed="800"></u-notice-bar>

		<view style="margin: 30rpx 30rpx 0;">
			<tn-subsection :list="tabslist" :current="current" mode="button" :borderRadius="50"
				backgroundColor="#207CF7" @change="getsubsection" buttonColor="tn-cool-bg-color-7"
				inactiveColor="#FFFFFF" activeColor="#357aba"></tn-subsection>
		</view>

		<view class="ysBox" v-if="current==0">
			<div class="selBox">
				<div class="title">
					<div class="le">
						模板选择
					</div>
					<div class="selList" @click.stop="">
						<div class="item" v-for="(item,index) in selOptList" @click.stop="handleOpenOpt(index)">
							{{item}}
							<img src="@/static/arrD.png" alt="" class="arrD" />
						</div>
					</div>
				</div>

				<div class="addPo">
					<div class="optDetailBox" v-if="showRule" @click.stop="closeOver">
						<div class="con" @click.stop="">
							<div class="optList" @click.stop="">
								<div class="item" @click.stop="handleOrder(item,index)" v-for="(item,index) in rules"
									:class="[item==seledRule?'item_a':'']">
									{{item}}
								</div>
							</div>
						</div>
					</div>
					<div class="optDetailBox" v-if="showThem" @click.stop="closeOver">
						<div class="con" @click.stop="">
							<div class="optList" @click.stop="">
								<div class="item" @click.stop="handleSelStyle(item)" v-for="(item,index) in styles"
									:class="[item.id==seledStyle.id?'item_a':'']">
									{{item.title}}
								</div>
							</div>
						</div>
					</div>


					<div class="optDetailBox" v-if="showSex" @click.stop="closeOver">
						<div class="con" @click.stop="">
							<div class="optList" @click.stop="">
								<div class="item" @click.stop="handleSelSex(item,index)" v-for="(item,index) in sexList"
									:class="[item==seledSex?'item_a':'']">
									{{item}}
								</div>
							</div>
						</div>
					</div>
				</div>


				<div class="conList">
					<div class="item" v-for="(item,index) in cankaoImgList.slice(0,8)"
						@click="handleSelModal(item,index)">
						
	 	<div class="top" :class="[item.id==seledCankaoImg.id?'item_a':'']">
							<img :src="item.path" class="img">
								<img v-if="item.id==seledCankaoImg.id" src="@/static/b_seled.png" alt="" class="tag" />
						</div>
						
					<!-- 	<div class="top" :class="[item.id==seledCankaoImg.id?'item_a':'']"
							:style="{backgroundImage:`url(${item.path})`}">
							<img v-if="item.id==seledCankaoImg.id" src="@/static/b_seled.png" alt="" class="tag" />
						</div> -->
						
						
						<!-- 	<div class="top" :class="[item.id==seledCankaoImg.id?'item_a':'']"
								:style="{backgroundImage:`url(${item.path})`}">
								<img v-if="item.id==seledCankaoImg.id" src="@/static/b_seled.png" alt="" class="tag" />
							</div> -->
						<div class="name">
							{{item.title}}
						</div>
					</div>
				</div>

				<div class="addLpd">
					<div class="moreBtn" @click="handleMorePopup">
						更多
					</div>
				</div>
				<!-- 	<u-button @click="test">测试压缩</u-button> -->

				<div class="upTitle">
					上传图片
				</div>

			<div class="tipAndUpBox">
				<div class="left">
					<div class="item" v-for="(item,index) in tipList">
						<img src="@/static/renx.png" alt="" />
						{{item}}
					</div>
			
				
				</div>
				<div class="upList">
					<div class="upBox">
						<div class="up1 up " @click.stop="upYsImg(0)" :class="[myModal?'up_a':'']"
							>
							<img :src="myModal" class="img">
							<span v-if="!myModal&&!showUpLoading1">点击<br>上传模板</span>
							<img src="@/static/b_camera.png" alt="" class="camera" />
			
							<div v-if="myModal" class="del" @click.stop="myModal='';">
								<u-icon name="trash" @click.stop="myModal='';" color="#1F79F0" size="20"></u-icon>
							</div>
							<u-loading-icon v-if="showUpLoading1" class="loading" text='' textSize="18"
								mode="circle" vertical duration="1000"></u-loading-icon>
						</div>
						<div class="des">
							上传模板
						</div>
					</div>
			
					<div class="upBox">
						<div class="up2 up" :class="[myPhoto?'up_a':'']"
							:style="{'background-image':`url(${myPhoto})`}" @click.stop="upYsImg(1)">
							<span v-if="!myPhoto&&!showUpLoading2">点击<br>上传照片</span>
							<img src="@/static/b_camera.png" alt="" class="camera" />
			
							<div v-if="myPhoto" class="del" @click.stop="myPhoto=''">
								<u-icon @click.stop="myPhoto=''" name="trash" color="#1F79F0" size="20"></u-icon>
							</div>
			
							<u-loading-icon v-if="showUpLoading2" class="loading" text='' textSize="18"
								mode="circle" vertical duration="1000"></u-loading-icon>
						</div>
						<div class="des">
							上传照片
						</div>
					</div>
				</div>
			
			</div>
				
					</div>

				</div>
				<div class="line"></div>

				<div class="tipBox">
					<img src="@/static/b_info.png" alt="" />
					模板可直接选择上面的现成模板，可点击自己上传<br>
					仅支持JPG/PNG格式，大小10M以下
				</div>
				<!-- <div class="ysBtn" @click="genYishuZhao">
					生成艺术照
				</div> -->
				<view class="dygbhg">
					<navigator class="whole" open-type="navigateBack">退出</navigator>

					<view @click="genYishuZhao" class="distinguish">生成艺术照 |
						<!-- 需要消耗{{ plan.unlock_aipainting*form.samples}}{{appInfo.number_alias ? appInfo.number_alias : '点数'}} -->
						需要消耗1{{appInfo.number_alias ? appInfo.number_alias : '点数'}}
					</view>
				</view>
			</div>
		</view>

		<view class="directask" v-if="current!=0" style="padding-top: 0;">
			<!-- <view v-if="modelslist.length>0" class="cu-form-group"> -->
		<!-- Mj引导页  如果current等于1-->
		<view v-if="current == 1">
		<view class="mj-new-leader" v-if="mjShowLead" >
		
		<view class="mj-bg">
				<view class="MjNewshow" :style="{'background-image':`url(${MjNewBaseUrl})`}"></view>
		</view>
		<view class="mj-next-btn" @click="mjnextLead"></view>
		</view>
		</view>
		<!-- 如果SD引导页面 如果current等于2 -->
		<view v-if="current == 2">
		<view class="mj-new-leader" v-if="sdShowLead" >
		
		<view class="mj-bg">
				<view class="MjNewshow" :style="{'background-image':`url(${MjNewBaseUrl})`}"></view>
		</view>
		<view class="mj-next-btn" @click="sdnextLead"></view>
		</view>
	
		</view>
		
		
			<view class="cu-form-group">
				<view class="cu-title flxe align-center justify-between">
					<view class="title flxe align-center">模型选择</view>
					<block v-if="showmj==1">
						<u-tag v-if="userData.vip_info&&userData.is_validity>0"
							:text="(userData.vip_info.mj_type == 'time'?'今日':'会员')+'剩余mj绘画:'+(userData.vip_info.mj_times==-1?'无限量':userData.vip_info.mj_times-userData.vip_info.mj_used+'次')"
							plain shape="circle" plainFill color="#207CF7" borderColor="#207CF7"
							bgColor="#207CF714"></u-tag>
					</block>
					<block v-else-if="showmj==2">
						<u-tag v-if="userData.vip_info&&userData.is_validity>0"
							:text="(userData.vip_info.sd_type == 'time'?'今日':'会员')+'剩余sd绘画:'+(userData.vip_info.sd_times == -1?'无限量':userData.vip_info.sd_times-userData.vip_info.sd_used+'次')"
							plain shape="circle" plainFill color="#207CF7" borderColor="#207CF7"
							bgColor="#207CF714"></u-tag>
					</block>
				</view>
				<view class="engine-container" @click="showmode = true" v-if="current==2">
					
					
					
					<view class="model_view">模型：{{xzmodels}}</view>
					<u-icon name="arrow-down-fill" color="#9e9e9e"></u-icon>
				</view>
			</view>
			<!-- mj模型选择新调整 -->
			<view class="mjSelBox" v-if="current==1">
				<view class="mjitem" v-for="(item,index) in modelslist"
					@click="modelsid = index,showmode = false,form.model_id = item.model_id.toString(),xzmodels = item.name,form.name = item.name"
					:style="{'border-color':index==modelsid?'#1F79F0':'','background-image':`url(${item.title=='官方V5.1'?'../../static/scy.png':'../../static/ecy.png'})`}">
					<view class="topRight" style="background-image: url('../../static/sjx.png')">
						热
					</view>
					<view class="bar">
						{{item.title=='官方V5.1'?'卡通动漫':'真实风格'}}
					</view>
				</view>
			</view>



			<view class="cu-form-group" :style="engineid != 0 ? 'margin-top: 20rpx' : ''"
				style="padding-top: 0;padding-bottom: 0;">
				<view class="cu-title flxe align-center justify-between">
					<view class="title flxe align-center">画面描述</view>
				</view>
				<view class="textarea-container">
					<textarea class="textarea" v-model="keywords" cursor-spacing="30rpx" :maxlength="500"
						placeholder-style="color: #9e9e9e;font-size:28rpx"
						placeholder="输入你的创意，支持中英文，用逗号分隔,关键词越多越精确，关键词越少AI自由发挥越多,如:最好的质量,城市,大雨,远景,赛博朋克" value="keywords"
						@input="textareainput" />
					<view class="textareaoperate tn-flex align-center justify-between">
						<!-- <view @click="getincrease" class="increase">描述增幅</view> -->
						<view @click="show_gpt = true" class="increase tn-main-gradient-orangeyellow">咒语助手</view>
						<view class="tn-flex align-center" style="color: #9e9e9e;">
							<view class="">{{cursor}}/500</view>
							<view style="margin: 0 20rpx;">||</view>
							<u-icon @click="keywords = '',galleryid ='',cursor = 0" name="trash-fill" color="#9e9e9e"
								size="24"></u-icon>
						</view>
					</view>
				</view>
				<view v-if="gallerylist.length>0" class="try-tips">
					<scroll-view class="scroll-view" scroll-x="true">
						<block v-for="(item,index) in gallerylist" :key="index">
							<view @click="tapgallery(index)" class="scroll-item"
								:style="{background: galleryid == item.id?'#207CF7':'',color: galleryid == item.id?'#fff':''}">
								{{item.name}}
							</view>
						</block>
					</scroll-view>
					<view class="change" @click="initWords"><text class="tn-icon-circle-arrow tn-color-cat"
							style="font-size: 34rpx;"></text></view>
				</view>
			</view>


			<!-- mj和sd展示 -->
			<view v-if="showmj!=0" class="cu-form-group" style="padding-top: 0;padding-bottom: 0;">
				<view class="cu-title">
					<view class="title flxe align-center">图片比例</view>
				</view>
				<view class="flxe proportion">
					<view class="radio flxe align-center justify-center flxe-column"
						:class="ratioIndex == 0 ? 'active' : ''" @click="ratio(0)">
						<view class="cu-proportion flxe align-center justify-center">
							<view class="proportion1"></view>
						</view>
						<view class="describe">1:1</view>
					</view>
					<view class="radio flxe align-center justify-center flxe-column"
						:class="ratioIndex == 1 ? 'active' : ''" @click="ratio(1)">
						<view class="cu-proportion flxe align-center justify-center">
							<view class="proportion2"></view>
						</view>
						<view class="describe">3:4</view>
					</view>
					<view class="radio flxe align-center justify-center flxe-column"
						:class="ratioIndex == 2 ? 'active' : ''" @click="ratio(2)">
						<view class="cu-proportion flxe align-center justify-center">
							<view class="proportion3"></view>
						</view>
						<view class="describe">4:3</view>
					</view>

					<view v-if="showmj==1" class="radio flxe align-center justify-center flxe-column"
						:class="ratioIndex == 3 ? 'active' : ''" @click="ratio(3)">
						<view class="cu-proportion flxe align-center justify-center">
							<view class="proportion2"></view>
						</view>
						<view class="describe">9:16</view>
					</view>
					<view v-if="showmj==1" class="radio flxe align-center justify-center flxe-column"
						:class="ratioIndex == 4 ? 'active' : ''" @click="ratio(4)">
						<view class="cu-proportion flxe align-center justify-center">
							<view class="proportion3"></view>
						</view>
						<view class="describe">16:9</view>
					</view>
				</view>
			</view>
			<!-- sd和mj都要展示 -->
			<view class="cu-form-group" style="padding-top: 0;padding-bottom: 0;">
				<view class="cu-title">
					<view class="title flxe align-center">参考图(可选)</view>
				</view>
				<view class="desc-tips">AI绘画时会参考您所上传的参考图的风格进行构图</view>
				<view class="cu-upload flxe align-center justify-center">
					<image class="upload-img" :src="refer_img" v-if="refer_img" mode="aspectFill"
						@click="preViewImg(refer_img)"></image>
					<view class="upload-delete tn-icon-delete tn-color-cat" style="font-size: 40rpx;" v-if="refer_img"
						@click="deleteImg()"></view>
					<view class="flxe flxe-column align-center" v-else @click="uploadImg(engineid)">
						<u-icon name="plus-circle-fill" color="#207CF7" size="28"></u-icon>
						<view class="upload">上传图片</view>
					</view>
				</view>
			</view>
			<!-- sd和mj都要展示 -->
			<view class="cu-form-group" v-if="current!=0" style="padding-top: 0;padding-bottom: 0;">
				<view class="cu-title">
					<view class="title flxe align-center">生成数量</view>
				</view>
				<view class="flxe generate">
					<block v-if="showmj==2">
						<view class="xz_generate flxe align-center justify-center"
							:class="form.samples == 1 ? 'xz_gactive' : ''" @click="form.samples = 1">
							<view :style="{color: form.samples == 1 ? '#207CF7':''}">1张</view>

						</view>
					</block>
					<block v-else-if="showmj==1">
						<view class="xz_generate flxe align-center justify-center"
							:class="form.samples == 4 ? 'xz_gactive' : ''" @click="form.samples = 4">
							<view :style="{color: form.samples == 4 ? '#207CF7':''}">4张</view>
						</view>
					</block>
				</view>
			</view>
		</view>

		<!-- 底部按钮区域 -->
		<view class="dygbhg" v-if="current!=0">
			<navigator class="whole" open-type="navigateBack">退出</navigator>
			<block v-if="showmj==1">
				<view
					v-if="userData.vip_info&&userData.is_validity>0&&userData.vip_info.mj_times-userData.vip_info.mj_used>0 ||userData.vip_info&&userData.is_validity>0&&userData.vip_info.mj_times == -1"
					@click="createClick" class="distinguish">立即生成</view>
				<view v-else @click="createClick" class="distinguish">生成 |
					需要消耗{{ plan.unlock_mj_aipainting}}{{appInfo.number_alias ? appInfo.number_alias : '点数'}}</view>
			</block>
			<block v-else-if="showmj==2">
				<view
					v-if="userData.vip_info&&userData.is_validity>0&&userData.vip_info.sd_times-userData.vip_info.sd_used>0 ||userData.vip_info&&userData.is_validity>0&&userData.vip_info.sd_times == -1"
					@click="createClick" class="distinguish">立即生成</view>
				<view v-else @click="createClick" class="distinguish">生成 |
					需要消耗{{ plan.unlock_aipainting*form.samples}}{{appInfo.number_alias ? appInfo.number_alias : '点数'}}
				</view>
			</block>
		</view>

		<u-loading-page :loading="loading" loading-text="正在加载" icon-size="35" bgColor="#1a1a1a" color="#fff"
			loadingColor="#fff"></u-loading-page>
		<u-popup :show="showmode" @close="showmode = false" safeAreaInsetTop :round="15" closeable>
			<view class="select u-flex justify-center"><text>选择模型</text></view>
			<scroll-view scroll-y="true" class="scroll_mode">
				<view class="tn-flex justify-between flex-wrap">
					<block v-for="(item,index) in modelslist" :key="index">
						<view v-if="item.title" class="card" :style="{borderColor: modelsid == index?'#207CF7':''}"
							@click="modelsid = index,showmode = false,form.model_id = item.model_id.toString(),xzmodels = item.name,form.name = item.name">
							<u-swiper :list="item.imgs" radius="0" height="110"
								:indicator="item.imgs.length>1?true:false" indicatorMode="line" circular></u-swiper>
							<view class="card-info">
								<view class="card-info-title">{{item.title=='官方V5.1'?'Niji 5':item.title}}</view>
								<view class="card-info-desc">{{item.name}}</view>
							</view>
						</view>
					</block>

				</view>

			</scroll-view>

		</u-popup>
		<u-popup :show="show_gpt" @close="show_gpt = false" mode="center" :round="10" closeable safeAreaInsetTop>
			<view class="gpt-select">
				<view class="gpt-title"><u--text text="咒语助手" iconStyle="font-size: 20px" color="#1a1a1a" bold size="18"
						lineHeight="30"></u--text></view>
				<u--text text="针对AI绘画场景下的gpt模型,能够生成高质量的描述词" color="#9e9e9e" size="14" lineHeight="30"></u--text>
				<!-- <u--text text="输入你的创意 想象"  iconStyle="font-size: 20px" bold size="16" lineHeight="30"></u--text> -->
				<view class="gpt-textarea-container"><u--textarea v-model="gpt_keywords" placeholder="输入你的创意 想象"
						count></u--textarea></view>
				<view class="use-gpt">
					<u-button :text="appInfo.number_alias ? '灵感一现(消耗1'+appInfo.number_alias+')':'灵感一现(消耗1点数)'"
						shape="circle" color="linear-gradient(to right, rgb(255, 202, 40), rgb(255, 167, 38))"
						@click="getGpt"></u-button>
				</view>
				<view class="gpt-textarea-container" style="margin-bottom: 20rpx;"><u--textarea height="200"
						v-model="gpt_text" v-if="gpt_text"></u--textarea></view>
				<u-button type="success" @click="setGpt" plain text="使用" shape="circle" v-if="gpt_text"></u-button>
			</view>
		</u-popup>

		<u-popup :closeOnClickOverlay="true" :show="showMorePopup" @close="showMorePopup = false" mode="bottom"
			:round="10" :closeable="false" safeAreaInsetTop>
			<div class="cankaoImgBox">
				<div class="top">
					<div class="title">
						模板选择
					</div>
					<img src="@/static/b_info.png" alt="" />
					<span>选择后直接作为生成照片参照</span>
				</div>
				<!-- <div class="conList">
					<div class="item" v-for="(item,index) in cankaoImgList" @click="handleSelMoreModal(item,index)">
						<div class="top" :class="[item.id==seledCankaoImg_temp.id?'item_a':'']"
							:style="{backgroundImage:`url(${item.path})`}">
							<img v-if="item.id==seledCankaoImg_temp.id" src="@/static/b_seled.png" alt="" class="tag" />
						</div>
						<div class="name">
							{{item.title}}
						</div>
					</div>
				</div> -->
				<!-- 添加分页 -->
				<scroll-view class="conList_divPage" :scroll-y="true" :scroll-x="false" @scrolltolower="scrollMore"
					:lower-threshold="150" :show-scrollbar="false">
					<div class="conList_div">
						<div class="item" v-for="(item,index) in cankaoImgList" @click="handleSelMoreModal(item,index)">
							<div class="top" :class="[item.id==seledCankaoImg_temp.id?'item_a':'']" 
								>
								<img class="img"  :src="item.path">
								<img v-if="item.id==seledCankaoImg_temp.id" src="@/static/b_seled.png" alt=""
									class="tag" />
							</div>
							<div class="name">
								  {{item.title}} 
							
							</div>
						</div>
					</div>
					<div class="loadSate">
						<u-loadmore @click="scrollMore" :status="status" />
					</div>
				</scroll-view>
				<div class="btnBox">
					<div class="left" @click="showMorePopup=false">
						取消
					</div>
					<div class="right" @click="handleConfirmSel">
						确定
					</div>
				</div>
			</div>
		</u-popup>
		<wike-model v-if="signShow" :authorize="false" :title="signTitle" btnText="立即获取" @save="signSign"
			@close="signShow = false"></wike-model>
		<wike-modal-qrcode :qrcode="gzhqrcode" :showconcern="showconcern"
			@concernclose="concernclose"></wike-modal-qrcode>
		<!-- <wike-tabbar :onTabbar="true" :isShowAnimate="true"></wike-tabbar> -->
		<!-- <u-picker :show="showmode" :columns="modelslist" keyName="name" @cancel="showmode = false"></u-picker> -->


		<!-- 自定义图片预览 -->
		<view class="preImgBox" v-if="showDemo">
			<u-icon name="close" class="close" color="#fff" size="22" @click="showDemo = false"></u-icon>
			<image @click="showDemo = false" :src="demoImg" mode="widthFix"></image>
		</view>
	</view>
</template>

<script>
	import BaseUrl from '@/common/config.js';
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';
	import {
		apiurl
	} from '@/common/request/request';

	import {
		translateapp,
		translate,
		mp_compressImage
	} from "@/utils/compress.js"
	let rewardedVideoAd = null;
	export default {
		mixins: [],
		components: {},
		data() {
			return {

				showDemo: false,
				demoImg: 'https://oaigc.oss-cn-chengdu.aliyuncs.com/face/demo.jpg',
				leadBaseUrl: BaseUrl.leadBaseUrl,
				MjNewBaseUrl:BaseUrl.NewBaseUrl,
				// 艺术照
				tipList: ['五官清晰', '人像正面', '人脸无遮挡', '照片清晰'],

				showUpLoading1: false,
				showUpLoading2: false,
				// modal: '',
				myModal: '',
				myPhoto: '',

				selOptList: [
					'排序规则',
					'主题风格',
					'性别',
				],

				sexList: [
					'男',
					'女',
					'全部'
				],

				cankaoImgList: [],
				seledCankaoImg: null,
				seledCankaoImg_temp: {
					id: -1
				},

				rules: [
					'降序',
					'升序',
				],
				seledRule: '降序',

				styles: [

				],
				seledStyle: '国风',

				seledSex: '',

				showRule: false,
				showThem: false,
				showSex: false,

				showMorePopup: false,

sdShowLead:false,
mjShowLead :false,
				showHuiHuaLead: false,
				showLead2: false,
				showLead1: true,

				signShow: false,
				signTitle: '',
				tobheight: 45,
				platform: this.$platform.get(),
				indexList: [],


				show_gpt: false,
				gpt_keywords: '',
				gpt_text: '',
				cursor: 0,
				form: {
					name: '',
					init_image: '',
					prompt: '',
					width: '',
					height: '',
					guidance_scale: '7',
					samples: '1',
					model_id: '',
					scheduler: 'DDPMScheduler',
					type: 'text2img',
					num_inference_steps: '30',
					// lora_model:'guofeng3-lora'
				},
				word: [],
				sentence: [],
				enable_face_enhance: false,
				is_last_layer_skip: false,
				ratioIndex: 0,
				isConnected: true, //是否有网
				page: 1,
				loadmore: 'loading',
				loading: true,
				slider: 50,
				value2: '',
				keywords: '',
				increase: '',
				noincrease: '',
				increaseswitch: false,
				keyword: ['莫斯科', '日落', '橄榄树', '椰子树', '小兔子梵高', '海底世界', '星球'],
				custyle: [{
					img: 'https://pub-8b49af329fae499aa563997f5d4068a4.r2.dev/generations/18134196791680595205.png',
					title: '真人模型'
				}, {
					img: 'https://pub-8b49af329fae499aa563997f5d4068a4.r2.dev/generations/17763741241683163592.png',
					title: '宠物模型'
				}, {
					img: 'https://pub-8b49af329fae499aa563997f5d4068a4.r2.dev/generations/4740030011682234157.png',
					title: '漫画模型'
				}, {
					img: 'https://pub-8b49af329fae499aa563997f5d4068a4.r2.dev/generations/20527297251680823430.png',
					title: '海底模型'
				}],
				showcoin: false,
				addSuc: false,
				plan: {},
				// needCoin: 0,
				cos_img: '',
				cos_id: 0,
				refer_img: '',
				refer_id: 0,
				// engine: 'sd',
				engine: 'ys',
				showmj: 0,
				current: 0,

				engineid: 0,
				needCoin: 0,
				gallerylist: [],
				galleryid: '',
				modelslist: [],
				modelsid: 0,
				xzmodels: '',
				showmode: false,
				noticebar: ['精美图片需要时间打磨，预计20秒-120秒出图',
					// '图片生成中请不要退出，否则可能会生成失败'
				],
				tabslist: ['艺术照', 'MJ绘图', 'SD绘图'],
				curNow: 0,
				cardswiper: [
					'https://cos.iseeds.xyz/cover/3.0-1.jpg',
					'https://cos.iseeds.xyz/cover/hhjmix-3.png',
					'https://cos.iseeds.xyz/style/gufeng1.png',
				],

				showconcern: false,
				gzhqrcode: '',
				proportion: '',


				status: 'nomore',
				page: 1,
				total: 0,
				limit: 12
			};
		},
		computed: {
			...mapGetters(['appInfo', 'homeTemplate', 'userInfo', 'isLogin', 'userData'])
		},
		async onLoad() {

			console.log('isLogin================', this.isLogin);
			this.getTempLiast({
				// sex: 1,
				init: true
			})
//艺术照如果不存在就设置成true
			this.showHuiHuaLead = !uni.getStorageSync('showHuiHuaLead')
//在MJ页面如果不存在就设置
			this.mjShowLead = !uni.getStorageSync('mjShowLead')
//在SD页面如果不存在就设置成true
			this.sdShowLead = !uni.getStorageSync('sdShowLead')
			console.log("uni.getStorageSync('showHuiHuaLead')", uni.getStorageSync('showHuiHuaLead'));



			if (this.platform == 'wxMiniProgram') {
				var menumtop = uni.getMenuButtonBoundingClientRect().top - uni.getSystemInfoSync().statusBarHeight;
				var paddingtop = uni.getSystemInfoSync().statusBarHeight + menumtop;
				this.tobheight = menumtop + paddingtop + uni.getMenuButtonBoundingClientRect().height;
			}
			if (this.$Route.query.prompt) {
				this.keywords = this.$Route.query.prompt
				if (this.$Route.query.refImg == "undefined") {
					// this.refer_img = ''
				} else {
					this.refer_img = this.$Route.query.refImg
				}

				this.cursor = this.$Route.query.prompt.length
				this.current = this.$Route.query.engine == 'rh' ? 0 : this.$Route.query.engine == 'mj' ? 1 : 2
				this.showmj = this.$Route.query.engine == 'rh' ? 0 : this.$Route.query.engine == 'mj' ? 1 : 2
				if (this.$Route.query.engine == 'sd') {
					this.form.samples = 1
					this.engine = 'sd'
					this.modelslist = []
					this.getModels();

				} else if (this.$Route.query.engine == 'mj') {
					this.form.samples = 4
					this.engine = 'mj'
					this.modelslist = []
					this.getModels();
				} else {
					// 艺术照-----创作相似待处理
					// this.$Route.query.rh_modalurl
				}
			} else {
				// rh优先展示
				this.getsubsection({
					index: 0
				})
			}
			this.gallery();
			this.getModels();
			this.getPlan()
		},
		onShow() {
			// 网络变化检测
			uni.onNetworkStatusChange(res => {
				this.isConnected = res.isConnected;

			});
			if (this.isLogin) {
				this.getUserData();

			}
			this.systemwechat()
		},
		onReady() {
			// #ifdef MP-WEIXIN
			if (wx.createRewardedVideoAd && this.appInfo.video_status == 1) {
				rewardedVideoAd = wx.createRewardedVideoAd({
					adUnitId: this.appInfo.video_id
				});
				rewardedVideoAd.onLoad(() => {
					console.log('onLoad event emit');
				});
				rewardedVideoAd.onError(err => {
					console.log('onError event emit', err);
				});
				rewardedVideoAd.onClose(res => {
					if (res && res.isEnded) {
						// 正常播放结束，可以下发游戏奖励
						this.memberAddCoin();
						this.showcoin = false;
					} else {
						// 播放中途退出，不下发游戏奖励
						uni.showToast({
							title: '看完广告后才可获得积分哦',
							icon: 'none'
						});
					}
				});
			}
			// #endif
			this.loading = false;
		},
		methods: {
			...mapActions(['appInit', 'logout', 'getUserInfo', 'getUserData']),
			async scrollMore(e) {
				console.log('scrollMore', this.page * this.limit, this.total, this.status);
				if (this.status == 'loadmore') {
					this.status = 'loading'
					let p = {
						order: this.seledRule == '降序' ? 0 : 1,
						page: this.page,
						limit: this.limit
					}
					if (this.seledStyle.id != -1) {
						p['styleId'] = this.seledStyle.id
					}
					if (this.seledSex != '全部') {
						p['sex'] = this.seledSex == '男' ? 0 : 1
					}

					let res = await this.$http('ys.templateList', p)
					if (res.code == 0) {
						this.cankaoImgList = [...this.cankaoImgList, ...res.msg.data.data]
						this.page++
						this.total = res.msg.data.total

						if (this.page * this.limit < this.total) {
							this.status = 'loadmore'
						} else {
							this.status = 'nomore'
						}
					}
				}
			},
			toYszDetail() {
				this.showDemo = true
				// uni.previewImage({
				// 	urls: ['https://oaigc.oss-cn-chengdu.aliyuncs.com/face/demo.jpg'],
				// 	longPressActions: {
				// 		itemList: ['发送给朋友', '保存图片', '收藏'],
				// 		success: function(data) {},
				// 		fail: function(err) {}
				// 	}
				// });
			},
			handleOrder(item, index) {
				this.seledRule = item
				this.showRule = false

				let p = {
					order: this.seledRule == '降序' ? 0 : 1,
					init: false
				}
				if (this.seledStyle.id != -1) {
					p['styleId'] = this.seledStyle.id
				}
				if (this.seledSex != '全部') {
					p['sex'] = this.seledSex == '男' ? 0 : 1
				}
				this.getTempLiast(p)
			},
			handleSelStyle(item) {
				this.seledStyle = item
				this.showThem = false

				let p = {
					order: this.seledRule == '降序' ? 0 : 1,
					init: false
				}
				if (this.seledStyle.id != -1) {
					p['styleId'] = this.seledStyle.id
				}
				if (this.seledSex != '全部') {
					p['sex'] = this.seledSex == '男' ? 0 : 1
				}
				this.getTempLiast(p)
			},
			handleSelSex(item, index) {
				this.seledSex = item
				this.showSex = false

				let p = {
					order: this.seledRule == '降序' ? 0 : 1,
					init: false
				}
				if (this.seledStyle.id != -1) {
					p['styleId'] = this.seledStyle.id
				}
				if (this.seledSex != '全部') {
					p['sex'] = this.seledSex == '男' ? 0 : 1
				}
				this.getTempLiast(p)
			},
			async getTempLiast(p = {}) {
				this.page = 1
				p['page'] = this.page
				p['limit'] = this.limit

				console.log('getTempLiast----参数', p);
				uni.showLoading({
					title: '模板加载中...'
				})
				let res = await this.$http('ys.templateList', p)

				if (res.code == 0) {
					this.cankaoImgList = res.msg.data.data
					console.log(this.cankaoImgList) 
					this.total = res.msg.data.total
					if (this.page * this.limit < this.total) {
						this.status = 'loadmore'
					} else {
						this.status = 'nomore'
					}
					this.page++

					this.styles = [...res.msg.style, {
						id: -1,
						title: '全部'
					}]
					if (p.init) {
						this.seledStyle = {
							id: -1,
							title: '全部'
						}
						this.seledSex = '全部'
					}
					// 当没有点击创作相似，直接进入时
					if (!this.$Route.query.rh_modalurl) {
						this.seledCankaoImg = this.cankaoImgList[0]
						this.seledCankaoImg_temp = this.cankaoImgList[0]
						this.myModal = this.cankaoImgList[0].path

						console.log('直接进入', this.$Route.query.rh_modalId);
					} else {
						// 如果使用了模版
						if (this.$Route.query.rh_modalId != -1) {
							let sameCankaoImg = this.cankaoImgList.find((item, index) => {
								return item.id == this.$Route.query.rh_modalId
							})
							this.seledCankaoImg = sameCankaoImg
							this.seledCankaoImg_temp = sameCankaoImg
							this.myModal = sameCankaoImg.path
							console.log('使用了模版', this.$Route.query.rh_modalId);
							// 用户自己上传的模版图
						} else {
							console.log('用户自己上传的模版图', this.$Route.query.rh_modalId);
							this.seledCankaoImg = {
								id: -1
							}
							this.seledCankaoImg_temp = {
								id: -1
							}
							this.myModal = this.$Route.query.rh_modalurl
						}
					}


					uni.hideLoading()
					console.log('艺术照模板列表返回值---', this.cankaoImgList, res);
				}
			},
			handleSelModal(item, index) {
				this.seledCankaoImg = item;
				this.myModal = item.path;
				if (this.seledCankaoImg_temp.id == item.id) {
					uni.previewImage({
						urls: [item.path],
						longPressActions: {
							itemList: ['发送给朋友', '保存图片', '收藏'],
							success: function(data) {
								console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data
									.index + 1) + '张图片');
							},
							fail: function(err) {
								console.log(err.errMsg);
							}
						}
					});
				}
				this.seledCankaoImg_temp = item;
			},

			handleSelMoreModal(item, index) {
				if (this.seledCankaoImg_temp.id == item.id) {
					uni.previewImage({
						urls: [item.previewUrl],
						longPressActions: {
							itemList: ['发送给朋友', '保存图片', '收藏'],
							success: function(data) {
								console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data
									.index + 1) + '张图片');
							},
							fail: function(err) {
								console.log(err.errMsg);
							}
						}
					});
				}
				this.seledCankaoImg_temp = item
			},



			async genYishuZhao() {
				if (!this.myModal) {
					return uni.showToast({
						title: '请上传模板图',
						icon: 'none'
					})
				}
				if (!this.myPhoto) {
					return uni.showToast({
						title: '请上传照片',
						icon: 'none'
					})
				}

				if (!uni.getStorageSync('token')) {
					uni.navigateTo({
						url: '/pages/user/signin'
					});
					uni.setStorageSync('route', '/pages/painting/draw');
					return;
				}

				// 金币余额校验
				if (this.userData.coin == 0) {
					var alias = this.appInfo.number_alias ? this.appInfo.number_alias : '点数';
					this.signTitle =
						"<p style='font-weight: 550;font-size: 16px;'>灵感一现需要<span style='color: #207CF7;padding: 0 4px;'>" +
						1 + "</span><span>" + alias +
						"</span></p><p style='padding-top: 10px;'>您当前有<span style='color: #207CF7;padding: 0 4px;'>" +
						this.userData.coin + "</span><span>" + alias +
						"</span>，不支持会员时长，无法生成，快去获取<span>" + alias +
						"</span>吧</p>"
					this.signShow = true
					return;
				}

				let p = {
					templateUrl: this.myModal,
					userUrl: this.myPhoto,
				}

				getApp().ysParmas = p
				uni.navigateTo({
					// url: '/pages/painting/ys?ysParmas=' + JSON.stringify(p),
					url: '/pages/painting/ys',
				})
				console.log('生成艺术照参数', p);
			},
			// 处理图片压缩
			// test() {
			// 	let _this = this
			// 	uni.chooseImage({
			// 		count: 1, //默认9
			// 		sizeType: ['original', 'compressed'],
			// 		sourceType: ['camera', 'album'], 
			// 		success: function(res) {
			// 			translate(res.tempFilePaths[0], 0.3, ' ', imgUrl => {
			// 				uni.previewImage({
			// 					urls: [imgUrl],
			// 					longPressActions: {
			// 						itemList: ['发送给朋友', '保存图片', '收藏'],
			// 						success: function(data) {
			// 							console.log('选中了第' + (data.tapIndex + 1) +
			// 								'个按钮,第' + (data.index + 1) + '张图片');
			// 						},
			// 						fail: function(err) {
			// 							console.log(err.errMsg);
			// 						}
			// 					}
			// 				});
			// 			})
			// 		}
			// 	});
			// },
			upYsImg(type) {
				if (type == 0 && this.myModal) {
					return uni.previewImage({
						urls: [this.myModal],
						longPressActions: {
							itemList: ['发送给朋友', '保存图片', '收藏'],
							success: function(data) {
								console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data
									.index + 1) + '张图片');
							},
							fail: function(err) {
								console.log(err.errMsg);
							}
						}
					});
				}
				if (type == 1 && this.myPhoto) {
					return uni.previewImage({
						urls: [this.myPhoto],
						longPressActions: {
							itemList: ['发送给朋友', '保存图片', '收藏'],
							success: function(data) {
								console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data
									.index + 1) + '张图片');
							},
							fail: function(err) {
								console.log(err.errMsg);
							}
						}
					});
				}



				let that = this;
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['camera', 'album'], //从相册选择
					success: function(res) {
						console.log('上传参考图返回值：', res, res.tempFiles[0].name.toLowerCase());
						if (!(res.tempFiles[0].name.toLowerCase().endsWith('.png') || res
								.tempFiles[0].name
								.toLowerCase().endsWith(
									'.jpeg') || res.tempFiles[0].name.toLowerCase()
								.endsWith('.jpg'))) {
							uni.showToast({
								title: '上传失败，请上传png、jpg和jpeg格式的图片',
								icon: 'none',
								duration: 2000
							})
							return
						}
						console.log(res.tempFiles[0].size, res.tempFiles[0].size /
							1048576);
						if (res.tempFiles[0].size > 10 * 1048576) {
							return uni.showToast({
								title: '上传失败，图片大小超10M',
								icon: 'none',
								duration: 2000
							})
						}

						/**
						 * H5端图片压缩
						 *  参数说明：
						 *  imgSrc 图片url
						 *  scale缩放比例 0-1
						 *  type 返回图片类型：base64、blob（默认blob）   
						 *  callback 回调设置返回值 
						 */
						// uni.showLoading({
						// 	title: '图片压缩中...'
						// });
						// translate(res.tempFilePaths[0], 0.3, ' ', imgUrl => {
						// 	uni.hideLoading()
						// 	console.log('imgUrl', imgUrl);

						// 	if (type == 0) {
						// 		that.showUpLoading1 = true
						// 	} else {
						// 		that.showUpLoading2 = true
						// 	}
						// 	uni.uploadFile({
						// 		url: apiurl('common/upload'),
						// 		filePath: imgUrl,
						// 		name: 'file',
						// 		formData: {
						// 			accept: 'image',
						// 			upload_type: 'ali-oss'
						// 		},
						// 		success: res2 => {
						// 			let a = JSON.parse(res2.data);
						// 			if (a.code == 0) {
						// 				console.log('JSON.parse(res2.data)', a);
						// 				if (type == 0) {
						// 					that.seledCankaoImg = {
						// 						id: -1
						// 					}
						// 					that.myModal = a.data.path;
						// 					that.showUpLoading1 = false
						// 				} else {
						// 					that.myPhoto = a.data.path;
						// 					that.showUpLoading2 = false
						// 				}
						// 			} else {
						// 				uni.showToast({
						// 					title: '上传图片失败',
						// 					icon: 'none'
						// 				});
						// 			}
						// 		}
						// 	});
						// })



						// 原图片上传逻辑
						const path = res.tempFilePaths[0];
						console.log('path===================', path);
						if (type == 0) {
							that.showUpLoading1 = true
						} else {
							that.showUpLoading2 = true
						}
						uni.uploadFile({
							url: apiurl('common/upload'),
							filePath: path,
							name: 'file',
							formData: {
								accept: 'image',
								upload_type: 'ali-oss'
							},
							success: res2 => {
								let a = JSON.parse(res2.data);
								if (a.code == 0) {
									console.log('JSON.parse(res2.data)', a);
									if (type == 0) {
										that.seledCankaoImg = {
											id: -1
										}
										that.myModal = a.data.path;
										that.showUpLoading1 = false
									} else {
										that.myPhoto = a.data.path;
										that.showUpLoading2 = false
									}
								} else {
									uni.showToast({
										title: '上传图片失败',
										icon: 'none'
									});
								}
							}
						});
					}
				});
			},
			handleConfirmSel() {
				this.showMorePopup = false
				this.seledCankaoImg = this.seledCankaoImg_temp
				// this.modal = ''
				this.myModal = this.seledCankaoImg_temp.path

			},

			handleMorePopup() {
				this.showMorePopup = true
			},
			closeOver() {
				this.showRule = false
				this.showThem = false
				this.showSex = false
			},
			handleOpenOpt(index) {
				if (index == 0) {
					this.showRule = !this.showRule
					this.showThem = false
					this.showSex = false

				} else if (index == 1) {
					this.showRule = false
					this.showThem = !this.showThem
					this.showSex = false
				} else if (index == 2) {
					this.showRule = false
					this.showThem = false
					this.showSex = !this.showSex
				}
				console.log('index============', index, this.showRule, this.showThem, this.showSex);
			},
			nextLead() {
				this.showLead1 = false
				this.showLead2 = true
			},
			sdnextLead(){
				this.sdShowLead = false
				uni.setStorageSync('sdShowLead',true)		
				// console.log(333)
							},
			mjnextLead(){
				// console.log(33333)
				 this.mjShowLead = false
				
				uni.setStorageSync('mjShowLead',true)
			},
			finishLead() {
				this.showHuiHuaLead = false
				this.showLead2 = false
				uni.setStorageSync('showHuiHuaLead', true)
			},
			signSign() {
				uni.navigateTo({
					url: '/pages/user/member/member'
				});
				this.signShow = false
			},
			systemwechat() {
				this.$http('conf.getGroupConf', {
					group: 'system.wechat'
				}).then(res => {
					if (res.code == 0) {
						this.gzhqrcode = res.data.qrcode_path
						const focuson = uni.getStorageSync('focuson');
						// console.log(focuson);
						if (!focuson) {
							if (this.gzhqrcode) {
								if (this.isLogin && this.appInfo.is_show_logged_qrcode == 1) {
									this.showconcern = true
								}
							}
						}
					}
				})
			},
			concernclose() {
				this.showconcern = false
			},
			getsubsection(e) {
				this.showmj = e.index
				this.current = e.index

				console.log('this.current---------------', this.current);
				this.modelsid = 0
				if (e.index == 0) {
					// 新增艺术照类型
					this.form.samples = 1
					this.engine = 'ys'
					this.modelslist = []
					this.getModels();
				} else if (e.index == 1) {
					this.form.samples = 4
					this.engine = 'mj'
					this.modelslist = []
					this.getModels();
				} else if (e.index == 2) {
					this.form.samples = 1
					this.engine = 'sd'
					this.modelslist = []
					this.getModels();
				}
				this.initWords()
			},

			async getGpt() {
				if (!this.isLogin) {
					uni.navigateTo({
						url: '/pages/user/signin'
					});
					uni.setStorageSync('route', '/pages/painting/draw');
					return;
				}
				if (!this.gpt_keywords) {
					uni.showToast({
						title: '请填写描述词',
						icon: 'none'
					});
					return;
				}
				if (this.userData.coin == 0) {
					var alias = this.appInfo.number_alias ? this.appInfo.number_alias : '点数';
					this.signTitle =
						"<p style='font-weight: 550;font-size: 16px;'>灵感一现需要<span style='color: #207CF7;padding: 0 4px;'>" +
						1 + "</span><span>" + alias +
						"</span></p><p style='padding-top: 10px;'>您当前有<span style='color: #207CF7;padding: 0 4px;'>" +
						this.userData.coin + "</span><span>" + alias +
						"</span>，不支持会员时长，无法生成，快去获取<span>" + alias +
						"</span>吧</p>"
					this.signShow = true
					return;
				}
				uni.showLoading({
					title: '内容审核中...'
				})
				// #ifdef H5
				let check = this.appInfo.is_h5_filter && this.appInfo.is_h5_filter == 1 ?
					await this.getcheckText(this
						.gpt_keywords) :
					1;
				// #endif
				// #ifdef MP-WEIXIN
				let check = await this.getcheckText(this.gpt_keywords);
				// #endif
				if (check == 1) {
					uni.showLoading({
						title: '咒语生成中...'
					})
					this.$http('gallery.chat', {
						prompt: this.gpt_keywords
					}).then(res => {
						if (res.code == 0) {
							this.gpt_text = res.data;
							uni.hideLoading();
						} else {
							uni.hideLoading();
							uni.showToast({
								title: '使用咒语失败,请尝试重试',
								icon: 'none'
							});
						}
					});
				}
			},
			setGpt() {
				// console.log(this.gpt_text.indexOf("英文："));
				if (this.gpt_text.indexOf("英文：") != -1) {
					let index = this.gpt_text.indexOf("英文：");
					let text = this.gpt_text.substring(index + 3);
					// console.log(text);
					this.keywords = text
					this.cursor = this.keywords.length
					// console.log(this.keywords.length);
				} else {
					let text = this.gpt_text;
					this.keywords = text
					this.cursor = this.keywords.length
				}
				this.show_gpt = false
			},
			textareainput(e) {
				// console.log(e.detail.cursor);
				this.cursor = e.detail.cursor
			},
			sectionChange(index) {
				this.curNow = index;
			},
			gallery() {
				let that = this;
				this.$http('gallery.getWords').then(res => {
					if (res.code == 0) {
						this.gallerylist = res.data
					}
				});
			},
			getModels() {
				let that = this;
				this.$http('gallery.getModels', {
					engine: that.engine
				}).then(res => {
					if (res.code == 0) {
						uni.setNavigationBarTitle({
							title: this.appInfo.site_name
						});
						if (that.engine == "mj") {
							this.modelslist = res.data.reverse()
						} else if (that.engine == "sd") {
							this.modelslist = res.data
						} else {
							this.modelslist = res.data
						}
						this.form.model_id = this.modelslist[this.modelsid].model_id
							.toString()
						this.form.name = this.modelslist[this.modelsid].name
						this.xzmodels = this.modelslist[this.modelsid].name

						if (this.$Route.query.model_name) {
							for (var ty = 0; ty < this.modelslist.length; ty++) {
								if (this.$Route.query.model_name == this.modelslist[ty]
									.name) {
									this.modelsid = ty
									this.form.model_id = this.modelslist[ty].model_id
										.toString()
									this.xzmodels = this.modelslist[ty].name
									this.form.name = this.modelslist[ty].name
								}
							}
						}

						console.log('模型列表---', this.modelslist);
					}
				});
			},
			tapgallery(e) {
				// console.log(this.gallerylist[e].guide.slice(0,500));
				this.keywords = this.gallerylist[e].guide.slice(0, 500)
				this.galleryid = this.gallerylist[e].id
				this.cursor = this.keywords.length
			},

			changepolish() {
				// console.log(e);

				uni.showLoading({
					title: '描述增幅中...'
				})
				this.$http('gallery.chat', {
					prompt: this.keywords
				}).then(res => {
					if (res.code == 0) {
						// this.increaseswitch = e
						// this.increase = res.data
						this.keywords = res.data
					}
				});
				// if(e){
				// 	if(this.increase){
				// 		this.keywords = this.increase
				// 		return;
				// 	}
				// 	this.increaseswitch = false
				// 	uni.showLoading({
				// 		title:'描述增幅中...'
				// 	})
				// 	this.noincrease = this.keywords
				// 	this.$http('gallery.chat', {prompt:this.keywords}).then(res => {
				// 		if (res.code == 0) {
				// 			this.increaseswitch = e
				// 			this.increase = res.data
				// 			this.keywords = res.data
				// 		}
				// 	});
				// 	return;
				// }
				// this.keywords = this.noincrease

			},
			getincrease() {
				var that = this;
				if (!this.keywords) {
					uni.showToast({
						title: '请输入描述',
						icon: 'none'
					})
					return;
				}
				uni.showModal({
					confirmText: '立即增幅',
					// showCancel:false,
					confirmColor: '#207CF7',
					content: '如果你正在寻找灵感,或懒得输入描述词,开启描述增幅GTP模型将自动根据你的输入的描述词为你补充描述词',
					title: '提示',
					success(res) {
						if (res.confirm) {
							that.changepolish()
						}
					}
				});
			},
			// loadmores() {
			// 	for (let i = 0; i < 30; i++) {
			// 		this.indexList.push({
			// 			url: this.urls[uni.$u.random(0, this.urls.length - 1)]
			// 		});
			// 	}
			// },

			getPlan() {
				this.$http('conf.getGroupConf', {
					group: 'system.plan'
				}).then(res => {
					if (res.code == 0) {
						this.plan = res.data;
						uni.setNavigationBarTitle({
							title: this.appInfo.site_name
						});
						// console.log(this.plan);
					}
				});
			},
			initWords() {
				this.gallerylist = uni.$u.randomArray(this.gallerylist)
			},
			ratio(e) {
				this.ratioIndex = e;
			},
			onExtend(e) {
				if (e == 0) {
					this.form.enable_face_enhance = !this.enable_face_enhance;
				} else {
					this.form.is_last_layer_skip = !this.is_last_layer_skip;
				}
			},
			onWords(e) {
				this.keywords = this.keywords ? this.keywords + ',' + e : e;
			},
			async createClick() {
				if (this.current != 0) {
					var that = this;
					if (!this.isLogin) {
						uni.navigateTo({
							url: '/pages/user/signin'
						});
						uni.setStorageSync('route', '/pages/painting/draw');
						return;
					}
					if (that.appInfo.time_member && that.appInfo.time_member == 1) {
						if (that.showmj == 1) {
							if (that.userData.vip_info && that.userData.is_validity > 0 && that
								.userData.vip_info
								.mj_used ==
								that.userData.vip_info.mj_times && this.userData.coin < this
								.plan.unlock_mj_aipainting
							) {
								var alias = that.appInfo.number_alias ? that.appInfo
									.number_alias : '点数';
								// this.signTitle = "<p style='font-weight: 550;font-size: 16px;'>您的绘画<span>" + alias +
								// 	"</span>不足或会员套餐内剩余绘画次数不足，无法生成绘画</p>"
								this.signTitle =
									"<p style='font-weight: 550;font-size: 16px;'>绘画需要<span style='color: #207CF7;padding: 0 4px;'>" +
									that.plan.unlock_mj_aipainting + "</span><span>" + alias +
									"</span></p><p style='padding-top: 10px;'>您的绘画<span>" +
									alias +
									"</span>不足或会员套餐内剩余次数不足，无法生成绘画</p>"
								this.signShow = true
								return;
							}
							if (that.userData.is_validity == 0 && this.userData.coin < this
								.plan
								.unlock_mj_aipainting) {
								var alias = that.appInfo.number_alias ? that.appInfo
									.number_alias : '点数';
								this.signTitle =
									"<p style='font-weight: 550;font-size: 16px;'>绘画需要<span style='color: #207CF7;padding: 0 4px;'>" +
									that.plan.unlock_mj_aipainting + "</span><span>" + alias +
									"</span></p><p style='padding-top: 10px;'>您的绘画<span>" +
									alias +
									"</span>不足或会员套餐内剩余次数不足，无法生成绘画</p>"
								this.signShow = true
								return;
							}
						} else if (that.showmj == 2) {
							if (that.userData.vip_info && that.userData.is_validity > 0 && that
								.userData.vip_info
								.sd_used == that.userData.vip_info
								.sd_times && this.userData.coin < (this.plan
									.unlock_aipainting * this.form.samples)) {
								var alias = that.appInfo.number_alias ? that.appInfo
									.number_alias : '点数';
								// this.signTitle = "<p style='font-weight: 550;font-size: 16px;'>您的绘画<span>" + alias +
								// 	"</span>不足或会员套餐内剩余次数不足，无法生成绘画</p>"
								this.signTitle =
									"<p style='font-weight: 550;font-size: 16px;'>绘画需要<span style='color: #207CF7;padding: 0 4px;'>" +
									(this.plan.unlock_aipainting * this.form.samples) +
									"</span><span>" + alias +
									"</span></p><p style='padding-top: 10px;'>您的绘画<span>" +
									alias +
									"</span>不足或会员套餐内剩余次数不足，无法生成绘画</p>"
								this.signShow = true
								return;
							}
							if (that.userData.is_validity == 0 && this.userData.coin < (this
									.plan.unlock_aipainting *
									this
									.form.samples)) {
								var alias = that.appInfo.number_alias ? that.appInfo
									.number_alias : '点数';
								this.signTitle =
									"<p style='font-weight: 550;font-size: 16px;'>绘画需要<span style='color: #207CF7;padding: 0 4px;'>" +
									(this.plan.unlock_aipainting * this.form.samples) +
									"</span><span>" + alias +
									"</span></p><p style='padding-top: 10px;'>您的绘画<span>" +
									alias +
									"</span>不足或会员套餐内剩余次数不足，无法生成绘画</p>"
								this.signShow = true
								return;
							}
						}
					} else {
						if (that.showmj == 1 && this.userData.coin < this.plan
							.unlock_mj_aipainting) {
							var alias = that.appInfo.number_alias ? that.appInfo.number_alias :
								'点数';
							this.signTitle =
								"<p style='font-weight: 550;font-size: 16px;'>mj绘画需要<span style='color: #207CF7;padding: 0 4px;'>" +
								this.plan.unlock_mj_aipainting + "</span><span>" + alias +
								"</span></p><p style='padding-top: 10px;'>您当前有<span style='color: #207CF7;padding: 0 4px;'>" +
								this.userData.coin + "</span><span>" + alias +
								"</span>，无法生成绘画，快去获取<span>" + alias +
								"</span>吧</p>"
							this.signShow = true
							return;
						}
						if (that.showmj == 2 && this.userData.coin < (this.plan
								.unlock_aipainting * this.form
								.samples)) {
							var alias = that.appInfo.number_alias ? that.appInfo.number_alias :
								'点数';
							this.signTitle =
								"<p style='font-weight: 550;font-size: 16px;'>sd绘画需要<span style='color: #207CF7;padding: 0 4px;'>" +
								this.plan.unlock_aipainting * this.form.samples +
								"</span><span>" + alias +
								"</span></p><p style='padding-top: 10px;'>您当前有<span style='color: #207CF7;padding: 0 4px;'>" +
								this.userData.coin + "</span><span>" + alias +
								"</span>，无法生成绘画，快去获取<span>" + alias +
								"</span>吧</p>"
							this.signShow = true
							return;
						}
					}
					if (!this.keywords) {
						uni.showToast({
							title: '请输入画面描述词',
							icon: 'none'
						});
						return;
					}
					if (!this.form.model_id) {
						uni.showToast({
							title: '请选择绘图模型',
							icon: 'none'
						});
						return;
					} else {
						uni.showLoading({
							title: '内容审核中...'
						})
						// #ifdef H5
						let check = this.appInfo.is_h5_filter && this.appInfo.is_h5_filter ==
							1 ? await this
							.getcheckText(
								this.keywords) :
							1;
						// #endif
						// #ifdef MP-WEIXIN
						let check = await this.getcheckText(this.keywords);
						// #endif
						if (check == 1) {
							this.aiPlay(this.refer_img + ' ' + this.keywords);
						}
					}
				}
			},
			getcheckText(e) {
				var that = this;
				return new Promise((resolve, reject) => {
					that.$http('ai.checkText', {
						prompt: e
					}).then(res => {
						if (res.code == 0) {
							resolve(1);
						}
					})
				});
			},
			gallerychat() {
				uni.showLoading({
					title: '润色中...'
				})
				this.$http('gallery.chat', {
					prompt: this.keywords
				}).then(res => {
					if (res.code == 0) {
						this.aiPlay(res.data);
					}
				});
			},
			aiPlay(e) {
				let that = this;
				that.form.prompt = e;
				switch (this.ratioIndex) {
					case 0:
						that.form.width = '512';
						that.form.height = '512';
						that.proportion = '';
						break;
					case 1:
						that.form.width = '512';
						that.form.height = '768';
						that.proportion = ' --ar 3:4';
						break;
					case 2:
						that.form.width = '768';
						that.form.height = '512';
						that.proportion = ' --ar 4:3';
						break;
					case 3:
						that.form.width = '512';
						that.form.height = '1024';
						that.proportion = ' --ar 9:16';
						break;
					case 4:
						that.form.width = '1024';
						that.form.height = '512';
						that.proportion = ' --ar 16:9';
						break;
				}

				if (that.refer_img) {
					that.form.init_image = that.refer_img;
					that.form.type = 'img2img';
				} else {
					that.form.type = 'text2img';
				}

				that.form.keywords = that.keywords
				console.log(that.form);

				uni.navigateTo({
					url: that.showmj == 1 ? '/pages/painting/generate?prompt=' + (that
							.form.prompt + (that
								.proportion ?
								that.proportion : '')) +
						'&model_id=' + (that.modelslist.length > 0 ? this.form
							.model_id : '') + '&version=' + (that
							.modelslist.length > 0 ? that.modelslist[this.modelsid]
							.version : '-- v5') +
						'&needCoin=' + that.plan.unlock_mj_aipainting +
						`&refImg=${that.refer_img?that.refer_img:''}&keywords=${that.keywords}` : that.showmj ==
						2 ?
						'/pages/painting/details?form=' + JSON
						.stringify(this.form) : '/pages/ys/ys'
				});
				console.log('创作相似url传递的参数：', this.form);
			},
			close_blur_view() {
				this.showcoin = false;
			},
			toMember() {
				uni.navigateTo({
					url: '/pages/member/member'
				});
			},
			toWelfare() {
				uni.switchTab({
					url: '/pages/welfare/welfare'
				});
			},
			showVideoAd() {
				if (rewardedVideoAd) {
					uni.showToast({
						title: '广告拉取中',
						icon: 'none'
					});
					rewardedVideoAd.show().catch(() => {
						// 失败重试
						rewardedVideoAd
							.load()
							.then(() => rewardedVideoAd.show())
							.catch(err => {
								console.log('激励视频 广告显示失败');
								uni.showToast({
									title: '广告显示失败',
									icon: 'none'
								});
							});
					});
				}
			},
			memberAddCoin() {
				this.$http('member.addCoin', {
					type: 'video'
				}).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: '获得积分+' + res.data
						});
						// let coin = {coin: this.userData.coin+1}
						// that.$store.commit('userData',coin)
						this.getUserInfo();
					} else {
						uni.showToast({
							title: '获得积分失败',
							icon: 'none'
						});
					}
				});
			},
			uploadImg(engineid) {
				let that = this;
				uni.chooseImage({
					count: 1, //count: 6, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {

						console.log('上传参考图返回值：', res.tempFiles[0].name, res
							.tempFiles[0].name.toLowerCase());
						if (!(res.tempFiles[0].name.toLowerCase().endsWith(
									'.png') || res.tempFiles[0].name
								.toLowerCase().endsWith(
									'.jpeg') || res.tempFiles[0].name.toLowerCase()
								.endsWith('.jpg'))) {
							uni.showToast({
								title: '上传失败，请上传png、jpg和jpeg格式的图片',
								icon: 'none',
								duration: 2000
							})
							return
						}
						const path = res.tempFilePaths[0];
						uni.uploadFile({
							url: apiurl('common/upload'),
							filePath: path,
							// name: 'img',
							// formData: {
							// 	platform: $platform.get(),
							// 	accept: 'image'
							// },
							name: 'file',
							formData: {
								accept: 'image',
								upload_type: 'ali-oss'
							},
							success: res2 => {
								let a = JSON.parse(res2.data);
								if (a.code == 0) {
									// if (engineid == 0) {
									// 	that.cos_img = a.data.path;
									// 	that.cos_id = a.data.id;
									// } else {
									that.refer_img = a.data.path;
									that.refer_id = a.data.id;

									that.form.refer_img = a.data.path
									// }
								} else {
									uni.showToast({
										title: '上传图片失败',
										icon: 'none'
									});
								}
							}
						});
					}
				});
			},
			preViewImg(img) {
				uni.previewImage({
					urls: [img],
					longPressActions: {
						itemList: ['发送给朋友', '保存图片', '收藏'],
						success: function(data) {},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			deleteImg() {
				// if (engineid == 0) {
				// 	this.cos_img = '';
				// 	this.cos_id = 0;
				// } else {
				this.refer_img = '';

				this.form.refer_img = ''
				this.form.init_image = ''
				// this.refer_id = 0;
				// }
			},
			open() {
				// console.log('open');
			},

		}
	};
</script>

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