<template>
	<view>
		<image src="../../static/images/broker/topBg.png" 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="../../static/images/broker/code.png" style="width: 50rpx;height: 50rpx;"></image>
				<text>我的邀请码</text>
			</view>
			<view class="cu-item text-center" @click="goNavPage('/pages/broker/myorder')">
				<image class="myicon" src="../../static/images/broker/order.png" style="width: 50rpx;height: 50rpx;"></image>
				<text>劳务订单</text>
				<view style="color: #888;font-size: 26rpx;">(针对劳务机构)</view>
			</view>
			<view class="cu-item text-center" @click="goNavPage('/pages/my/myentry')">
				<image class="myicon" src="../../static/images/broker/record.png" style="width: 50rpx;height: 50rpx;"></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>