<template>
	<view class="main">
		<view class="one">
			<swiper class="swiper" circular :indicator-dots="true" indicator-color="#F5F5F5"
				indicator-active-color="#ffffff" :autoplay="false" :interval="3000" :duration="1000">
				<swiper-item class="list" v-for="(item,index) in advertList" :key="index">
					<image class="image" :src="item.image&&item.image.length>0?item.image[0].url:''" mode=""></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="two">
			<uni-collapse>
				<uni-collapse-item title="群组" thumb="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png">
					<view class="content">
						<text class="text">群组</text>
					</view>
				</uni-collapse-item>
				<uni-collapse-item title="好友" thumb="https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/unicloudlogo.png">
					<view class="content">
						<text class="text">群组</text>
					</view>
				</uni-collapse-item>
			</uni-collapse>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {},
				// 广告
				advertList: []
			}
		},
		onShow: async function() {
			const that = this;
			await that.searchToken();
			await that.search();
		},
		onPullDownRefresh: async function() {
			const that = this;
			await that.search();
			uni.stopPullDownRefresh();
		},
		methods: {
			// 用户信息
			searchToken() {
				const that = this;
				try {
					const res = uni.getStorageSync('token');
					if (res) that.$set(that, `user`, res);
				} catch (e) {
					uni.showToast({
						title: err.errmsg,
						icon: 'error',
						duration: 2000
					});
				}
			},
			// 查询
			async search() {
				const that = this;
				// 广告
				const res = await that.$api(`/adv`, 'GET', {
					is_use: '0'
				})
				if (res.errcode == '0') {
					that.$set(that, `advertList`, res.data)
				} else {
					uni.showToast({
						title: res.errmsg,
					});
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		.one {
			padding: 0 0 2vw 0;

			.swiper {
				height: 60vw;

				.list {
					.image {
						width: 100%;
						height: 100%;
					}
				}
			}
		}
	}
</style>