<template>
	<view class="content">
		<view v-if="isAuth">
			<!-- 状态栏 -->
			<u-sticky bgColor="#FFFFFF">
				<view class="status_bar"></view>
				<view class="work-bar">
					<view class="work-bar-user">
						<image class="cover" :src="userInfo.avatar || require('@/static/imgs/default-active.png')" mode="aspectFill"></image>
						<view class="nickname">{{userInfo.nickname}}<text class="card" v-if="isManager">{{identity.name}}</text></view>
					</view>
					<view class="work-bar-add" @click="onCreateOrder" v-if="isManager">
						<uni-icons class="icon" type="plusempty" size="30rpx" color="#111"></uni-icons>创建订单
					</view>
				</view>
			</u-sticky>
			<!-- 未认证或未考试 -->
			<block v-if="!isManager">
				<view class="block open-interest">
					<view class="title">实习顾问专属权益</view>
					<view class="open-interest-flex">
						<view class="open-interest-item" v-for="(item, index) in rightsArr" :key="index" @click="onToast(item)">
							<image class="open-interest-icon" :src="item.icon"></image>
							<view class="open-interest-text">{{item.title}}</view>
						</view>
					</view>
				</view>
				<view class="block open-interest">
					<view class="title">仅需3步即可成为实习顾问</view>
					<view class="open-interest-block">
						<image class="open-interest-icon" :src="isCertification ? require('@/static/icons/work_icon_25.png'): require('@/static/icons/work_icon_24.png')"></image>
						<view class="open-interest-text">
							<view class="open-interest-title">实名认证</view>
							<view class="open-interest-submit">通过身份证实名认证</view>
						</view>
						<button class="open-interest-btn" size="mini" :disabled="isCertification" @click="$Router.push({name: 'UserCertification'})">{{isCertification ? '已认证': '去认证'}}</button>
					</view>
					<view class="open-interest-block">
						<image class="open-interest-icon" :src="isAnswer ? require('@/static/icons/work_icon_25.png'): require('@/static/icons/work_icon_23.png')"></image>
						<view class="open-interest-text">
							<view class="open-interest-title">通过实习顾问考试</view>
							<view class="open-interest-submit">通过线上考试即可完成</view>
						</view>
						<button class="open-interest-btn" size="mini" :disabled="isAnswer" @click="$Router.pushTab({name: 'CollegeTest'})">{{isAnswer ? '已通过': '去考试'}}</button>
					</view>
					<view class="open-interest-block">
						<image class="open-interest-icon" :src="sign.isSign ? require('@/static/icons/work_icon_25.png'): require('@/static/icons/work_icon_27.png')"></image>
						<view class="open-interest-text">
							<view class="open-interest-title">实习顾问签约</view>
							<view class="open-interest-submit">完成实习顾问在线签约</view>
						</view>
						<button class="open-interest-btn" size="mini" :disabled="sign.isSign" @click="onSign">{{sign.isSign ? '已签约': '去签约'}}</button>
					</view>
				</view>
				<!-- 提示信息 -->
				<u-popup :show="privilegeShow" mode="center" bgColor="transparent">
					<view class="privilege-lay">
						<image class="privilege-lay-img" src="@/static/imgs/privilege-lay-header.png" mode="widthFix"></image>
						<view class="privilege-lay-content"><text>{{privilegeText}}</text></view>
						<view class="privilege-lay-remove">
							<u-icon class="privilege-lay-icon" name="close-circle" color="white" size="30" @click="privilegeShow = false"></u-icon>
						</view>
					</view>
				</u-popup>
			</block>
			<!-- 管理中台 -->
				<view class="flex">
					<view class="flex-item" @click="onNav('ConsultWork')">
						<image class="flex-icon" src="/static/icons/icon_00.png" mode="aspectFill"></image>
						<view class="flex-title">
							<view class="flex-name">协商调解咨询类</view>
							<view class="flex-tips">信用卡、贷款业务</view> 
						</view>
						<view class="flex-btn">去查看</view>
					</view>
					<view class="flex-item" @click="onNav('AccountWork')">
						<image class="flex-icon" src="/static/icons/work_icon_30.png" mode="aspectFill"></image>
						<view class="flex-title">
							<view class="flex-name">账户管理咨询类</view>
							<view class="flex-tips">客户账户管理咨询类订单</view> 
						</view>
						<view class="flex-btn">去查看</view>
					</view>
					<view class="flex-item" @click="onNav('DelegationWork')">
						<image class="flex-icon" src="/static/icons/work_icon_29.png" mode="aspectFill"></image>
						<view class="flex-title">
							<view class="flex-name">委托管理类</view>
							<view class="flex-tips">客户委托管理类订单</view> 
						</view>
						<view class="flex-btn">去查看</view>
					</view>
					
					<view class="flex-item" @click="onNav('ServiceWork')">
						<image class="flex-icon" src="/static/icons/icon_01.png" mode="aspectFill"></image>
						<view class="flex-title">
							<view class="flex-name">法律咨询类</view>
							<view class="flex-tips">个人、企业法律</view>
						</view>
						<view class="flex-btn">去查看</view>
					</view>
					<view class="flex-item" @click="onNav('ActionWork')">
						<image class="flex-icon" src="/static/icons/icon_02.png" mode="aspectFill"></image>
						<view class="flex-title">
							<view class="flex-name">诉讼委托咨询类</view>
							<view class="flex-tips">案件委托、拓展服务</view>
						</view>
						<view class="flex-btn">去查看</view>
					</view>
					<view class="flex-item" @click="onNav('EnableWork')">
						<image class="flex-icon" src="/static/icons/icon_03.png" mode="aspectFill"></image>
						<view class="flex-title">
							<view class="flex-name">增收赋能咨询类</view>
							<view class="flex-tips">销售、领袖、演说等</view>
						</view>
						<view class="flex-btn">去查看</view>
					</view>
                    <view class="flex-item" @click="onNav('AccountWork2')">
                    	<image class="flex-icon" src="/static/icons/icon_04.png" mode="aspectFill"></image>
                    	<view class="flex-title">
                    		<view class="flex-name">线下订单</view>
                    		<view class="flex-tips">线下咨询类订单</view>
                    	</view>
                    	<view class="flex-btn">去查看</view>
                    </view>
				</view>
		</view>
		<!-- 未登录 -->
		<view v-else class="auth-null">
			<u-empty
                mode="permission"
                icon="https://douhuo-storage.oss-cn-beijing.aliyuncs.com/images/2023/06/06/c95ebcf8641fcbd413f990d661f638cb.gif"
                text="暂未登录"
			/>
			<button class="auth-null-btn" size="mini" @click="onNav('Auth')">登录</button>
		</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 => {
						switch (res.tapIndex){
							case 0:
								this.onNav('MagAccount2')
								break;
							case 1:
								this.onNav('OrderCreate', { type: 'self' })
								break;
							case 2:
								this.onNav('OrderCreate', { type: 'other' })
								break;
						}
						
						
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		padding-bottom: 30rpx;
	}
	// 登录提示
	.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;
				}
			}
		}
	}
	
	.flex{
		width: 100%;
		padding: 0 30rpx;
		box-sizing: border-box;
		&-item{
			background: white;
			padding: 30rpx;
			border-radius: 30rpx;
			margin-top: 30rpx;
			display: flex;
			box-sizing: border-box;
			position: relative;
			.flex-icon{ width: 48px; height: 48px; border-radius: 30rpx; }
			.flex-title{
				box-sizing: border-box;
				padding-left: 30rpx;
				.flex-name {
					color: #293f66;
					font-size: 34rpx;
					font-weight: bold;
					padding: 4rpx 0;
				}
				.flex-tips {
					color: #929db3;
					font-size: 28rpx;
				}
			}
			.flex-btn {
				position: absolute;
				right: 30rpx;
				top: 48rpx;
				height: 60rpx;
				line-height: 60rpx;
				border-radius: 80rpx;
				color: #468bff;
				background-color: #f8fbff;
				border: 2rpx solid #d8e6ff;
				font-size: 28rpx;
				padding: 0 25rpx;
			}
		}
	}
</style>
