<template>
	<view class="container">
		<navBar title="" :navImg="navImg" :back="false" color="#333333" background="#FFFFFF" />

		<!-- 轮播图 -->
		<view class="swiperBox">
			<u-swiper height="514rpx" :autoplay="false" :list="list1" @change="change" @click="click">
			</u-swiper>
		</view>



		<view class="mainContent">
			<view class="topBox">
				<view class="left">
					<image class="item" v-for="(item,index) in list1" :src="item"
						:style="{'margin-left':index==0?'32rpx':'0'}">
					</image>
				</view>

				<view class="right">
					<view class="t1">
						CHILDREN PICTURE BOO
					</view>
					<view class="t2">
						专属故事
					</view>
					<view class="btnBox" @click="toGen">
						即刻代写
						<image class="arrIcon">
						</image>
					</view>
				</view>
			</view>

			<view class="botBox">
				<view class="title">
					精选绘本故事
					<image class="bookIcon">
					</image>
				</view>
				<view class="list">
					<view class="item" v-for="(item,index) in jingxuanList">
						<image class="pic" :src="item.sd_image.replace('localhost:8000',baseUrl)" mode="widthFix">
						</image>
						<view class="des">
							{{item.title}}
						</view>
					</view>
				</view>
			</view>
			<tabBar :tabBarList="tabBarList" :routePath="routePath" @onTabBar="onTabBar" />

			<!-- 隐私弹框 -->
			<privacy-popup @confirmP="confirmP" :urlTitle="urlTitle" @cancleP="cancleP"
				:showPrivateBox="showPop"></privacy-popup>
		</view>


	</view>
</template>

<script>
	import {
		getJingxuan
	} from '@/api/index/index.js'
	import PrivacyPopup from "@/components/privacyPopup/index.vue";
	import uploadUrl from '@/common/config.js'
	export default {
		components: {
			PrivacyPopup
		},
		data() {
			return {
				baseUrl:uploadUrl.baseUrl,
				jingxuanList:[],
				
				navImg: require('@/static/other/logo.png'),
				showPop: false,
				urlTitle: '',

				list1: [
					'https://cdn.uviewui.com/uview/swiper/swiper1.png',
					'https://cdn.uviewui.com/uview/swiper/swiper2.png',
					'https://cdn.uviewui.com/uview/swiper/swiper3.png',
				],

				tabBarList: [{
						"pagePath": "pages/index/index",
						"iconPath": "../../static/tabbar/index.png",
						"selectedIconPath": "../../static/tabbar/index_a.png",
						"text": "首页"
					},
					{
						"pagePath": "pages/my/index",
						"iconPath": "../../static/tabbar/my.png",
						"selectedIconPath": "../../static/tabbar/my_a.png",
						"text": "我的"
					}
				],
				routePath: '',
			}
		},

		onLoad(o) {
			
			
			
			uni.hideTabBar()
			let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
			let curRoute = routes[routes.length - 1].route // 获取当前页面路由，也就是最后一个打开的页面路由
			this.routePath = curRoute;
			console.log('routePath', this.routePath);
			this.getJingxuan()
		},
		onShow() {
			this.handlePrivate()
			
		},
		methods: {
			async getJingxuan() {
						let res1 = await getJingxuan()
						console.log('首页精选返回值--------2', res1);
						if (res1.code == 0) {
							this.jingxuanList=res1.data.data
							// this.chargeList=[]
						} else {
						this.$toast(res1.message)
						}
					},
			
			toGen() {
				uni.navigateTo({
					url: '/pages/index/genRes/index'
				})
			},
			handlePrivate() {
				let _this = this
				if (uni.getPrivacySetting) {
					uni.getPrivacySetting({
						success: res => {
							console.log("是否需要授权--首页：", res.needAuthorization, "隐私协议的名称为：", res
								.privacyContractName)
							_this.urlTitle = res
								.privacyContractName
							if (res.needAuthorization) {
								getApp().globalData.showPrivacy = true;
								_this.showPop = true
							} else {
								getApp().globalData.showPrivacy = false;
							}
						},
						fail: () => {},
						complete: () => {},
					})
				}
			},
			confirmP() {
				this.showPop = false
			},
			cancleP() {
				let _this = this
				uni.showModal({
					title: '提示',
					content: '拒绝将退出小程序,确定退出?',
					success: function(res) {
						if (res.confirm) {
							_this.showPop = false
							wx.exitMiniProgram({
								success: function() {
									// uni.removeStorageSync('iv'); //清除缓存	
								}
							})
						} else if (res.cancel) {

						}
					}
				});
			},
			onTabBar(e) {
				console.log('e------------', e);
				uni.switchTab({
					url: '/' + e
				})
			},
			async testReq() {

				console.log('testStore()111111', this.$store.getters['user/testInfo']);
				console.log('testStore()111111', this.$store.getters['user/testInfo2']);
				// let res = await getValidateCode({
				// 	phone: '15609038521',
				// 	event: 'register'
				// })
				// uni.showToast({
				// 	title: res.msg,
				// 	icon: 'none'
				// })
				// console.log('发送短信验证码返回值', res);
				// if (res.code == 0) {}
			},
			testStore() {
				this.$store.dispatch('user/testAct', '6666666')
				console.log('testStore()', this.$store.getters['user/testInfo']);
				// this.$store.dispatch('testAct', '66666');
				// console.log('存入仓库后', this.$store.getters.testInfo);
			},
			async testLogin() {
				let res = await this.$store.dispatch('user/testAct2', {
					phone: '15609038533',
					event: 'register'
				})
				console.log('测试登录返回值：', res);
			},
			testLogout() {
				this.$store.dispatch('user/testAct3')
				console.log('测试退出登录返回值：', this.$store.getters['user/testInfo3']);
			},
		}
	}
</script>

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