<template>
	<view class="content">
		<view class="">
			<!-- 头部 -->
			<u-navbar :border-bottom="false" :is-back="false" title=" ">
				<view class="slot-wrap">
					<view class="padding-left-40 " >
						<u-icon size="34" name="map"></u-icon>
						<text  style="font-size: 34rpx;padding: 0 10rpx;">{{gander?gander:'暂无园区信息'}}</text>
					</view>
				  <!-- <view class="padding-left-40 " @click="ganderShow=true">
					<text class="padding-right-10" style="font-size: 34rpx;">{{gander?gander:'暂无园区信息'}}</text>
					<u-icon  :name="ganderShow?'arrow-up-fill':'arrow-down-fill'" top="-5" size="20" color="#7f7f7f"></u-icon>
				  </view> -->
				</view>
			</u-navbar>
			<!-- banner -->
			<swiper   class="screen-swiper square-dot "  :indicator-dots="true" :circular="true"
			 :autoplay="true" interval="5000" duration="500">
				<swiper-item v-for="(item,index) in bannerList" :key="index">
					<image   :src="item.image" mode="aspectFill" ></image>
				</swiper-item>
			</swiper>
			<!-- 公告 -->
			<view v-if="!$isEmpty(noticeList)" class="">
				<view class="bg-white" style="height: 10rpx;"></view>
				<hotConsult  @onTap="jump('/pages/index/notice/notice')" @detailTap="goNoticeDetail" :swiperTexts="noticeList"></hotConsult>
			</view>
			<!-- 园区服务 -->
			<view class="bg-white">
				<view  style="padding: 30rpx 30rpx 0 30rpx; ">
					<text class="cuIcon-titles text-blue"></text>
					<text class="text-bold text-lg">园区服务</text>
				</view>
				<view class="nav-list  padding-top-30" >
					<view
						v-if="item.show"
						hover-class="none"
						@click="jump(item.url)"
						class="nav-li light"  :style="{backgroundColor:item.color}" 
						v-for="(item,index) in elements" :key="index">
						<view class="nav-title" style="color: #000000;font-size: 28rpx;">{{item.title}}</view>
						<view class="" style="padding-top: 10rpx;font-size: 24rpx;color: #acacac;">{{item.name}}{{item.show}}</view>
						<image :src="item.icon" mode=""></image>
						<u-badge  :is-center="true" type="error" :count="item.count"></u-badge>
					</view>
				</view>
			</view>
			<view class="bg-white" v-if="loginType=='enterprise'">
				<view  style="padding: 30rpx 30rpx 0 30rpx; ">
					<text class="cuIcon-titles text-blue"></text>
					<text class="text-bold text-lg">消防服务</text>
				</view>
				<view class="nav-list  padding-top-30" >
					<view hover-class="none"
						@click="jump(item.url)"
						class="nav-li light"  :style="{backgroundColor:item.color}" 
						v-for="(item,index) in fireList" :key="index">
						<view class="nav-title" style="color: #000000;font-size: 28rpx;">{{item.title}}</view>
						<view class="" style="padding-top: 10rpx;font-size: 24rpx;color: #acacac;">{{item.name}}</view>
						<image :src="item.icon" mode=""></image>
					</view>
				</view>
			</view>
			<view class="bg-white padding-bottom-20">
				<view class="flex justify-between" style="padding: 26rpx;">
					<view class="">
						<text class="cuIcon-titles text-blue"></text>
						<text class="text-bold text-lg">园区动态</text>
					</view>
					<view @click="jump('/pages/news/list')" style="padding-top: 6rpx;font-size: 26rpx;color: #676767;">
						<text>查看更多</text>
						<text class="cuIcon-right "></text>
					</view>
				</view>
				<infomation :newList="newsList"></infomation>
			</view>
			<u-action-sheet @click="ganderChange" :list="ganderArray" v-model="ganderShow"></u-action-sheet>
		</view>
		<u-tabbar v-model="tabbarCurr"
		 :icon-size="tabbar.iconSize" 
		 :active-color="tabbar.activeColor" 
		 :list="tabbar.list" >
		 </u-tabbar>
	</view>
</template>

