<template>
	<view class="container">
		<view class="top">
			<uni-swiper-dot class="uni-swiper-dot-box" @clickItem=clickItem :info="banner" :current="current" :mode="mode"
				field="bannerName">
				<swiper class="swiper-box" @change="changeSwiper" :current="swiperDotIndex" :autoplay="autoplay"
					:interval="interval" :duration="duration">
					<swiper-item v-for="(item, index) in banner" :key="index">
						<view class="swiper-item" :class="'swiper-item' + index">
							<!-- <text style="color: #fff; font-size: 32px;">{{index+1}}</text> -->
							<image class="img" @click="linkTo(item)" :src="item.bannerImg"></image>
						</view>
					</swiper-item>
				</swiper>
			</uni-swiper-dot>
		</view>
		
		<view class="middle">
			<uni-group mode="card">
				<uni-grid :column="2" :square="true" :highlight="false" @change="change" :showBorder="true">
					<uni-grid-item v-for="(val, i) in funcList" :index="i" :key="i">
						<view class="grid-item-box">
							<!-- <uni-icons type="image" :size="30" color="#777" /> -->
							<image :src="val.icon" class="iconImage" mode="aspectFill" />
							<text class="text">{{ val.title }}</text>
						</view>
					</uni-grid-item>
				</uni-grid>
			</uni-group>
		</view>
		
		<view class="foot">
				<uni-group mode="card" title="素材数据" style="text-align:center;">
					<uni-grid :column="3" :square="true" :highlight="false">
						<uni-grid-item v-for="(params, v) in list" :index="v" :key="v">
							<view class="grid-item-box">
								<!-- <uni-icons type="image" :size="30" color="#777" /> -->
								<image :src="params.icon" class="listIconImage" mode="aspectFill" />
								<text class="text">{{ params.text }}</text>
								<text class="text">{{ params.num }}</text>
							</view>
						</uni-grid-item>
					</uni-grid>
				</uni-group>
		</view>
		
	</view>
</template>

<script>
	import {
		queryCreatorTypeImgNum,
		listBanner
	} from '@/api/index.js'
	export default {
		data() {
			return {
				banner:[],
				current: 0,
				mode: 'nav',
				swiperDotIndex: 0,
				autoplay: true,
				interval: 5000,
				duration: 500,
				pageUrl:'',
				funcList: [{
					title: '素材管理',
					url: '/pages/index/material/material',
					icon: '/static/material.png'
				}, {
					title: '上传素材',
					url: '/pages/index/upload/upload',
					icon: '/static/upload.png'
				}],
				list: [{
						typeId: 1,
						text: '头像',
						num: '',
						icon: '/static/headBack.png'
					},
					{
						typeId: 2,
						text: 'Gif动图',
						num: '',
						icon: '/static/gifBack.png'
					},
					{
						typeId: 3,
						text: '手机壁纸',
						num: '',
						icon: '/static/phoneBack.png'
					},
					{
						typeId: 4,
						text: '朋友圈',
						num: '',
						icon: '/static/friendBack.png'
					},
					{
						typeId: 5,
						text: '表情包',
						num: '',
						icon: '/static/emoBack.png'
					},
					{
						typeId: 6,
						text: 'iwatch',
						num: '',
						icon: '/static/iwatchBack.png'
					}
				]
			};
		}, 
		created(){
			
			
		},
		onLoad(){
			this.queryCreatorTypeImgNum();
			this.getBanner();
		},
		methods: {
			changeSwiper(e){
				this.current = e.detail.current;
			},
			change(e) {
				this.pageUrl = this.funcList[e.detail.index].url
				console.log('this.pageUrl',this.pageUrl)
				/** 跳转指定页面*/
				 uni.navigateTo({
				 	url: this.pageUrl
				 });
			},
			clickItem(e) {
				this.swiperDotIndex = e
				console.log('this.swiperDotIndex', this.swiperDotIndex) 
			},
			// 跳转banner详情页
			linkTo(item) {
				if (item.id) {
					uni.navigateTo({
						url: '../index/banner'
					});
				}
			},
			
			// 获取banner列表
			async getBanner() {
				const res = await listBanner() 
				if (res.data.code === 200) {
					this.banner = res.data.data
					console.log('banner',this.banner)
				} else {
					uni.showModal({ 
						content: 'banner加载失败！',
						showCancel: false
					});
				}
			},
			
			// 查询艺术家图片分类数量
			async queryCreatorTypeImgNum() {
				const userInfo = uni.getStorageSync('userInfo')
				if (!userInfo) {
					console.log('havent userInfo')
					
				} else {
					console.log('have userInfo')
				}
				const res = await queryCreatorTypeImgNum(userInfo.id)
				console.log('res',res)
				if (res.data.code === 200) {
					this.list[0].num = res.data.data.headNum
					this.list[1].num = res.data.data.gifNum
					this.list[2].num = res.data.data.backNum
					this.list[3].num = res.data.data.friendNum
					this.list[4].num = res.data.data.emoNum
					this.list[5].num = res.data.data.watchNum
					console.log('list',this.list)
				} else {
					uni.showModal({
						content: '图片分页数量加载失败！',
						showCancel: false
					});
				}
			},
		}
	}
</script>

<style lang="scss">
	.container{
		font-family:‘Franklin Gothic Medium’, ‘Arial Narrow’, Arial, sans-serif;
	}
	.img {
		position: absolute;
		width: 100%;
		height: 100%;
	}
	.grid-item-box {
		flex: 1;
		// position: relative;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 10px 0;
	}

	.grid-item-box-row {
		flex: 1;
		// position: relative;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
		justify-content: center;
		padding: 10px 0;
	}

	.swiper-box {
		height: 150px;
	}

	.swiper-item {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: center;
		align-items: center;
		height: 200px;
		color: #fff;
	}

	.swiper-item0 {
		background-color: #cee1fd;
	}

	.swiper-item1 {
		background-color: #b2cef7;
	}

	.swiper-item2 {
		background-color: #cee1fd;
	}

	.image {
		width: 750rpx;
	}

	/* #ifndef APP-NVUE */
	::v-deep .image img {
		-webkit-user-drag: none;
		-khtml-user-drag: none;
		-moz-user-drag: none;
		-o-user-drag: none;
		user-drag: none;
	}

	/* #endif */

	@media screen and (min-width: 500px) {
		.uni-swiper-dot-box {
			width: 400px;
			margin: 0 auto;
			margin-top: 8px;
		}

		.image {
			width: 100%;
		}
	}

	.uni-bg-blue {
		background-color: #007aff;
	}
	
	.iconImage{
		width:3rem;
		height:3rem;
	}
	
	.listIconImage{
		width:2rem;
		height:2rem;
	}

</style>
