<template>
	<view class="center">
		<view class="top">
			<view class="vheigh"></view>
			<image class="top-bg" src="../../static/img/top-bg.png" mode=""></image>
			<view class="top-main flex">
				<view class="search-box flex" @click="clickSearch()">
					<image class="search" src="../../static/img/search.png" mode=""></image>
					<view class="search-font">输入关键词搜索</view>
				</view>
			</view>
		</view>
		<swiper class="carousel" autoplay="true" duration="400" interval="5000" @change="swiperChange">
			<swiper-item v-for="(item, index) in carouselList" :key="index" class="carousel-item"
				@click="bannerNavToUrl(item)">
				<image :src="item.pic" />
			</swiper-item>
		</swiper>
		<view class="tongz flex">
			<view>
				<view class="tongz-bg">
					<image src="../../static/img/tongz-bg.png" mode=""></image>
				</view>
				<view class="tongz-left flex">
					<image class="image-left" src="../../static/img/ling.png" mode=""></image>
					<u-notice-bar style="width: 100%;" mode="vertical" type="none" :volume-icon="false"
						:more-icon="false" :list="text"></u-notice-bar>
				</view>
			</view>
		</view>
		<view class="navbar-box">
			<view class="navbar-title">
				<image class="navbar-icon" src="../../static/icon/title-icon.png" mode=""></image>
				<view class="navbar-font">
					分红数据
				</view>
			</view>
			<view class="navbar-main">
				<view class="navbar-item">
					<view class="item-num">{{now_jjfh}}</view>
					<view class="item-font">当前分红基金</view>
				</view>
				<view class="xian"></view>
				<view class="navbar-item">
					<view class="item-num">{{now_num}}</view>
					<view class="item-font">当前每股股价</view>
				</view>
				<view class="xian"></view>
				<view class="navbar-item">
					<view class="item-num">{{my_num}}</view>
					<view class="item-font">我的当前股数</view>
				</view>
				<view class="xian"></view>
				<view class="navbar-item">
					<view class="item-num">{{my_money}}</view>
					<view class="item-font">我的当前分红</view>
				</view>
			</view>
		</view>
		<view class="main-box">
			<view class="main-item" @click="nav('/pages/navigation/bdjj?money='+bd_money)">
				<image class="main-image" src="../../static/icon/n1.png" mode="widthFix"></image>
				<view class="main-num">￥{{bd_money}}</view>
				<view class="main-font">报单奖金</view>
			</view>
			<view class="main-item" @click="nav('/pages/navigation/tdjj?money='+team_money)">
				<image class="main-image" src="../../static/icon/n2.png" mode="widthFix"></image>
				<view class="main-num">￥{{team_money}}</view>
				<view class="main-font">团队奖金</view>
			</view>
			<view class="main-item" @click="nav('/pages/navigation/fhsy?money='+fh_money)">
				<image class="main-image" src="../../static/icon/n3.png" mode="widthFix"></image>
				<view class="main-num">￥{{fh_money}}</view>
				<view class="main-font">分红收益</view>
			</view>
			<view class="main-item" @click="nav('/pages/navigation/team')">
				<image class="main-image" src="../../static/icon/n4.png" mode="widthFix"></image>
				<view class="main-num">{{team}}</view>
				<view class="main-font">我的团队</view>
			</view>
			<view class="main-item" @click="nav('/pages/user/shareQrCode')">
				<image class="main-image" src="../../static/icon/n5.png" mode="widthFix"></image>
				<view class="main-font">邀请好友</view>
			</view>
			<view class="main-item" @click="nav('/pages/set/userinfo')">
				<image class="main-image" src="../../static/icon/n6.png" mode="widthFix"></image>
				<view class="main-font">个人资料</view>
			</view>
			<view class="main-item" @click="nav('/pages/money/withdrawal?way=brokerage_price')">
				<image class="main-image" src="../../static/icon/n7.png" mode="widthFix"></image>
				<view class="main-font">发起提现</view>
			</view>
			<view class="main-item" @click="nav('/pages/navigation/productlist')">
				<image class="main-image" src="../../static/icon/n8.png" mode="widthFix"></image>
				<view class="main-font">产品咨讯</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		loadIndexs,
		order_info
	} from '@/api/index.js';
	import {
		link
	} from '@/api/user.js';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				current: 0,
				titleNViewBackground: '',
				swiperCurrent: 0,
				swiperLength: 0,
				carouselList: [], //轮播图列表
				text: ['双模式 双系统  开创第三代新零售'],
				now_jjfh: 0,
				now_num: 0,
				my_num: 0,
				my_money: 0,
				bd_money: 0,
				team_money: 0,
				fh_money: 0,
				team: 0,
				timers: '',
			};
		},
		onShow() {
			this.loadData();
		},
		onHide() {
			clearTimeout(this.timers);
			console.log(this.timers, 'onhide');
		},
		// 监听页面卸载
		onUnload() {
			// 关闭倒计时
			clearTimeout(this.timers);
			console.log(this.timers, 'unload');
		},
		// 监听页面后退
		onBackPress() {
			// 关闭倒计时
			clearTimeout(this.timers);
			console.log(this.timers, 'back');
		},
		methods: {
			...mapMutations(['setLat', 'setLon', 'setChoose']),
			loadData() {
				this.getorder()
				loadIndexs({})
					.then(({
						data
					}) => {
						let goods = data.info;
						this.dataList = goods.bastList; //精品推荐
						this.carouselList = data.banner;
					})
					.catch(e => {});
				link({
						page: 1,
						limit: 1,
					})
					.then(({
						data
					}) => {
						this.team = data.total + data.totalLevel
					})
					.catch(e => {
						console.log(e);
					});
			},
			getorder() {
				if(this.timers){
					clearTimeout(this.timers);
				}
				order_info({}).then(({
					data
				}) => {
					// this.timers = setTimeout(this.getorder, 1000);
					this.now_jjfh = data.sum;
					this.now_num = data.every_piece;
					this.my_num = data.user_piece;
					this.my_money = data.award;
					this.bd_money = data.recommend_award;
					this.team_money = data.group_award;
					this.fh_money = data.day_award;
					console.log(this.timers);
				})
			},
			nav(url) {
				uni.navigateTo({
					url,
					fail() {
						uni.switchTab({
							url
						});
					}
				});
			},
			//轮播图切换修改背景色
			swiperChange(e) {
				const index = e.detail.current;
				this.swiperCurrent = index;
				this.titleNViewBackground = this.carouselList[index].background;
			},
			// 點擊搜索框
			clickSearch() {
				uni.navigateTo({
					url: '/pages/product/search'
				});
			},
		}
	};
