<template>
	<view class="index-page ">
		<view class="header custom_status_bar">
			<view class="status_bar">
				 <div class="name">工作台</div>
				 <div class="actions">
					 <div class="message" @click="linkToMessage">
						 <image v-if="user.userAvatar" class="icon" src="/static/index/message.png" mode="widthFix"></image>
					 </div>
					 <div class="scan" @click="scanQrcode">
						 <image class="icon" src="/static/index/scanner.png" mode="widthFix"></image>
						 <text class="icon-name">扫一扫</text>
					</div>
				 </div>
			</view>		
			<view class="user-info">
				<div class="company">
					<text class="company-name">{{user.ocName}}</text>
					<image class="icon" src="/static/index/company.png" mode="widthFix"></image>
				</div>
				<div class="user">
					<view class="avatar-box">
						<image v-if="user.userAvatar" class="avatar" :src="user.userAvatar" mode="widthFix" @error="userAvatar=defaultAvatar"></image>
						<image v-else class="avatar" :src="defaultAvatar" mode="widthFix"></image>
					</view>
					<view class="info">
						<view class="user-name">
							{{user.userName}}
						</view>
						<view class="user-position">
							{{user.positionName}}
						</view>
					</view>
				</div>
			</view>
		</view>
		<view class="container">
			<view class="cont">
				<div class="container-wrap">
					<div class="notice">
						<div class="notice-name">
							<image class="icon" src="/static/index/notice.png" mode="widthFix"></image>
							<text>最近动态</text>
						</div>
						<div class="notice-cont">
							<uni-notice-bar
								scrollable :text="notice" 
								background-color="#fff0"
								:speed="20"
								color="#333" />
						</div>
					</div>
					<view class="tab">
						<div class="tab-item">
							<image class="icon" src="/static/index/tab1.png" mode="widthFix"></image>
							<view class="tab-name">待办任务 {{taskTotal>99?'99+':taskTotal}} 个</view>
						</div>
						<div class="tab-item">
							<image class="icon" src="/static/index/tab2.png" mode="widthFix"></image>
							<view class="tab-name">告警事件  {{alertTotal>99?'99+':alertTotal}}个</view>
						</div>
						<div class="tab-item">
							<image class="icon" src="/static/index/tab3.png" mode="widthFix"></image>
							<view class="tab-name">待处理隐患   {{dangerTotal>99?'99+':dangerTotal}}个</view>
						</div>
					</view>
					<view class="tab-cont">
						<div class="part">
							<div class="head">
								<text class="head-name">待办任务</text>
								<view class="more" @click="linkTo('task','待办任务')">更多</view>
							</div>
							<div class="part-cont">
								<div class="item" v-for="item in taskList" :key="item.taskId">
									<div class="title">
										<div class="name">{{item.taskTitle}}</div>
										<view class="state">{{taskStatus(item.status)}}</view>
									</div>
									<div class="tags">
										<text class="tag">{{taskPriority(item.taskPriority)}}</text>
										<text class="tag">{{item.taskCatTitle}}</text>
										<text class="tag">{{taskType(item.taskTypeId)}}</text>
									</div>
									<view class="time">
										预期结束时间：{{item.expectedEndTime}}
									</view>
									<div class="bottom">
										<view class="user">
											<image class="avatar" src="/static/index/user.png" mode="widthFix"></image>
											处理人：{{item.handleAccountName}}
										</view>		
										<view class="hand-time">
											{{item.launchTime}}
										</view>																
									</div>
								</div>
							</div>
						</div>
						<div class="part">
							<div class="head">
								<text class="head-name">告警事件</text>
								<view class="more" @click="linkTo('alert','告警事件')">更多</view>
							</div>
							<div class="part-cont">
								<div class="item" v-for="item in alertList" :key="item.alertId">
									<div class="title">
										<div class="name">{{item.alertTitle}}</div>
										<view class="state">{{alertStatus(item.status)}}</view>
									</div>
									<div class="tags">
										<text class="tag">{{alertLevel(item.alertLevel)}}</text>
									</div>
									<view class="time">
										发生时间：{{item.alertTime}}
									</view>
									<div class="bottom">
										<view class="user">
											<image class="avatar" src="/static/index/user.png" mode="widthFix"></image>
											处理人：{{item.handleAccountName}}
										</view>		
										<view class="hand-time">
											{{item.handleTime}}
										</view>																
									</div>
								</div>
							</div>
						</div>
						<div class="part">
							<div class="head">
								<text class="head-name">待处理隐患</text>
								<view class="more" @click="linkTo('danger','待处理隐患')">更多</view>
							</div>
							<div class="part-cont">
								<div class="item" v-for="item in dangerList" :key="item.dangerId">
									<div class="title">
										<div class="name">{{item.dangerTitle}}</div>
										<view class="state">{{dangerStatus(item.status)}}</view>
									</div>
									<div class="tags">
										<text class="tag">{{dangerLevel(item.dangerLevel)}}</text>
										<text class="tag">{{item.dangerCatTitle}}</text>
									</div>
									<view class="time">
										预期结束时间：{{item.dangerDeadLine}}
									</view>
									<div class="bottom">
										<view class="user">
											<image class="avatar" src="/static/index/user.png" mode="widthFix"></image>
											处理人：{{item.curAccountName}}
										</view>		
										<view class="hand-time">
											{{item.submitTime}}
										</view>																
									</div>
								</div>
							</div>
						</div>
					</view>										
				</div>
			</view>
		</view>
	</view>