<script>
import {tabbar} from "@/assets/js/tabbar.js"
import hotConsult from "@/components/hot-consult/hot-consult.vue"
import infomation from "@/components/infomation/infomation.vue"
export default {
	components:{
		hotConsult,infomation
	},
	data() {
		return {
			//登陆类型
			loginType:this.$cache.get('loginType') || '',
			//tabbar
			tabbarCurr:0,
			tabbar:tabbar,
			//园区 label
			
			ganderShow:false,
			//园区列表
			ganderArray:[], 
			gander:'',
			
			//banner
			bannerList: [],
			// 公告
			noticeList:[],
			//消防服务
			fireList:[],
			//园区服务
		    elements: [],
			
			//园区动态
			newsList:[]
			
		};
	},
	onShow() {
		this.fetchNoticeList()
		if (this.loginType==this.$loginType.ENTERPRISE) {
			this.fetchWaitAuditNum()
		}
	},
	onLoad() {
		
		this.fetchStaticData()
		this.fetchUserInfo()
		this.fetchNewsList()
	},
	methods:{
		fetchNewsList(){
			let params={
				size:5,
				agencyId:this.$cache.get('agencyId').toString()
			}
			this.$api.CMS.page(params).then(res=>{
				this.newsList=res.data.records
			})
		},
		/**
		 * 加载用户数据
		 */
		fetchUserInfo(){
		   if (this.loginType==this.$loginType.STAFF) {
				//员工
				let phone=this.$cache.get('phone')
				this.$api.enterprisestaff.detail({phone:phone}).then(res=>{
					getApp().globalData.userInfo=res.data
					this.$cache.put("residentialId",res.data.residentialId)
					this.gander=res.data.agencyName
				})
		   }else if (this.loginType==this.$loginType.ENTERPRISE) {
			   this.gander=this.$cache.get('enterpriseName')
				let creditCode=this.$cache.get('creditCode')
				this.$api.enterprise.detail({creditCode:creditCode}).then(res=>{
					getApp().globalData.userInfo=res.data
					this.$cache.put("residentialId",res.data.residentialId)
				})
		   }
		},
		/**
		 * 加载待审核员工的数量
		 */
		fetchWaitAuditNum(){
			let that=this
			let obj={
				enterpriseId:this.$cache.get('enterpriseId'),
				size:300,
				examine:0
			}
			this.$api.enterprisestaff.page(obj).then(res=>{
				if (!that.$isEmpty(res.data.records)) {
					that.elements.forEach(item=>{
						if (item.url=='/pages/index/staffAudit/list') {
							item.count=res.data.total
						}
					})				
				}else{
					that.elements.forEach(item=>{
						if (item.url=='/pages/index/staffAudit/list') {
							item.count=0
						}
					})	
				}
				console.log(that.elements);
			})
		},
		/**
		 * @param {Object} index更改园区
		 */
		ganderChange(index){
			this.gander=this.ganderArray[index].text
		},
		/**
		 * 跳转
		 * @param {Object} url
		 */
		jump(url){
			if (!this.$isEmpty(url)) {
				uni.navigateTo({
					url:url
				})
			}
		},
		/**
		 * 加载通知列表
		 */
		fetchNoticeList(){
			let params={
				agencyId:this.$cache.get('agencyId')
			}
			this.$api.notice.page(params).then(res=>{
				this.noticeList=res.data.records
			})
		},
		/**
		 * 跳转到通知详情
		 */
		goNoticeDetail(item){
			console.log(item);
			getApp().globalData.noticeDetail=item
			uni.navigateTo({
				url:"/pages/index/notice/detail",
			})
		},
		/**
		 * 加载静态数据
		 */
		fetchStaticData(){
			this.bannerList=[
				{
				  'image': "http://139.9.103.171:1888/miniofile/xlyq/banner01.jpg"
				},
			]
			this.elements=[
				{
					title: '我的企业',
					name: 'My business',
					color: '#f9f4f1',
					icon: '../../static/index/gander/qiye.png',
					url:'/pages/company/company',
					count:0,
					show:true
				},
				{
					title: '我的资料',
					name: 'My profile',
					color: '#ecf3f9',
					icon: '../../static/index/gander/renzheng.png',
					// url:'/pages/auth/auth?operationType=1',
					url:'/pages/index/myinfo/myinfo',
					count:0,
					show:this.loginType==this.$loginType.STAFF
				}, 
				{
					title: '员工审核',
					name: 'Staff certification',
					color: '#ecf3f9',
					icon: '../../static/index/gander/renzheng.png',
					url:'/pages/index/staffAudit/list',
					count:0,
					show:this.loginType==this.$loginType.ENTERPRISE
				},
				{
					title: '我的测温',
					name: 'My temperature',
					color: '#f0f3ff',
					icon: '../../static/index/gander/cewen1.png',
					url:'/pages/index/my-temperature/my-temperature',
					count:0,
					show:this.loginType==this.$loginType.STAFF
				}, 
				{
					title: '员工测温',
					name: 'Staff temperature',
					color: '#f0f3ff',
					icon: '../../static/index/gander/cewen1.png',
					url:'/pages/index/staff-temperature/staff-temperature',
					count:0,
					show:this.loginType==this.$loginType.ENTERPRISE
				}, 
				{
					title: '通行记录',
					name: 'Access records',
					color: '#f7f7f5',
					icon: '../../static/index/gander/tongxing.png',
					url:'/pages/index/access-record/access-record',
					count:0,
					show:true
				}
			]
			this.fireList=[
				{
					title: '烟感报警',
					name: 'Smoke alarm',
					color: '#f2f0fd',
					icon: '../../static/index/fire/yangan.png',
					url:"/pages/index/fire/list/list?fireType=0"
				},
				{
					title: '燃气告警',
					name: 'Gas alarm',
					color: '#f0ecea',
					icon: '../../static/index/fire/ranqi.png',
					url:"/pages/index/fire/list/list?fireType=1"
				}, 
				{
					title: '消防水压',
					name: 'Fire water pressure',
					color: '#ecf3f9',
					icon: '../../static/index/fire/xiaofang.png',
					url:"/pages/index/fire/list/list?fireType=2"
				}, 
				
			]
		}
	}
};
</script>

