<template>
	<view>
		<image :src="$getImageUrl('static/images/applet/brokerCenter.jpg')" class="header-image" mode="widthFix"></image>
		<view class="cu-bar bg-white solid-bottom">
			<view class="action">
				<text class="cuIcon-title text-orange "></text> 我的收益
			</view>
			<view class="action">
				<button class="cu-btn bg-green shadow" @click="goNavPage('/pages/broker/income')">详情</button>
			</view>
		</view>
		<view class="lw-table">
			<view class="lw-table-item padding">
				<view class="lw-table-value text-price text-bold text-red">{{statistics.income_total}}</view>
				<view class="lw-table-title text-gray padding-top-xs">总收益</view>
			</view>
			<view class="lw-table-item padding">
				<view class="lw-table-value text-price text-bold text-red">{{statistics.income}}</view>
				<view class="lw-table-title text-gray padding-top-xs">当前收益</view>
			</view>
		</view>
		<view class="cu-bar bg-white solid-bottom margin-top">
			<view class="action">
				<text class="cuIcon-title text-orange "></text> 我的下线
			</view>
		</view>
		<view class="lw-table">
			<view class="lw-table-item padding" @click="goNavPage('/pages/broker/myuser')">
				<view class="lw-table-value text-bold text-black">{{statistics.user}}</view>
				<view class="lw-table-title text-gray padding-top-xs">我的用户</view>
			</view>
			<view class="lw-table-item padding" @click="goNavPage('/pages/broker/myworker')">
				<view class="lw-table-value text-bold text-black">{{statistics.worker}}</view>
				<view class="lw-table-title text-gray padding-top-xs">我的雇主</view>
			</view>
		</view>
		<view class="cu-list grid col-3 no-border margin-top">
			<view class="cu-item text-center" @click="goNavPage('/pages/broker/broker')">
				<image class="myicon" :src="$getImageUrl('static/images/applet/myicon02.png')"></image>
				<text>邀请码</text>
			</view>
			<view class="cu-item text-center" @click="goNavPage('/pages/broker/myorder')">
				<image class="myicon" :src="$getImageUrl('static/images/applet/myicon04.png')"></image>
				<text>订单信息</text>
			</view>
			<view class="cu-item text-center" @click="goNavPage('/pages/my/myentry')">
				<image class="myicon" :src="$getImageUrl('static/images/applet/shebao.png')"></image>
				<text>报备记录</text>
			</view>
		</view>
	</view>
</template>

<script>
	var _this;
	export default {
		data() {
			return {
				userinfo: {},
				brokerinfo: {},
				statistics: {
					income_total: 0,
					income: 0,
					user: 0,
					worker: 0,
				},
			};
		},
		onLoad: function(){
			_this = this;
			_this.userinfo = uni.getStorageSync('userinfo') || false;
			_this.brokerinfo = uni.getStorageSync('brokerinfo') || false;
			if (_this.userinfo===false || _this.brokerinfo===false){
				uni.reLaunch({
					url: "/pages/my/my"
				});
				return false;
			}
			_this.init();
		},
		methods: {
			init: function() {
				_this.$req.ajax({
					path: "broker/center",
					data: {
						brokerid: _this.brokerinfo.id
					}
				}).then((data) => {
					_this.statistics = data
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			},
			goNavPage: function(pageurl) {
				_this.userinfo = _this.checkLogin("/pages/my/my");
				if (_this.userinfo===false){
					return false;
				}
				uni.navigateTo({
					url: pageurl,
					fail: function() {
						uni.switchTab({
							url: pageurl
						});
					}
				});
			},
		}
	}
</script>

<style scoped>
	.header-image {width:750rpx;}
	.lw-table {display: flex;align-items: center;justify-content: space-around;background: white;padding:20rpx 0;}
	.lw-table .lw-table-item {text-align: center;}
	.lw-table .lw-table-value {font-size:40rpx;}
</style>