</template>

<script>
	import {getNotices} from '@/api/system/art.js'
	import { getAlertByPage } from '@/api/aqpt/alertApi.js';
	import { getDangerByPage } from '@/api/aqpt/dangerApi.js';
	import { getTaskByPage } from '@/api/aqpt/taskApi.js';
	import{
		taskStatus,taskPriority,taskType,
		alertLevel,alertStatus,
		dangerStatus,dangerLevel,
	} from '@/libs/enum.js';
	export default {
		data() {
			return {
				applist: [],
				defaultAvatar:"/static/components/avatar.png",
				notice:"",
				user:{
					groupName: "",
					ocName: "",
					positionName: "",
					roleName: "",
					userAvatar: "",
					userIntro: "",
					userName: "",
					userPhone: "",
					userPhoto: "",
					userRealName: ""					
			    },
				alertList:[],
				dangerList:[],
				taskList:[],
				alertTotal:0,
				dangerTotal:0,
				taskTotal:0
			}
		},
		onShow() {
			this.getData()
		},
		methods: {
			taskStatus,taskPriority,taskType,
			alertLevel,alertStatus,
			dangerStatus,dangerLevel,
			scanQrcode(){
				uni.scanCode({
					onlyFromCamera: true,
					success: function (res) {
						console.log('条码类型：' + res.scanType);
						console.log('条码内容：' + res.result);
					},
					fail() {
						uni.showToast({
							icon:'none',
							title:"扫码失败"
						})
					}
				});
			},
			linkToMessage(){
				uni.navigateTo({
					url:"/pages/message/message"
				})
			},
			getData(){
				let user=uni.getStorageSync('accountInfo');
				if(user){this.user=user}
				let notice=""
				getNotices({
					page: 1,
					limit: 10,
					artCatId: 2,
					artCatTitle: "最新动态"
				}).then((res)=>{
					for(let i=0;i<res.data.length;i++){
						notice+=`${res.data[i].artTitle} 发布时间:${res.data[i].issuedAt};`
					}
					this.notice=notice
				})
				let params={
					page: 1,
					limit: 5,
					status: 0,
					handleAccountId: user.userId							
				}
				getAlertByPage(params).then((res)=>{
					this.alertList=res.data
					this.alertTotal=res.total
				})
				getDangerByPage({
					page: 1,
					limit: 5,
					curAccountId: user.userId
				}).then((res)=>{
					this.dangerList=res.data
					this.dangerTotal=res.total
				})
				getTaskByPage(params).then((res)=>{
					this.taskList=res.data
					this.taskTotal=res.total
				})				
			},
			linkTo(type,name){
				uni.navigateTo({
					url:`/pages/index/detail/detail?type=${type}&name=${name}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.index-page {
		min-height: 100vh;
		background-color: rgba(245, 246, 248, 1);
		.header{
			height: 400rpx;
			background-image: url('/static/index/bg.png');
			background-repeat: no-repeat;
			background-size: 100% 100%;
			/* #ifdef MP-WEIXIN */
				padding-top: 28px;
			/* #endif */
			.status_bar{
				padding: 0 32rpx;
				height: 88rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.name{
					font-size: 40rpx;
					font-weight: 600;
					color: #000;
				}
				.actions{
					display: flex;
					align-items: center;
					.message{
						.icon{
							display: inline-block;
							width: 32rpx;
						}
					}
					.scan{
						width: 144rpx;
						height: 48rpx;
						border-radius: 20rpx;
						background-color: #fff;
						display: flex;
						justify-content: center;
						align-items: center;
						margin-left: 32rpx;
						.icon{
							display: inline-block;
							width: 28rpx;					
						}		
						.icon-name{
							font-size: 24rpx;
							color: #000;
							padding-left: 10rpx;
						}
					}				
				}
			}	
			.user-info{
				width: 686rpx;
				height: 228rpx;
				background: linear-gradient(180deg, #7AB2FF 0%, #808EFF 100%);
				margin: 0 auto;
				border-radius: 16px;
				margin-top: 24rpx;
				padding: 24px 22rpx 0 30rpx;
				box-sizing: border-box;
				.company{
					display: flex;
					justify-content: flex-end;
					align-items: center;
					.company-name{
						padding-right: 10rpx;
						font-size: 28rpx;
						color: #fff;
					}
					.icon{
						display: block;
						width: 40rpx;
						height: 40rpx;
					}
				}
				.user{
					display: flex;
					align-items: center;
					.avatar-box{
						width: 72rpx;
						height: 72rpx;	
						border-radius: 50%;
						.avatar{
							display: block;
							width: 72rpx;
							height: 72rpx;	
							border-radius: 50%;
						}					
					}
					.info{
						padding-left: 24rpx;
						.user-name{
							font-size: 32rpx;
							color: #fff;
						}
						.user-position{
							font-size: 24rpx;
							color: #fff;
							opacity: 0.6;
							padding-top: 8rpx;
						}						
					}
				}
			}		
		}
		.container{
			position: relative;
			width: 750rpx;			
			.cont{
				width: 750rpx;
				min-height: 1200px;			
				position: absolute;
				overflow: auto;
				background-image: url('/static/index/bg-bottom.png');
				background-repeat: no-repeat;
				background-size: 100% 1200px;
				background-position: 0 0; 				
				box-sizing: border-box;
				top: -45px;
				margin-top: var(--status-bar-height);
				left: 0;
				.container-wrap{
					padding: 0 32rpx;	
					background-color: rgba(245, 246, 248, 1);	
					padding-bottom: 180rpx;								
				}
				.notice{
					height: 84rpx;
					background-color:rgba(245, 246, 248, 1);
					margin-top: 48rpx;
					border-radius: 8rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;					
					box-shadow: 0px 10px 10px -4px rgba(45, 54, 67, 0.2);
					padding: 0 32rpx;
					.notice-name{
						font-weight: 600;
						font-size: 24rpx;
						color: rgba(0, 0, 0, 0.9);
						.icon{
							width: 22rpx;
							margin-right: 8rpx;
						}
					}
					.notice-cont{
						width: 500rpx;
						height: 80rpx;
						flex: 1;
						font-size: 28rpx;
						color: rgba(0, 0, 0, 0.9);
						// background-color: #fff;
					}
				}
				.tab{
					display: flex;
					justify-content: center;
					align-items: center;
					padding: 40rpx 0 20rpx 0;
					.tab-item{
						width: 33.33%;
						height: 150rpx;
						display: flex;
						justify-content: center;
						align-items: center;	
						flex-direction: column;
						.icon{
							width: 96rpx;
						}
						.tab-name{
							font-size: 28rpx;
							color: rgba(0, 0, 0, 0.9);
							padding-top: 12rpx;
						}
					}
				}
				.tab-cont{				
					.part{
						.head{
							padding-top: 20rpx;
							display: flex;
							justify-content: space-between;
							align-items: center;
							.head-name{
								font-size: 32rpx;
								font-weight: 600;
								color: rgba(0, 0, 0, 0.9);
							}
							.more{
								font-size: 24rpx;
								color: rgba(110, 116, 128, 1);								
							}
					    }
						.part-cont{
							.item{
								background-color: #fff;
								border-radius: 12rpx;
								margin-top: 16rpx;
								padding: 24rpx 20rpx;
								.title{
									display: flex;
									justify-content: space-between;
									align-items: center;
									.name{
										font-size: 36rpx;
										color: rgba(0, 0, 0, 0.8);
									}
									.state{
										font-size: 32rpx;
										color: rgba(250, 139, 55, 1);
									}
								}
								.tags{
									padding-top: 24rpx;
									.tag{
										background: rgba(245, 246, 248, 1);	
										font-size: 20rpx;
										margin-left: 10rpx;
										padding: 10rpx 20rpx;
										&:nth-child(1){
											color: rgba(234, 130, 89, 1);
											background: rgba(251, 241, 237, 1);
										}
									}
								}
								.time{
																	padding-top: 20rpx;
									font-size: 28rpx;									
									color:rgba(241, 57, 57, 0.8);
								}
								.bottom{
									display: flex;
									justify-content: space-between;
									align-items: center;
									padding-top: 20rpx;
									.user{
										display: flex;
										align-items: center;
										font-size: 24rpx;
										color: rgba(0, 0, 0, 1);
										.avatar{
											width: 44rpx;
											margin-right: 10rpx;
										}
									}
									.hand-time{
										font-size: 24rpx;
										color: rgba(0, 0, 0, 1);
									}
								}							
							}
						}
					}
				}
			}
		}
	}

</style>
