<template name="basics">
	<view>
		<!-- #ifdef APP-PLUS -->
		<view class="status_bar">
			<view class="top_view"></view>
		</view>
		<!-- #endif -->
		<mescroll-uni ref="mescrollRef" :top="StatusBar+'px'" @init="mescrollInit" @down="downCallback" :up="upOption" @up="upCallback">
			<view class="banner">
				<view class="cu-bar search">
					<view class="search-form radius">
						<text class="cuIcon-search"></text>
						<input type="text" placeholder="搜索" confirm-type="search"></input>
					</view>
					<view class="icon-ui"  @click="$noMultipleClicks(scan)">
						<text class="cuIcon-scan"></text>
					</view>
				</view>
				<view class="banner_img">
					<image src="../../static/banner.png" mode=""></image>
				</view>
			</view>
			<view class="home-apps">
				<view class="home-apps-list">
					<navigator class="home-apps-item" hover-class="none" url="/pages/basics/basic-info/basic-info">
						<view class="home-apps-item-img">
							<image src="../../static/icon-apps/home-base.png" mode=""></image>
						</view>
						<view class="text">
							<text>基本资料</text>
						</view>
					</navigator>
					<navigator class="home-apps-item" hover-class="none" url="/pages/basics/work-plan/work-plan">
						<view class="home-apps-item-img">
							<image src="../../static/icon-apps/home-rili.png" mode=""></image>
						</view>
						<view class="text">
							<text>工作安排</text>
						</view>
					</navigator>
					<navigator class="home-apps-item" hover-class="none" url="/pages/basics/risk-distribution/risk-distribution">
						<view class="home-apps-item-img">
							<image src="../../static/icon-apps/home-risk.png" mode=""></image>
						</view>
						<view class="text">
							<text>风险分布</text>
						</view>
					</navigator>
					<navigator class="home-apps-item" hover-class="none" url="/pages/basics/study-files/study-files">
						<view class="home-apps-item-img">
							<image src="../../static/icon-apps/home-fl.png" mode=""></image>
						</view>
						<view class="text">
							<text>法律法规</text>
						</view>
					</navigator>
				</view>
				<view class="home-apps-list">
					<navigator class="home-apps-item" hover-class="none" url="/pages/application/eight-assignments">
						<view class="home-apps-item-img">
							<image src="../../static/icon-apps/home-gw.png" mode=""></image>
						</view>
						<view class="text">
							<text>高危作业</text>
						</view>
					</navigator>
					<navigator class="home-apps-item" hover-class="none" url="/pages/application/commitment">
						<view class="home-apps-item-img">
							<image src="../../static/icon-apps/home-cns.png" mode=""></image>
						</view>
						<view class="text">
							<text>安全承诺</text>
						</view>
					</navigator>
					<!-- <view class="home-apps-item"></view>
					<view class="home-apps-item"></view> -->
					<navigator class="home-apps-item" hover-class="none" url="/pages/application/onlinexxks/home">
						<view class="home-apps-item-img">
							<image src="../../static/icon-apps/home-study.png" mode=""></image>
						</view>
						<view class="text">
							<text>学习园地</text>
						</view>
					</navigator>
					<view class="home-apps-item"></view>
					<!-- <navigator class="home-apps-item" hover-class="none" url="/pages/application/onlinexxks/face/index">
						<view class="home-apps-item-img">
							<image src="../../static/icon-apps/home-study.png" mode=""></image>
						</view>
						<view class="text">
							<text>人脸识别</text>
						</view>
					</navigator> -->
				</view>
			</view>
			<view class="home-hidden">
				<view class="home-work-title">
					<view class="title">
						<view class="q_title"></view>
						<view class="text-black f30b">隐患播报</view>
					</view>
					<view class="this-date" @click="$noMultipleClicks(goHiddenRoll)">更多</view>
				</view>
				<view class="main">
					<view>
						<maoScroll :data="rollData" :showNum="showNum" :lineHeight="lineHeight" :animationScroll="animationScroll" :animation="animation">
							<template v-slot="{line}">
								<view class="flex-line" >
									<view class="oline" v-if="line.HIDDENDESCR">
										{{line.HIDDENDESCR.length>10?line.HIDDENDESCR.substr(0,10)+'...':line.HIDDENDESCR}}
									</view>
									<view class="otext">
										{{line.CREATORNAME}}
									</view>
									<view>
										{{line.CREATTIME}}
									</view>
								</view>
							</template>
						</maoScroll>
					</view>
				</view>
			</view>
			<view class="home-work">
				<view class="home-work-title">
					<view class="title">
						<view class="q_title"></view>
						<view class="text-black f30b">我的工作</view>
					</view>
					<view class="this-date">{{today}}</view>
				</view>
				<view class="work-list">
					<swiper class="swiper" indicator-dots="indicatorDots">
						<swiper-item>
							<view class="work-box">
								<navigator v-if="isRest=='1'" class="swiper-item" hover-class="none" url="../" @click="showRest()">
									<view class="work-border">
										{{hidCount.dpc}}
									</view>
									<view class="mt10">
										待排查
									</view>
								</navigator>
								<navigator v-else class="swiper-item" hover-class="none" url="/pages/application/hidden-trouble-investigation/hidden-trouble-app/hidden-trouble-app?isIndex=1">
									<view class="work-border">
										{{hidCount.dpc}}
									</view>
									<view class="mt10">
										待排查
									</view>
								</navigator>
								<navigator class="swiper-item" hover-class="none" url="/pages/application/hidden-danger-management/hidden-danger-no-change/hidden-danger-no-change?isIndex=1">
									<view class="work-border">
										{{hidCount.dzg}}
									</view>
									<view class="mt10">
										待整改
									</view>
								</navigator>
								<navigator class="swiper-item" hover-class="none" url="/pages/application/hidden-danger-management/hidden-danger-overdue/hidden-danger-overdue?isIndex=1">
									<view class="work-border">
										{{hidCount.ycq}}
									</view>
									<view class="mt10">
										已超期
									</view>
								</navigator>
