<template>
	<view class="container">
		<!-- <wike-skeleton :count="4" v-if="homeTemplate.length === 0"></wike-skeleton> -->
		
		<view>
			<view class="directask">
				<!-- 📝 -->
				<view class="askaquestion u-flex align-center">
					<!-- <image src="/static/images/ask.png"></image> -->
					📝直接提问</view>
				<view class="textarea">
					<u--textarea @focus="focustextarea" maxlength="-1" v-model="valuechat" height="100" border="none"
						placeholder="您可以向Ai提出任何问题..."></u--textarea>
					<view class="operate u-flex align-center">
						
						<view @click="valuechat = ''" class="empty">清空</view>
						<view @click="ondraw" v-if="appInfo.is_aipainting&&appInfo.is_aipainting == 1" style="background: #ffc107;margin-right: 30rpx;border: #ffc107 1px solid;" hover-class="hoversubmit" class="submit">Ai绘画</view>
						<view @click="onSubmit(valuechat)" hover-class="hoversubmit" class="submit">提交问题</view>
					</view>
					</view>
					</view>
					</view>
	</view>
</template>

<script>
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';
	let interstitialAd = null,
		timer,
		time2;
	export default {
		components: {},
		data() {
			return {
				onTabbar: false,
				isShowAnimate: false,
				valuechat: '',
				platform: this.$platform.get(),
				h5share: false
			};
		},
		computed: {
			...mapGetters(['appInfo', 'isLogin', 'userInfo', 'homeTemplate', 'userData'])
		},
		watch: {
			appInfo: function(e) {
				let that = this;
				uni.setNavigationBarTitle({
					title: that.appInfo.site_name
				});
			}
		},
		onLoad() {
			var that = this;
			uni.getSystemInfo({
				success: function(res) {}
			});
			setTimeout(() => {
				that.onTabbar = true;
				that.isShowAnimate = true;
			}, 500);
		},
		onReady() {
			let that = this;
			// #ifdef MP-WEIXIN
			clearTimeout(timer);
			// 在适合的场景显示插屏广告
			timer = setTimeout(function() {
				// 在页面onLoad回调事件中创建插屏广告实例
				if (wx.createInterstitialAd && that.appInfo.interstitial_status == 1) {
					interstitialAd = wx.createInterstitialAd({
						adUnitId: that.appInfo.interstitial_id
					});
					interstitialAd.onLoad(() => {});
					interstitialAd.onError(err => {});
					interstitialAd.onClose(() => {
						if (that.appInfo.interstitial_infinite_status == 1) {
							that.showInterstitial();
						}
					});
					interstitialAd.show().catch(err => {
						console.error(err);
					});
				}
			}, 4000);
			// #endif
		},
		onShow() {
			if (this.isLogin) {
				this.getUserData();
			}
		},
		onUnload() {
			clearInterval(time2);
		},
		methods: {
			...mapActions(['appInit', 'logout', 'getUserInfo', 'getUserData']),
			init() {
				var that = this;
				return Promise.all([this.appInit()]).then(res => {
					
				});
			},
			showInterstitial() {
				time2 = setInterval(
					function() {
						interstitialAd.show().catch(err => {
							console.error(err);
						});
					},
					this.appInfo.gap ? this.appInfo.gap * 1000 : 12000
				);
			},
			updateTemplate() {
				this.$store.dispatch('getTemplate');
			},
			onToForm() {
				uni.navigateTo({
					url: '/pages/chat/chat'
				});
			},
			onhelper() {
				uni.switchTab({
					url: '/pages/template/template'
				});
			},
			focustextarea() {
		
			},
			ondraw(){
				
				uni.navigateTo({
					url: '/pages/chat/chat?draw=1'
				});
			},
			onSubmit(e) {
				// console.log(e);
				var that = this;
				if (!e) {
					uni.showToast({
						title: '请输入关键词或问题',
						icon: 'none'
					});
					return;
				}
				uni.navigateTo({
					url: '/pages/chat/chat?question=' + e
				});
				that.valuechat = ''
			}
		}
	};
</script>

<style lang="scss">
	.container{
		// margin-top: 25%;
	}
	.top-notice {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
	}

	.form {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		margin-top: 15%;

		.title {
			font-size: 38rpx;
			font-weight: bolder;
			// margin-top: 15rpx;
			margin: 15rpx 35rpx 0;
		}

		.desc {
			// margin-top: 15rpx;
			font-size: 28rpx;
			color: #666;
			margin: 15rpx 35rpx;
		}

		.btn-group {
			width: 80%;
			// margin-top: 26%;
            // margin-bottom: 42%;
			    position: absolute;
			    bottom: 80px;
                padding-bottom: env(safe-area-inset-bottom);
			.btn {
				margin: 30rpx 0rpx;

				.u-button {
					height: 100rpx;
				}
			}
		}
	}

	.directask {
		padding: 30rpx 30rpx 200rpx;
		border-top: 1px solid #ededed;

		.askaquestion {
			font-size: 32rpx;
			margin-bottom: 25rpx;
			image{
				width: 32rpx;
				height: 32rpx;
				margin-right: 12rpx;
			}
		}

		.textarea {
			box-shadow: 0px 0px 10px 5px #9e9e9e36;
			margin-top: 30rpx;
			margin-bottom: 30rpx;
			border-radius: 20rpx;
			padding: 20rpx 30rpx 30rpx 12rpx;

			.u-textarea {
				border-radius: 20rpx;
			}

			.operate {
				justify-content: flex-end;

				.empty {
					margin-right: 30rpx;
					border: 1px solid #9e9e9e;
					color: #9e9e9e;
					padding: 12rpx 42rpx;
					border-radius: 10rpx;
				}

				.submit {
					padding: 12rpx 42rpx;
					border-radius: 10rpx;
					border: 1px solid #26b3a0;
					background: #26b3a0;
					color: #fff;
				}

				.hoversubmit {
					background: #f7f7f7;
					color: #acacb3;
				}
			}
		}

		.case {
			color: #26b3a0;
			background: #f5f8f7;
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			font-size: 30rpx;
			padding-left: 30rpx;
			border-radius: 10rpx;
			margin: 25rpx 0;
			border-radius: 10rpx;
			overflow: hidden;
			display: -webkit-box !important;
			text-overflow: ellipsis;
			word-break: break-all;
			-webkit-line-clamp: 1;
			-webkit-box-orient: vertical !important;
		}

		.helpme {
			background: #f5f8f7;
			border-radius: 20rpx;
			padding: 30rpx;
			width: 48%;

			margin-bottom: 25rpx;

			height: 92px;

			.title {
				font-size: 30rpx;
				font-weight: bold;
				margin-bottom: 18rpx;
				color: #000;
				overflow:hidden; text-overflow:ellipsis; white-space:nowrap
			}

			.sub_title {
				color: #8f9ca2;
				font-size: 24rpx;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
			}
		}
	}

	.wxad {
		border-radius: 20rpx;
		overflow: hidden;
		margin-bottom: 24rpx;
	}

	.cu-dialog {
		position: fixed;

		top: 60rpx;
		left: 100rpx;
		// background: #000000;
	}

	.guide-img {
		width: 580rpx;
		height: 430rpx;
	}
</style>