<template>
	<view class="content">	
		<view class="head">
			<view class="head-lf">
				<view class="name">{{heandName}}</view>			
			</view>
			<view class="head-rt">
				<view class="message zhcx-iconfont zhcx-icon-xiaoxi1">
					<view class="dot">
						<!-- <text>9</text> -->
					</view>
				</view>
				<view class="scanCode zhcx-iconfont zhcx-icon-saomiao" @click="scanCode" />								
			</view>
		</view>
		<uni-notice-bar  showIcon
			text="智慧安全助理通告,智慧安全助理通告,智慧安全助理通告"
		scrollable single/>		
		<view class="list-box workbench">
			<view class="title">
				<text class="tl-1">移动</text>
				<text>工作台</text>
			</view>
			<view class="list">
				<view class="item col-4" v-for="item in items" :key="item.id" @click="linkTo(item.id)">
					<view class="icon">
						<text class="zhcx-iconfont" :class="item.icon" :style="{color:item.color?item.color:'#17b18f'}"></text>
					</view>
					<view class="text">{{item.name}}</view>
				</view>
			</view>			
		</view>
		<view class="banner">
			<swiper :autoplay="true" :interval="3000" :duration="500" circular>
				<swiper-item>
					<view class="swiper-item">
						<image class="bannerImage" src="https://dfs.xazhyc.com/group1/M00/00/01/rBAACGIV34aAElXbAAA37O8IABU50.jpeg"></image>
					</view>
				</swiper-item>
				<swiper-item>
					<view class="swiper-item">
						<image class="bannerImage" src="https://dfs.xazhyc.com/group1/M00/00/01/rBAACGIV352ASQByAAB8a11R5uQ99.jpeg" ></image>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<view class="handle-table">
			<view class="handle-table-title">
				<view class="title-lf">
					<text>待办任务</text>
					<text>【{{taskInfo.total}}】</text>
				</view>
				<view class="title-rt" @click="showMoreTask">
					<text>查看全部</text>
				</view>			
			</view>
			<view class="handle-table-list">
				<view class="item" 
					  v-for="item in taskInfo.items" 
					  :key="item.taskId"
					  @click="showTaskDetail(item)">
					<view class="cont">
						<view class="tag" :class="[formatTaskTage(item.taskTypeId)]">
							<text>{{item.taskTypeId|formatTaskType}}</text>
						</view>
						<view class="name">{{item.taskTitle}}</view>						
					</view>
					<view class="time">{{item.expectedEndTime|distanceTime}}</view>
				</view>						
			</view>
		</view>
    </view>
</template>

<script>
	import {distanceTime,isEmpty} from '@/libs/index.js';
	import {taskType} from '@/libs/enum'
	import {getCheckTaskByPage} from '@/api/task'
	export default {
		filters:{
			distanceTime(val){
				return distanceTime(val)
			},
			formatTaskType(val){
				return taskType(val)
			}
		},
		data() {
			return {
				heandName:"",
				items: [{
						id: 1,name: '全部风险点',color: "#00bfff",
						icon: "zhcx-icon-tupian"
					},
					{
						id: 3,
						name: '隐患上报',
						icon: "zhcx-icon-common_emergency"
					},
					{
						id: 4,
						name: '立即巡检',
						icon: "zhcx-icon-saomiao"
					},
					{
						id: 5,
						name: '检查记录',
						icon: "zhcx-icon-common_ledger"
					},
					{
						id: 6,
						name: '预警中心',
						icon: "zhcx-icon-common_warning"
					}					
				],
				taskInfo:{
					total:0,
					items:[]
				}
			}
		},
		onShow() {
			let userInfo=uni.getStorageSync('accountInfo');
			if(!isEmpty(userInfo)){
				userInfo=JSON.parse(userInfo);
				let executeAccountId=userInfo.userId;
				this.heandName=userInfo.ocName||userInfo.groupName;
				getCheckTaskByPage({
					page:1,
					limit:6,
					isWaiting:1,
					executeAccountId
				}).then((res)=>{
					this.taskInfo.total=res.total;
					this.taskInfo.items=res.data;
				})			
			}			
		},
		methods: {
			scanCode(){
				// 允许从相机和相册扫码
				uni.scanCode({
					success: function (res) {
						let ids = res.result
						uni.navigateTo({
							url: '/views/entRiskPointCheck/index?id=' + ids
						})
					},
					fail(msg) {
						console.log(msg)
						uni.showToast({
							icon:'none',
							mask:true,
							title:'扫码失败'
						})
					}
				});
			},
			showMoreTask(){
				uni.navigateTo({
					url: "/views/task/taskList"
				})
			},			
			linkTo(id) {
				switch (id) {
					case 1:
						uni.navigateTo({
							url: '/views/entRiskPoint/index?id=2',
						})
						return;
					case 3:
						uni.navigateTo({
							url: '/views/danger/riskPointDanger?id=2',
						})												 
						return;
					case 4:
						this.scanCode();
						return;
					case 5:
						uni.navigateTo({
							url: '/views/checkRecord/checkRecord',
						})
						return;
					case 6:
						uni.navigateTo({
							url: '/views/warning/index',
						})
						return;
				}
			},
			formatTaskTage(val){
				let type="";
				switch(val){
					case 1 :
						type="warn";
					break;
					// case 2 :
					// 	type="success";
					// break;	
					case 3 :
						type="purple";
					break;
					case 4 :
						type="danger";
					break;									
				}
				return type;
			},
			showTaskDetail(item){
				let riskPointId=item.riskPointId;
				uni.navigateTo({
					url:'/views/task/detail/detail?id='+item.taskId+'&riskPointId='+riskPointId
				})
			}			
		}
	}
</script>

<style lang="scss" scoped>
	@import url('./index.css');
</style>