<!--								<view class="swiper-item">-->
<!--									<view class="work-border">-->
<!--										{{hidCount.dfc}}-->
<!--									</view>-->
<!--									<view class="mt10">-->
<!--										待整改-->
<!--									</view>-->
<!--								</view>-->
								<navigator class="swiper-item" hover-class="none" url="/pages/application/hidden-danger-management/hidden-danger-check/hidden-danger-check?isIndex=1">
									<view class="work-border">
										{{hidCount.dys}}
									</view>
									<view class="mt10">
										待验收
									</view>
								</navigator>
								<navigator class="swiper-item" hover-class="none" url="/pages/application/hidden-danger-management/hidden-danger-finish/hidden-danger-finish?isIndex=1">
									<view class="work-border">
										{{hidCount.yys}}
									</view>
									<view class="mt10">
										已验收
									</view>
								</navigator>
							</view>
						</swiper-item>
						<!-- <swiper-item>
							<view class="work-box">
								<view class="swiper-item">
									<view class="work-border">
										1
									</view>
									<view class="mt10">
										未提交
									</view>
								</view>
								<view class="swiper-item">
									<view class="work-border">
										1
									</view>
									<view class="mt10">
										未提交
									</view>
								</view>
							</view>
						</swiper-item> -->
					</swiper>
				</view>
			</view>
			<view class="home-date">
				<view class="home-work-title">
					<view class="title">
						<view class="q_title"></view>
						<view class="text-black f30b">排查数据</view>
					</view>
					<!-- <view class="this-date">更多</view> -->
				</view>
				<view class="home-date-list">
					<view class="qd-date">
						<view class="qd-date-item">
							<view class="date text-blue">
								{{hdCount.monthTotal}}
							</view>
							<view class="name">
								发现隐患数
							</view>
						</view>
						<view class="qd-date-item">
							<view class="date text-orange">
								{{hdCount.monthChecked}}
							</view>
							<view class="name">
								已整改隐患数
							</view>
						</view>
						<view class="qd-date-item">
							<view class="date text-green">
								{{hdCount.monthTotal==0?0:((hdCount.monthChecked/hdCount.monthTotal*100).toFixed(2))}}%
							</view>
							<view class="name">
								隐患整改率
							</view>
						</view>
						<view class="qd-tag bg-blue">
							<text>月</text>
							<text>度</text>
						</view>
					</view>
					<view class="qd-date">
						<view class="qd-date-item">
							<view class="date text-blue">
								{{hdCount.yearTotal}}
							</view>
							<view class="name">
								发现隐患数
							</view>
						</view>
						<view class="qd-date-item">
							<view class="date text-orange">
								{{hdCount.yearChecked}}
							</view>
							<view class="name">
								已整改隐患数
							</view>
						</view>
						<view class="qd-date-item">
							<view class="date text-green">
								{{hdCount.yearTotal==0?0:((hdCount.yearChecked/hdCount.yearTotal*100).toFixed(2))}}%
							</view>
							<view class="name">
								隐患整改率
							</view>
						</view>
						<view class="qd-tag bg-red">
							<text>年</text>
							<text>度</text>
						</view>
					</view>
				</view>
			</view>
			<view class="cu-tabbar-height"></view>
			</mescroll-uni>

	</view>
