<template>
	<view class="content">
		
		<view class="block">
			<view class="block-title">统计数据</view>
			<view class="total-flex">
				<view class="total-item" @click="onNav('Orders', { 'type': 2 })">
					<image class="icon" src="@/static/icons/work_icon_00.png"></image>
					<view class="title">预约咨询单</view>
					<view class="number">{{orderCount.init_payed}}<text>单</text></view>
				</view>
				<view class="total-item" @click="onNav('Orders', { 'type': 4 })">
					<image class="icon" src="@/static/icons/work_icon_01.png"></image>
					<view class="title">已缴费</view>
					<view class="number">{{orderCount.service_payed}}<text>单</text></view>
				</view>
				<view class="total-item" @click="onNav('Orders', { 'type': 10 })">
					<image class="icon" src="@/static/icons/work_icon_02.png"></image>
					<view class="title">办理完成</view>
					<view class="number">{{orderCount.b_complete}}<text>单</text></view>
				</view>
				<view class="total-item" @click="onNav('RefundOrder')">
					<image class="icon" src="@/static/icons/work_icon_03.png"></image>
					<view class="title">已退款</view>
					<view class="number">{{orderCount.refund}}<text>单</text></view>
				</view>
				<view class="total-item">
					<image class="icon" src="@/static/icons/work_icon_04.png"></image>
					<view class="title">完成结算</view>
					<view class="number">{{orderCount.settlement_count}}<text>单</text></view>
				</view>
				<view class="total-item" @click="onNav('AccountBonus')">
					<image class="icon" src="@/static/icons/work_icon_05.png"></image>
					<view class="title">结算金额</view>
					<view class="number">{{orderCount.settlement_price}}<text>元</text></view>
				</view>
				
			</view>
		</view>
		<view class="block">
			<view class="block-title">协商调解咨询订单管理</view>
			<view class="tool-flex">
				<view class="tool-flex-item" @click="onNav('Orders', { 'type': 0 })">
					<image class="icon" src="@/static/icons/work_icon_06.png"></image>
					<view class="number" v-if="orderCount.a_init > 0">{{orderCount.a_init}}</view>
					<view class="text">待预约</view>
				</view>
				<view class="tool-flex-item" @click="onNav('Orders', { 'type': 2 })">
					<image class="icon" src="@/static/icons/work_icon_21.png"></image>
					<view class="number" v-if="orderCount.a_service > 0">{{orderCount.a_service}}</view>
					<view class="text">匹配服务包</view>
				</view>
				<view class="tool-flex-item" @click="onNav('Orders', { 'type': 3 })">
					<image class="icon" src="@/static/icons/work_icon_07.png"></image>
					<view class="number" v-if="orderCount.a_serviced > 0">{{orderCount.a_serviced}}</view>
					<view class="text">待缴服务费</view>
				</view>
				<view class="tool-flex-item" @click="onNav('Orders', { 'type': 4 })">
					<image class="icon" src="@/static/icons/work_icon_10.png"></image>
					<view class="number" v-if="orderCount.b_sign > 0">{{orderCount.b_sign}}</view>
					<view class="text">待签约</view>
				</view>
				<view class="tool-flex-item" @click="onNav('Orders', { 'type': 5 })">
					<image class="icon" src="@/static/icons/work_icon_08.png"></image>
					<view class="number" v-if="orderCount.a_bank > 0">{{orderCount.a_bank}}</view>
					<view class="text">待完善资料</view>
				</view>
				<view class="tool-flex-item" @click="onNav('Orders', { 'type': 6 })">
					<image class="icon" src="@/static/icons/work_icon_09.png"></image>
					<view class="number" v-if="orderCount.b_check > 0">{{orderCount.b_check}}</view>
					<view class="text">初审中</view>
				</view>
				<view class="tool-flex-item" @click="onNav('Orders', { 'type': 7 })">
					<image class="icon" src="@/static/icons/work_icon_12.png"></image>
					<view class="number" v-if="orderCount.b_recheck > 0">{{orderCount.b_recheck}}</view>
					<view class="text">复审中</view>
				</view>
				<view class="tool-flex-item" @click="onNav('Orders', { 'type': 8 })">
					<image class="icon" src="@/static/icons/work_icon_13.png"></image>
					<view class="number" v-if="orderCount.b_process > 0">{{orderCount.b_process}}</view>
					<view class="text">办理中</view>
				</view>
				<view class="tool-flex-item" @click="onNav('Orders', { 'type': 9 })">
					<image class="icon" src="@/static/icons/work_icon_14.png"></image>
					<view class="number" v-if="orderCount.b_confirm > 0">{{orderCount.b_confirm}}</view>
					<view class="text">待结案</view>
				</view>
				<view class="tool-flex-item" @click="onNav('Orders', { 'type': 10 })">
					<image class="icon" src="@/static/icons/work_icon_15.png"></image>
					<!-- <view class="number" v-if="orderCount.b_complete > 0">{{orderCount.b_complete}}</view> -->
					<view class="text">办理完成</view>
				</view>
			</view>
		</view>
		<view class="block">
			<view class="block-title">转让订单管理</view>
			<view class="tool-flex">
				<view class="tool-flex-item" @click="onNav('TransfersOrders', { type: 'out' })">
					<image class="icon" src="@/static/icons/work_icon_26.png"></image>
					<view class="number" v-if="orderCount.transfer_out > 0">{{orderCount.transfer_out}}</view>
					<view class="text">转出订单</view>
				</view>
				<view class="tool-flex-item" @click="onNav('TransfersOrders', { type: 'in' })">
					<image class="icon" src="@/static/icons/work_icon_19.png"></image>
					<view class="number" v-if="orderCount.transfer_in > 0">{{orderCount.transfer_in}}</view>
					<view class="text">转入订单</view>
				</view>
			</view>
		</view>
		<view class="block">
			<view class="block-title">特殊订单管理</view>
			<view class="tool-flex">
				<view class="tool-flex-item" @click="onNav('ModifyOrder', {})">
					<image class="icon" src="@/static/icons/work_icon_16.png"></image>
					<view class="number" v-if="orderCount.audit_bank > 0">{{orderCount.audit_bank}}</view>
					<view class="text">修改资料</view>
				</view>
				<view class="tool-flex-item" @click="onNav('PoorOrder', {})">
					<image class="icon" src="@/static/icons/work_icon_17.png"></image>
					<view class="number" v-if="orderCount.diff_prices > 0">{{orderCount.diff_prices}}</view>
					<view class="text">补差价</view>
				</view>
				<view class="tool-flex-item" @click="onNav('RefundOrder')">
					<image class="icon" src="@/static/icons/work_icon_18.png"></image>
					<view class="number" v-if="orderCount.refund > 0">{{orderCount.refund}}</view>
					<view class="text">退款订单</view>
				</view>
				<view class="tool-flex-item" @click="onNav('OfflineOrders')">
					<image class="icon" src="@/static/icons/work_icon_28.png"></image>
					<view class="text">线下订单</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { index, rights, sign, synthesisCount } from '@/apis/interfaces/work.js'
	export default {
		data() {
			return {
				isAuth			: false,
				rightsArr		: [],
				userInfo		: {
					nickname: '',
					avatar	: ''
				},
				identity		: {},
				isAnswer		: false,
				isCertification	: false,
				certification	: null,
				isManager		: false,
				orderCount		: {},
				// 权益说明
				privilegeShow	: false,
				privilegeText	: '',
				// 签约状态
				sign			: {
					isSign	: false,
					address	: ""
				},
				// 综法订单管理
				synthesisData	: {}
			};
		},
		onShow() {
			let i = 0;
			this.isAuth = this.$store.getters.getToken != ''
			if(this.isAuth){
				this.getIndex()
			}
		},
		methods: {
			// 签约
			onSign(){
				if(!this.isCertification){
					uni.showToast({
						title: '暂未实名认证，无法签约，请完成实名认证',
						icon : 'none'
					})
					return
				}
				if(this.sign.address == ''){
					uni.showToast({
						title: '暂时无法签约，请前往“我的”，点击用户头像，完善通讯地址信息后重试',
						icon : 'none'
					})
					return
				}
				uni.showLoading({
					title	: '获取签约地址',
					mask	: true
				})
				sign().then(res => {
					uni.hideLoading()
					this.$Router.push({
						name	: 'ESign',
						params	: {
							url: res.sign_url
						}
					})
				}).catch(err => {
					uni.showToast({
						title: err.message,
						icon : 'none'
					})
				})
			},
			// 显示业务员权益
			onToast(val){
				this.privilegeText = val.content
				this.privilegeShow = true
			},
			// 工作台信息
			getIndex(){
				uni.showLoading({
					title: '加载中...',
					mask : true
				})
				Promise.all([rights(), index(), synthesisCount()]).then(res => {
					let rightsData		= res[0], 
						indexData  		= res[1],
						synthesisData	= res[2]
						
					let { nickname, avatar, business_orders_count, isCertification, certification, isManager, isAnswer, identity, sign } = indexData
					this.rightsArr = rightsData
					this.userInfo = {
						nickname,
						avatar
					}
					this.isCertification = isCertification
					this.certification 	 = certification
					this.isManager 		 = isManager
					this.isAnswer 		 = isAnswer
					this.orderCount 	 = business_orders_count
					this.identity 		 = identity
					this.sign			 = sign
					
					this.synthesisData	 = synthesisData
					
					uni.hideLoading()
				}).catch(err => {
					uni.showToast({
						title: err.message,
						icon : 'none'
					})
				})
			},
			// 导航
			onNav(name, obj){
				let params = obj || {}
				this.$Router.push({name, params})
			},
			// 创建订单
			onCreateOrder(){
				uni.showActionSheet({
					itemList: ['个人订单', '客户订单'],
					success : res => {
						this.onNav('OrderCreate', {
							type: res.tapIndex === 0 ? 'self' : 'other'
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		padding: 30rpx 0;
	}
	// 登录提示
	.auth-null{
		height: 100vh;
		width: 100vw;
		background: white;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		.auth-null-btn{
			height: 90rpx;
			line-height: 90rpx;
			padding: 0;
			width: 70vw;
			background: $main-color;
			color: white;
			font-size: 32rpx;
			margin-top: 100rpx;
			font-weight: bold;
		}
	}
	// 弹出特权
	.privilege-lay{
		width: 70vw;
		.privilege-lay-img{
			width: 70vw;
			vertical-align: top;
		}
		.privilege-lay-content{
			background: white;
			border-radius: 0  0 20rpx 20rpx;
			width: 70vw;
			padding: 80rpx 30rpx 50rpx;
			box-sizing: border-box;
			margin-top: -50rpx;
			line-height: 50rpx;
			color: #111111;
			font-size: 30rpx;
		}
		.privilege-lay-remove{
			padding-top: 30rpx;
			text-align: center;
			.privilege-lay-icon{
				display: inline-block;
			}
		}
	}
	// header
	.work-bar{
		padding: 30rpx;
		margin-bottom: 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		&-user{
			position: relative;
			line-height: 70rpx;
			height: 70rpx;
			width: calc(100% - 200rpx);
			padding-left: 90rpx;
			box-sizing: border-box;
			.cover{
				width: 70rpx;
				height: 70rpx;
				border-radius: 50%;
				position: absolute;
				left: 0;
				top: 0;
			}
			.nickname{
				font-weight: bold;
				font-size: 34rpx;
				.card{
					color: $main-color;
					font-size: 24rpx;
					display: inline-block;
					height: 40rpx;
					line-height: 38rpx;
					border-radius: 24rpx;
					padding: 0 15rpx;
					margin-left: 20rpx;
					margin-bottom: 2rpx;
					vertical-align: middle;
					border:solid 1rpx $main-color;
					font-weight: normal;
				}
			}
		}
		&-add{
			width: 200rpx;
			font-size: 30rpx;
			text-align: right;
			line-height: 70rpx;
			.icon{
				margin-right: 5rpx;
				font-weight: bold;
			}
		}
	}
	// 订单管理
	.tool-flex{
		padding: 0 10rpx;
		display: flex;
		flex-wrap: wrap;
		.tool-flex-item{
			width: 25%;
			text-align: center;
			margin-bottom: 30rpx;
			position: relative;
			.icon{
				width: 78rpx;
				height: 78rpx;
				background: #ddd;
				border-radius: 20rpx;
			}
			.number{
				position: absolute;
				right: 20%;
				background: #fe4444;
				top: -10rpx;
				height: 40rpx;
				line-height: 40rpx;
				min-width: 40rpx;
				font-size: 24rpx;
				color: white;
				border-radius: 50%;
			}
			.text{
				line-height: 40rpx;
				font-size: 26rpx;
				color: #111;
				text-align: center;
			}
		}
	}
	// 数据统计单
	.total-flex{
		padding: 0 20rpx 20rpx;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		.total-item{
			margin: 0 10rpx 20rpx;
			background: #f8f8f8;
			width: calc(50% - 20rpx);
			padding: 20rpx 20rpx 20rpx 120rpx;
			box-sizing: border-box;
			border-radius: $radius;
			position: relative;
			min-height: 140rpx;
			.icon{
				position: absolute;
				left: 20rpx;
				top: 50%;
				width: 70rpx;
				height: 70rpx;
				margin-top: -35rpx;
			}
			.title{
				font-size: 28rpx;
				color: #111;
				line-height: 40rpx;
				@extend .nowrap;
			}
			.number{
				padding-top: 5rpx;
				font-weight: bold;
				font-size: 34rpx;
				color: #111;
				font-family: Arial, Helvetica, sans-serif;
				line-height: 40rpx;
				@extend .nowrap;
				text{
					font-size: 80%;
					font-weight: normal;
					padding-left: 10rpx;
				}
			}
		}
	}
	// 通用板块
	.block{
		background: white;
		margin: 0 30rpx 20rpx;
		border-radius: $radius;
		.block-title{
			padding: 30rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-weight: bold;
			color: '#111';
			font-size: 32rpx;
		}
	}
	// 开通业务员
	.open-interest{
		padding: 30rpx;
		margin-bottom: 30rpx;
		.title{
			text-align: center;
			font-size: 34rpx;
			font-weight: bold;
			line-height: 80rpx;
		}
		.open-interest-flex{
			display: flex;
			flex-wrap: wrap;
			padding-top: 30rpx;
			justify-content: space-between;
			.open-interest-item{
				text-align: center;
				.open-interest-icon{
					width: 88rpx;
					height: 88rpx;
					vertical-align: top;
					margin-bottom: 15rpx;
				}
				.open-interest-text{
					font-size: 28rpx;
					color: #111111;
					line-height: 40rpx;
				}
			}
		}
		// 开通步骤
		.open-interest-block{
			padding: 30rpx 0;
			display: flex;
			justify-content: space-between;
			align-items: center;
			.open-interest-icon{
				width: 88rpx;
				height: 88rpx;
			}
			.open-interest-text{
				width: calc( 100% - 258rpx);
				padding:0 30rpx;
				box-sizing: border-box;
				.open-interest-title{
					font-weight: bold;
					color: #111111;
					line-height: 40rpx;
					font-size: 30rpx;
				}
				.open-interest-submit{
					color: #666666;
					font-size: 26rpx;
					line-height: 40rpx;
				}
			}
			.open-interest-btn[size="mini"]{
				width: 170rpx;
				height: 70rpx;
				line-height: 70rpx;
				padding: 0;
				border-radius: 35rpx;
				background: $main-color;
				color: white;
				font-size: 30rpx;
				&::after{
					display: none;
				}
				&[disabled]{
					background: #EEEEEE;
					color: #999999;
				}
			}
		}
	}
</style>