</script>

<style lang="scss">
	page,
	.center {
		min-height: 100%;
		height: auto;
		background: #ffffff;
	}

	.vheigh {
		height: var(--status-bar-height);
		background-color: $base-color;
	}

	.top {
		position: relative;
		width: 100%;
		height: 360rpx;

		.top-bg {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			width: 100%;
			height: 100%;
		}

		.top-main {
			position: relative;
			z-index: 2;
			padding: 30rpx;

			.search-box {
				justify-content: center;
				width: 698rpx;
				height: 60rpx;
				background: rgba(255, 240, 245, 0.4);
				box-shadow: 0px 10rpx 20rpx 0px rgba(4, 114, 69, 0.22);
				border-radius: 30rpx;

				.search {
					width: 34rpx;
					height: 34rpx;
				}

				.search-font {
					margin-left: 14rpx;
					font-size: 28rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #ffffff;
				}
			}
		}
	}

	.carousel {
		width: 700rpx;
		height: 276rpx;
		/* #ifndef APP-PLUS */
		margin: -240rpx auto 0;
		/* #endif */
		/* #ifdef APP-PLUS */
		margin: -180rpx auto 0;
		/* #endif */
		border-radius: 40rpx;

		image {
			border-radius: 40rpx;
			width: 700rpx;
			height: 276rpx;
		}
	}

	.tongz {
		width: 690rpx;
		height: 70rpx;
		margin: 32rpx auto 0;
		padding: 18rpx 30rpx 18rpx 24rpx;
		align-items: center;
		position: relative;

		.tongz-bg {
			position: absolute;
			top: 0;
			right: 0;
			left: 0;
			width: 690rpx;
			height: 70rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.tongz-left {
			width: 640rpx;

			.image-left {
				width: 28rpx;
				height: 34rpx;
			}

			.tongz-font {
				margin-left: 22rpx;
				font-size: 28rpx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #0f253a;
			}
		}

		.tongz-right {
			position: relative;
			z-index: 11;
			width: 12rpx;
			height: 26rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}
	}

	.navbar-box {
		width: 700rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50, 50, 52, 0.06);
		border-radius: 20rpx;
		padding: 30rpx 0;
		margin: 40rpx auto 0;
	}

	.navbar-title {
		display: flex;
		align-items: center;
		padding: 0 26rpx 20rpx;
		border-bottom: 1px solid #f5f5f5;

		.navbar-icon {
			width: 30rpx;
			height: 26rpx;
		}

		.navbar-font {
			margin-left: 10rpx;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #333333;
		}
	}

	.navbar-main {
		padding-top: 45rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;
		line-height: 1;

		.xian {
			width: 1rpx;
			height: 31rpx;
			background: #333333;
		}

		.navbar-item {
			flex: 1;
			display: flex;
			flex-direction: column;
			align-items: center;

			.item-num {
				font-size: 39rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #333333;
			}

			.item-font {
				margin-top: 20rpx;
				font-size: 21rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #666666;
			}
		}
	}

	.main-box {
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		padding: 10rpx 24rpx;
	}

	.main-item {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		width: 342rpx;
		height: 200rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50, 50, 52, 0.06);
		border-radius: 20rpx;
		margin-top: 20rpx;
		line-height: 1;

		.main-image {
			width: 68rpx;
		}

		.main-num {
			margin-top: 20rpx;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
		}

		.main-font {
			margin-top: 20rpx;
			font-size: 26rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #4D4D4D;
			line-height: 21rpx;
		}
	}
</style>