<template>
	<view class="content">
		<view class="top-box">
			<image src="../../static/img/usert-bg.png" mode="" class="box-bg"></image>
			<view class="box-data">
				<view class="data-item">
					<view class="val">
						{{userInfo.now_money*1 || '0'}}
					</view>
					<view class="name">
						消费积分
					</view>
				</view>
				<view class="line">
					
				</view>
				<view class="data-item">
					<view class="val">
						{{userInfo.max_pool*1|| '0'}}
					</view>
					<view class="name">
						分红额度
					</view>
				</view>
			</view>
		</view>
		<view class="flex center-box ">
			<view class="flex center-item" @click="navto('/pages/user/xzdl?type=2')">
				<image src="../../static/icon/dh.png" mode=""></image>
				<view class="name">兑换</view>
			</view>
			<view class="line">
			</view>
			<view class="flex center-item" @click="navto('/pages/user/xzdl?type=1')">
				<image src="../../static/icon/hz.png" mode=""></image>
				<view class="name">互转</view>
			</view>
			<view class="line">
			</view>
			<view class="flex center-item" @click="toTx">
				<image src="../../static/icon/tx.png" mode=""></image>
				<view class="name">提现</view>
			</view>
		</view>
		<view class="tit">
			我的資產
		</view>
		<view class="bottom-list" v-for="key in navList">
			<view class="flex list-item">
				<image :src="key.img" mode="" class="logo"></image>
				<view class="much">
					<view class="">
						{{key.name}}
					</view>
					<view class="val">
						余额:{{userInfo[key.val]*1 || '0'}}
					</view>
				</view>
				<view class="btn" v-if="key.agent" @click="goft">
					复投
				</view>
				<view class="more" @click="navto('/pages/user/sz?type=' + key.type)">
					查看明细
				</view>
				<image src="../../static/icon/back.png" mode="" class="black"></image>
			</view>
		</view>
		<image src="../../static/img/xccg.gif" mode="" class="cg" @click="navto('/pages/user/xccg')"></image>
	</view>
</template>

<script>
	import {
		saveUrl,
		interceptor
	} from '@/utils/loginUtils.js';
	import {
		getUserInfo,
		userPool,
		goft
	} from '@/api/user.js';
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				navList: {
					ft: {
						name: '复投积分',
						val: 'resumption',
						type: 1,
						agent: true,
						img: '../../static/icon/xc1.png'
					},
					yj: {
						name: '佣金',
						val: 'brokerage_price',
						type: 2,
						agent: false,
						img: '../../static/icon/xc2.png'
					},
					fh: {
						name: '分红额度',
						val: 'max_pool',
						type: 3,
						agent: false,
						img: '../../static/icon/xc3.png'
					},
					xfjf: {
						name: '消费积分',
						val: 'now_money',
						type:4,
						agent: false,
						img: '../../static/icon/xc4.png'
					}
				}
			}
		},
		onLoad() {
			
		},
		onShow() {
			this.loadBaseData()
		},
		computed: {
			...mapState('user',['userInfo','hasLogin'])
		},
		onPullDownRefresh() {
			this.loadBaseData('down')
		},
		methods: {
			...mapMutations('user',['setUserInfo']),
			toTx() {
				let that = this
				if (!that.hasLogin) {
					// 保存地址
					saveUrl();
					// 登录拦截
					interceptor();
				} else {
					// uni.navigateTo({
					// 	url,
					// 	 fail() {
					// 	 	uni.switchTab({
					// 	 		url
					// 	 	})
					// 	 }
					// })
					if(that.userInfo.is_real == 1) {
						uni.showModal({
							title: "提示",
							content: '您提交的实名资料正在审核中，请耐心等待审核',
							showCancel:false
						})
					}else if(that.userInfo.is_real == 0) {
						uni.showModal({
							title: "提示",
							content: '您的账号未完成实名认证，是否立即完成实名认证？',
							complete(res) {
								if(res.confirm) {
									that.navto('/pages/user/smrz')
								}
							}
						})
					}else {
						that.navto('/pages/user/withdrawal')
					}
				}
			},
			loadBaseData(tit) {
				const obj = this
				getUserInfo({})
					.then(({
						data
					}) => {
						obj.setUserInfo(data);
						if(tit == 'down') {
							uni.stopPullDownRefresh();
						}
					})
					.catch(e => {
						console.log(e);
						if(tit == 'down') {
							uni.stopPullDownRefresh();
						}
					});
			
			},
			navto(url) {
				
				if (!this.hasLogin) {
					// 保存地址
					saveUrl();
					// 登录拦截
					interceptor();
				} else {
					uni.navigateTo({
						url,
						 fail() {
						 	uni.switchTab({
						 		url
						 	})
						 }
					})
				}
				
			},
			goft() {
				let that = this
				if(this.ftLoading) {
					return
				}
				this.ftLoading = true
				goft().then(res => {
					console.log(res);
					that.loadBaseData()
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #fff;
		min-height: 100%;
		height: auto;
	}
	.top-box {
		position: relative;
		.box-bg {
			width: 100%;
			height: 396rpx;
		}
		.box-data {
			width: 100%;
			height: 200rpx;
			position:absolute;
			top: 0;
			bottom: 0;
			margin: auto;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 37rpx;
			font-weight: bold;
			color: #fff;
			.data-item {
				flex-grow: 1;
				text-align: center;
				.val {
					font-size: 55rpx;
					font-weight: 800;
					padding-bottom: 15rpx;
				}
			}
			.line {
				
				width: 2rpx;
				height: 74rpx;
				background: #FFFFFF;
				opacity: 0.35;
			}
		}
	}
	.center-box {
		position: relative;
		width: 670rpx;
		height: 186rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50,50,52,0.06);
		border-radius: 20rpx;
		margin:-98rpx auto 0;
		font-size: 30rpx;
		font-weight: bold;
		color: #333333;
		.center-item {
			flex-grow: 1;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			image {
				width: 55rpx;
				height: 55rpx;
			}
			.name {
				padding-top: 10rpx;
			}
		}
		.line {
			width: 2rpx;
			height: 74rpx;
			background: #eff1f5;
		}
	}
	.bottom-list {
		.list-item {
			width: 670rpx;
			height: 127rpx;
			// background-color: red;
			border-bottom:1px solid #E8E8E8;
			
			margin: auto;
			.logo {
				width: 81rpx;
				height: 81rpx;
			}
			.much {
				padding-left: 14rpx;
				flex-grow: 1;
				font-size: 30rpx;
				font-weight: bold;
				color: #333333;
				.val {
					padding-top: 15rpx;
					font-size: 22rpx;
					font-weight: 500;
					color: #999999;
				}
			}
			.btn {
				width: 127rpx;
				height: 52rpx;
				border: 2px solid #ff5050;
				border-radius: 26rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				font-size: 26rpx;
				font-weight: 500;
				color: #ff5050;
				margin-right: 24rpx;
			}
			.more {
				font-size: 24rpx;
				font-weight: 500;
				color: #999999;
				padding-right: 14rpx;
			}
			.black {
				width: 16rpx;
				height: 27rpx;
			}
		}
	}
	.cg {
		display: block;
		width: 706rpx;
		height: 193rpx;
		margin: 30rpx auto 0;
	}
	.tit {
		
		font-size: 36rpx;
		font-weight: bold;
		color: #333333;
		padding:46rpx 0;
		width: 750rpx-92rpx;
		margin: auto;
	}
</style>