<template>
	<view class="main-container">
		<view class="sub-title">
			AI智能问答
		</view>
		<view class="enters-view">
			<view class="enter-view" v-for="(item, index) in chatTypes">
				<view class="enter-box">
					{{ item.name }}
				</view>
			</view>
		</view>
		 
	</view>
</template>

<script>
	// import messageShow from '../components/messageshow.vue';
	import request from '@/api/request.js'
	import { wxlogin, shareSuccess, updateUserName, getUserinfo } from '@/api/index.js';
	import { mapState, mapMutations } from 'vuex'
	import { dateFormat } from '@/common/util.js'
	import { curVersion } from '@/common/config.js'
	import { CHAT_TYPE } from '@/common/enum.js'
	export default {
		data() {
			return {
				CHAT_TYPE,
				index: 1,
				info: {
					user: 'ai',
					// status: 'WAITING',
					content: '欢迎加入AI降临派，有什么我可以帮助你的吗?'
				},
				code: '',
				chatTypes: [
					{ name: '智能问答', type: CHAT_TYPE.NORMAL, enable: true },
					{ name: '科学问答', type: CHAT_TYPE.SCIENCE, enable: true },
					{ name: '小作文版', type: CHAT_TYPE.WRITER, enable: true },
					{ name: '情景对话', type: CHAT_TYPE.SCENE, enable: false }
				],
				chatDesc: null,
				chatDescList: [{
					mainTitle: 'AI降临派提供基于最新人工智能技术的问答机器人，可以为您解决如下几类问题：',
					skills : [
						` - 知乎百度答题，做作业`,
						` - 文案润色、翻译、创意、写诗词`
					],
					subtitle: `您可以尝试这样提问:`,
					qestions: [
						` - 请帮我作一首关于月亮的诗?`,
						` - 请帮我做一个市场营销方案。`
					],
					times: 1
				},
				{
					mainTitle: '在基础版的能力上，回答问题更严谨，回答长度也有所增加，更适合用来：',
					skills : [
						` - 做作业，写代码，写论文`,
						` - 探讨各领域学术问题 `
					],
					subtitle: `您可以尝试这样提问:`,
					qestions: [
						` - 锂与稀硫酸反应的化学方程式`,
						` - AI技术发展对人类的影响是什么？`
					],
					times: 'scienceSpend'
				},
				{
					mainTitle: '在基础版的能力上，扩展了AI回答的文字长度，并且文字表达更具创意，更适合用来：',
					skills : [
						` - 活动策划、产品宣传稿、广告创意`,
						` - 写作文、写儿歌、各类公文写作`
					],
					subtitle: `您可以尝试这样提问:`,
					qestions: [
						` - 请写一篇产品宣传文案，主要卖点是……`,
						` - 请以感恩祖国为主题写一篇文章。`
					],
					times: 'writerSpend'
				}, null
				]
			};
		},
		computed: {
			...mapState(['userId', 'chatToken', 'version', 'chatType', 'invited', 'settings']),
		},
		components: {
			
		},
		onLoad(option) {
			console.log('main page onLoad option:', option);
			const idex = this.chatTypes.findIndex(m => m.type === this.chatType)
			this.chatDesc = this.chatDescList[idex]
			if (option.uid && option.uid != 'undefined') {
				this.setShareId(option.uid)
			}
			if (!this.chatToken || curVersion !== this.version) {
				this.$store.dispatch('login').then(rst => {
				})
			} else {
				this.updateUserinfo()
			}
		},
		created() {			
			wx.getSystemInfo({
			  success (res) {
			    console.log(res)
			  }
			})
			wx.showShareMenu({
				withShareTicket: true,
				//设置下方的Menus菜单，才能够让发送给朋友与分享到朋友圈两个按钮可以点击
				menus: ["shareAppMessage", "shareTimeline"]
			})
		},
		mounted() {
		},
		methods: {
			...mapMutations(['setLoginInfo', 'setSessionId', 'setVersion', 'setShareId', 'setChatType', 'setInvited']),
			changetype(item, index) {
				this.setChatType(item.type)
				this.chatDesc = this.chatDescList[index]
			},
			async updateUserinfo() {
				const res = await getUserinfo()
				if (res.code === 0) {
					this.setLoginInfo(res.data)
					uni.stopPullDownRefresh();
				}
			},
			async gotoChat() {
				const item = this.chatTypes.find(m => m.type === this.chatType)
				if (!item.enable) {
					return
				}
				
				if (!this.chatToken) {
					this.$store.dispatch('login').then(rst => {
						uni.navigateTo({
						 	url: '/pages/ai/chat/chat'
						});
					})
				} else {
					uni.navigateTo({
						url: '/pages/ai/chat/chat'
					});
				}
			},
			gotoDraw() {
				uni.navigateTo({
					url: '/pages/ai/draw/draw'
				});
			},
			onShareAppMessage: function (obj) {
				setTimeout(() => {
					this.setInvited(1)
				}, 3000)
				let path = `/pages/ai/main/main?uid=${this.userId}`
				let title = '加入AI降临派，与AI真神对话！'
				// 分享配置
				return { title,	path };
			},
			adShareTimes: async function() {
				const that = this
				const rst = await shareSuccess()
				if (rst.code === 0) {
					wx.showToast({
						title: `恭喜您，获得${that.settings.share.addTimes}次提问次数`,
						icon: 'none',
						duration: 2000
					})
				}
			},
			onShareTimeline() {
				let path = `/pages/ai/main/main?uid=${this.userId}`
				let title = '加入AI降临派，与AI真神对话！'
				return { title,	path }
			}
		}
	}
</script>

<style lang="less" scoped>
	.main-container {
		padding: 20rpx 40rpx;
		background-color: @mainBg;
		height: 100%;
		.sub-title {
			padding: 0 16rpx;
			color: @fontColor;
		}
		.enters-view {
			display: flex;
			flex-wrap: wrap;
			.enter-view {
				width: 50%;
				padding-bottom: 20rpx;
				box-sizing: border-box;
				
				&:nth-child(2n + 1) {
					padding-right: 10rpx;
				}
				&:nth-child(2n) {
					padding-left: 10rpx;
				}
				.enter-box {
					border: 1px solid @mainColor;
					color: @fontColor;
					min-height: 160rpx;
				}
			}
		}
	}
</style>