</template>

<script>
	import {
		basePath,
		loginUserId,
		formatDate,
		loginUser,
		setloginUserId,
		setCorpinfoId,
		setloginUser,
		setDeptId,
		isRest,
		corpinfoId,
		setIsRest
	} from '@/common/tool.js';

	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import maoScroll from '@/components/mao-scroll/mao-scroll.vue';
	export default {
		components:{
			maoScroll
		},
		mixins: [MescrollMixin], // 使用mixin (在main.js注册全局组件)
		data() {
			return {
				noClick:true,
				StatusBar: this.StatusBar,
				StatusBarb: this.StatusBar + 50,
				hidCount: [],
				hdCount:{},
				today :'',
				triggered: false,

				totalList:[],
				isGoodsEdit: false,  // 是否加载编辑后的数据
				downOption:{
					mustToTop:true,
				},
				upOption: {
					use: false, // 禁止上拉
					toTop: {
						src: '' // 不显示回到顶部按钮
					}
				},
				isRest :'',
				showNum: 6,
				lineHeight: 60,
				animationScroll: 180,
				animation: 3000,
				rollData:[]
			};
		},
		mounted(){
			// uni.startPullDownRefresh();
			let now = new Date();
			var today =  formatDate(now, 'yyyy-MM-dd');
			this.getIsRest();
			this.getData();
			this.getListData();
			// 获取隐患播报滚动
			this.getHiddenRoll();
			// this._freshing = false;
			// setTimeout(() => {
			// 	this.triggered = true;
			// }, 1000)

		},
		// onPullDownRefresh() {
		// 	console.log('refresh');
		// 	setTimeout(function () {
		// 		uni.stopPullDownRefresh();
		// 	}, 1000);
		// },
		methods: {
			async downCallback(page) {

				await this.getWork();
				await this.getMonth();
				await this.getYear();
				await this.mescroll.endSuccess();
				this.mescroll.scrollTo( 0,100 )
			},
			getWork(){
				return new Promise((resolve, reject) => {
					var _this = this;
					uni.request({
						url: basePath + '/app/hidden/getCountByUserId',
						method: 'POST',
						dataType: 'json',
						header:{
								'Content-type':'application/x-www-form-urlencoded'
						},
						data: {
							userId: loginUserId,
							CORPINFO_ID: loginUser.CORPINFO_ID,
							USER_ID: loginUser.USER_ID,
							USER_NAME: loginUser.NAME,
							CHECK_DEPARTMENT_ID: loginUser.DEPARTMENT_ID,
							IS_MAIN:loginUser.ISMAIN
						},
						success: (res) => {
							if (res.data != null) {
								_this.hidCount = res.data.hidCount;
								resolve();
							}
						}
					});
				})
			},

			showRest(){

				uni.showModal({
					title: '提示',
					showCancel:false,
					content: '您处于离岗状态，无需检查清单。',
					confirmText: "返回", // 确认按钮文字
					success: (res) => {
					}
				})
			},
			getMonth(){
				return new Promise((resolve, reject) => {
					var _this = this;
					//月隐患数
					uni.request({
						url: basePath + '/app/hidden/getIndexCount',
						method: 'POST',
						dataType: 'json',
						header:{
							'Content-type':'application/x-www-form-urlencoded'
						},
						data: {
							userId: loginUserId,
							IS_MONTH:'1'
						},
						success: (res) => {
							if (res.data != null) {
								_this.hdCount.monthTotal = res.data.total;
								_this.hdCount.monthChecked = res.data.checked;
								_this.hdCount.monthUncheck = res.data.uncheck;
								this.$forceUpdate();
								resolve();

							}
						}
					});
				})
			},
			getYear(){
				return new Promise((resolve, reject) => {
					var _this = this;
					//年隐患数
					uni.request({
						url: basePath + '/app/hidden/getIndexCount',
						method: 'POST',
						dataType: 'json',
						header:{
							'Content-type':'application/x-www-form-urlencoded'
						},
						data: {
							userId: loginUserId,
							IS_YEAR:'1'
						},
						success: (res) => {
							if (res.data != null) {
								_this.hdCount.yearTotal = res.data.total;
								_this.hdCount.yearChecked = res.data.checked;
								_this.hdCount.yearUncheck = res.data.uncheck;
								this.$forceUpdate();
								resolve();
							}
						}
					});
				})
			},
			getData() {


				var _this = this;
				let now = new Date();
				_this.today =  formatDate(now, 'yyyy-MM-dd');
				uni.request({
					url: basePath + '/app/hidden/getCountByUserId',
					method: 'POST',
					dataType: 'json',
					header:{
							'Content-type':'application/x-www-form-urlencoded'
					},
					data: {
						userId: loginUserId,
						CORPINFO_ID: loginUser.CORPINFO_ID,
						USER_ID: loginUser.USER_ID,
						USER_NAME: loginUser.NAME,
						CHECK_DEPARTMENT_ID: loginUser.DEPARTMENT_ID,
							IS_MAIN:loginUser.ISMAIN
					},
					success: (res) => {

						if (res.data != null) {
							_this.hidCount = res.data.hidCount;
						}
					},
					fail: (res) => {
						uni.showToast({
							icon: 'none',
							title: "服务器正在升级，请稍后再试。",
							duration: 2000
						});
						setTimeout(function() {
							plus.runtime.quit();
							// ios quit方法无效，退出到登陆页
							setloginUserId(null);
							setCorpinfoId(null);
							setDeptId(null);
							setloginUser(null);
							uni.removeStorage({key: 'USER'});
							uni.navigateTo({
								url: '/pages/login/home'
							});
						}, 2000);
					}
				});

				//月隐患数
				uni.request({
					url: basePath + '/app/hidden/getIndexCount',
					method: 'POST',
					dataType: 'json',
					header:{
						'Content-type':'application/x-www-form-urlencoded'
					},
					data: {
						userId: loginUserId,
						IS_MONTH:'1'
					},
					success: (res) => {
						if (res.data != null) {
							_this.hdCount.monthTotal = res.data.total;
							_this.hdCount.monthChecked = res.data.checked;
							_this.hdCount.monthUncheck = res.data.uncheck;
							this.$forceUpdate();//强制刷新
						}
					}
				});
				//年隐患数

				uni.request({
					url: basePath + '/app/hidden/getIndexCount',
					method: 'POST',
					dataType: 'json',
					header:{
						'Content-type':'application/x-www-form-urlencoded'
					},
					data: {
						userId: loginUserId,
						IS_YEAR:'1'
					},
					success: (res) => {
						if (res.data != null) {
							_this.hdCount.yearTotal = res.data.total;
							_this.hdCount.yearChecked = res.data.checked;
							_this.hdCount.yearUncheck = res.data.uncheck;
							this.$forceUpdate();//强制刷新
						}
					}
				});
			},

			goHiddenRoll(){
				this.$emit('setInit',true);
				uni.navigateTo({
					url: '/pages/application/hidden-danger-management/hidden-danger-record/hidden-danger-record-roll',
				});
			},
			// 获取清单数量
			getListData(){
				var _this=this;
				uni.showLoading({
					title: '加载中'
				})

				uni.request({

					url: basePath + '/app/listmanager/checkList',
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type':'application/x-www-form-urlencoded'
					},
					data: {
						CORPINFO_ID: loginUser.CORPINFO_ID,
						USER_ID: loginUser.USER_ID,
						USER_NAME: loginUser.NAME,
						CHECK_DEPARTMENT_ID: loginUser.DEPARTMENT_ID,
						IS_MAIN:loginUser.ISMAIN,
					},
					success: (res) => {
						if("success" == res.data.result){
							uni.hideLoading();
							var content = res.data.varList;
							for(var i=0;i<content.length;i++){
								if(content[i].checkCount==0){
									this.totalList.push(content[i]);
								}else{
									this.totalList.push(content[i]);
								}
							}
						}else{
							uni.showToast({
								icon:'none',
								title: '系统异常',
								duration: 2000
							});
						}
					},
					fail: (res) => {
						uni.showToast({
							icon: 'none',
							title: "服务器正在升级，请稍后再试。",
							duration: 2000
						});
						setTimeout(function() {
							plus.runtime.quit();
						}, 2000);
					}
				})
			},
			// 获得滚动隐患
			getHiddenRoll(){

				var _this=this;
				uni.showLoading({
					title: '加载中'
				})
				uni.request({

					url: basePath + '/app/hidden/getHiddenByCorp',
					method: 'POST',
					dataType: 'json',
					header: {
						'Content-type':'application/x-www-form-urlencoded'
					},
					data: {
						CORPINFO_ID: loginUser.CORPINFO_ID,
					},
					success: (res) => {
						if("success" == res.data.result){
							uni.hideLoading();
							for(var i = 0; i < res.data.hiddenList.length; i++){
								if(res.data.hiddenList[i].CREATTIME){
									var subStr=new RegExp('-','ig');//创建正则表达式对象,不区分大小写,全局查找
									let date = new Date(res.data.hiddenList[i].CREATTIME.replace(subStr,"/"))
									res.data.hiddenList[i].CREATTIME = formatDate(date, 'MM-dd hh:mm')
								}
							}
							_this.rollData = res.data.hiddenList;
							_this.$forceUpdate(); //强制刷新
						}else{
							uni.showToast({
								icon:'none',
								title: '系统异常',
								duration: 2000
							});
						}
					},
					fail: (res) => {
						uni.showToast({
							icon: 'none',
							title: "服务器正在升级，请稍后再试。",
							duration: 2000
						});
						setTimeout(function() {
							plus.runtime.quit();
						}, 2000);
					}
				})
			},
			// refresh() {
			// 	if (this._freshing) return;
			// 	this._freshing = true;
			// 	this.getData();
			// 	setTimeout(() => {
			// 		this.triggered = false;
			// 		this._freshing = false;
			// 	}, 1000)
			// },
			// refreshEnd() {
			// 	this.triggered = 'restore'; // 需要重置
			// 	console.log("onRestore");
			// },

			// scan(){
			// 	let _this=this;
			// 	uni.scanCode({
			// 		success: function (res) {
			// 			let flag=false;
			// 			let listId =  res.result;
			// 			for(var i=0;i<_this.totalList.length;i++){
			// 				if(_this.totalList[i].LISTMANAGER_ID==listId){
			// 					flag=true;
			// 					_this.goToList({listId:_this.totalList[i].LISTMANAGER_ID,listName:_this.totalList[i].NAME});
			// 					break;
			// 				}
			// 			}
			// 			if(!flag){
			// 				uni.showToast({
			// 					title: "无法检查该清单",
			// 					duration: 2000
			// 				});
			// 			}
			// 		}
			// 	});
			// },

			scan(){
				let _this=this;
				uni.scanCode({
					success: function (res) {
						if(res.result.indexOf('%_face') > 0){
							_this.goToFace(res.result.substring(0,res.result.indexOf('%_face')))
						}else{
							let flag=false;
							let listId =  res.result;
							for(var i=0;i<_this.totalList.length;i++){
								if(_this.totalList[i].LISTMANAGER_ID==listId){
									flag=true;
									_this.goToList({listId:_this.totalList[i].LISTMANAGER_ID,listName:_this.totalList[i].NAME});
									break;
								}
							}
							if(!flag){
								uni.showToast({
									title: "无法检查该清单",
									duration: 2000
								});
							}
						}
					}
				});
			},

			getIsRest(){
				var _this = this;
				// 查看是否离岗
				uni.request({
					url: basePath+'/app/offduty/isRest',
					method: 'POST',
					dataType: 'json',
					header:{
						'Content-type':'application/x-www-form-urlencoded'
					},
					data: {
						CORPINFO_ID:corpinfoId,
						USER_ID:loginUser.USER_ID,
					},
					success: (res) => {
						if (res.data.ISREST != null) {
							setIsRest(res.data.ISREST);
							_this.isRest = res.data.ISREST;
						}
						_this.$forceUpdate();
					},
					fail: (res) => {
						uni.showToast({
							icon: 'none',
							title: "服务器正在升级，请稍后再试。",
							duration: 2000
						});
					}
				});
			},
			// scan(){
			// 	let _this=this;
			// 	uni.scanCode({
			// 		success: function (res) {
			// 			let flag=false;
			// 			let unit =  res.result;
			// 			uni.navigateTo({
			// 				url: '/pages/basics/risk-distribution/risk-distribution-forunit?unit='+unit
			// 			});
			// 			// _this.goToList({listId:_this.totalList[i].LISTMANAGER_ID,listName:_this.totalList[i].NAME});
			// 		}
			// 	});
			// },
			//跳转事件
			goToexclude(e) {
				this.$emit('setInit',true);
				uni.navigateTo({
					url: '/pages/basics/hidden-danger-exclude/exclude-list',
				});
			},
			goToDanger(e) {
				this.$emit('setInit',true);
				uni.navigateTo({
					url: '/pages/basics/danger-exclude/danger-exclude-list',
				});
			},
			toSetinit(e) {
				this.$emit('setInit',true);
			},
			//跳转事件
			goToList(e) {
				uni.navigateTo({
					url: '/pages/application/hidden-trouble-investigation/hidden-trouble-app/hidden-trouble-spot?listId='+e.listId+'&listName='+e.listName
				});
				// uni.navigateTo({
				// 	url: '/pages/application/hidden-trouble-investigation/hidden-trouble-app/check-items-list?listId='+e.listId+'&listName='+e.listName
				// });
			},
			goToFace(userId){
				uni.navigateTo({
					url: '/pages/basics/recognitionFace/index?userId='+userId
				});
			}
		}
	}
</script>
<style>
.status_bar {
    height: var(--status-bar-height);
    width: 100%;
    background-color: #0b216a;
}
.top_view {
    height: var(--status-bar-height);
    width: 100%;
    position: fixed;
    background-color: #0b216a;
    top: 0;
    z-index: 999;
}
	/*说明*/
	.notice-warp{
		font-size: 26upx;
		padding: 40upx 0;
		border-bottom: 1upx solid #eee;
		text-align: center;
	}
	.notice-warp .notice{
		color:#555;
	}
	.notice-warp .btn-change{
		display: inline-block;
		margin-top: 28upx;
		padding: 6upx 16upx;
		border: 1upx solid #FF6990;
		border-radius: 40upx;
		color: #FF6990;
	}
	.notice-warp .btn-change:active{
		opacity: .5;
	}
	.main{
		padding: 0 30upx;
	}
	.flex-line{
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.flex-line .oline{
		flex: 1;
	}
	.flex-line .otext{
		width: 200upx;
		text-align: left;
		 white-space: nowrap;
		 overflow: hidden;
		  text-overflow: ellipsis;
	}
</style>