<style lang="scss" scoped>
	page,.content{
		background-color: #FFFFFF;
		min-height: 100vh;
	}
	//四宫格 begin
	.nav-list {
		display: flex;
		flex-wrap: wrap;
		justify-content: flex-start;
	}
	.nav-li {
		padding: 30upx 30rpx;
		border-radius: 12upx;
		width: 44%;
		margin: 10rpx 2% 10upx;
		background-size: cover;
		background-position: center;
		position: relative;
		z-index: 1;
	}
	.nav-li::after {
		content: "";
		position: absolute;
		z-index: -1;
		background-color: inherit;
		width: 100%;
		height: 100%;
		left: 0;
		bottom: -10%;
		border-radius: 10upx;
		opacity: 0.2;
		transform: scale(0.9, 0.9);
	}
	.nav-li.cur {
		color: #fff;
		background: rgb(94, 185, 94);
		box-shadow: 4upx 4upx 6upx rgba(94, 185, 94, 0.4);
	}
	.nav-title {
		font-size: 32upx;
		font-weight: 300;
	}
	.nav-title::first-letter {
		font-size: 40upx;
		margin-right: 4upx;
	}
	.nav-name {
		font-size: 28upx;
		text-transform: Capitalize;
		margin-top: 20upx;
		position: relative;
	}
	.nav-name::before {
		content: "";
		position: absolute;
		display: block;
		width: 40upx;
		height: 6upx;
		background: #fff;
		bottom: 0;
		right: 0;
		opacity: 0.5;
	}
	.nav-name::after {
		content: "";
		position: absolute;
		display: block;
		width: 100upx;
		height: 1px;
		background: #fff;
		bottom: 0;
		right: 40upx;
		opacity: 0.3;
	}
	.nav-name::first-letter {
		font-weight: bold;
		font-size: 36upx;
		margin-right: 1px;
	}
	.nav-li image {
		position: absolute;
		right: 30upx;
		top: 22upx;
		width: 66upx;
		height: 66upx;
	}
	//四宫格 end
	
</style>