<template>
	<view>
		<image :src="$getImageUrl('static/images/applet/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> {{income_title}}
			</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="{'text-price':brokerinfo.type == 1}" class="lw-table-value text-bold text-red">{{statistics.income_total}}</view>
				<view class="lw-table-title text-gray padding-top-xs">{{income_total_title}}</view>
			</view>
			<view class="lw-table-item padding">
				<view :class="{'text-price':brokerinfo.type == 1}" class="lw-table-value text-bold text-red">{{statistics.income}}</view>
				<view class="lw-table-title text-gray padding-top-xs">{{income_now_title}}</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/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="$getImageUrl('static/images/applet/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="$getImageUrl('static/images/applet/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
						});
					}
				});
			},
		},
		computed: {
			income_title() {
				return _this.brokerinfo.type == 1 ? '我的收益' : '我的积分';
			},
			income_total_title() {
				return _this.brokerinfo.type == 1 ? '总收益' : '总积分';
			},
			income_now_title() {
				return _this.brokerinfo.type == 1 ? '当前收益' : '剩余积分';
			},
			income_unit() {
				return _this.brokerinfo.type == 1 ? '元' : '分';
			},
		},
	}
</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>