<template>
	<view class="zxbox">
		<view class="zxtop">
			<view class="navbox">
				<uni-nav-bar  color="#ffffff" leftWidth='160rpx' rightWidth="48rpx" :background-color="backgroundColor" :border="false" statusBar='true' fixed="true">
					<block slot="left">
						<view class="topl flexc">
							<image :src="adrimg" ></image>
							<view class="over">{{city}}</view>
						</view>
					</block>
					<view class="topc flexc" v-if="checkPermi(['idcard:idcard:list'])">
						<image :src="secimg"></image>
						<input  placeholder="请输入您要找的客户名称" confirm-type="search" v-model="usename" @confirm="getConfirm"/>
					</view>
					<block slot="right">
						<!-- #ifndef H5 -->
						<view class="topr flexcc" @click='getScanFn'>
							<image :src="codeimg"></image>
						</view>
						<!-- #endif -->
					</block>
				</uni-nav-bar>
			</view>
			<image :src="bgimg" class="bgimg"></image>
			<view class="zxmain">
				<view class="banbox mb12" v-if="bannerlist.length">
					<banner :bannerlist="bannerlist"></banner>
				</view>
				<view class="grid" v-if="checkPermi(['system:system:user'])">
					<view class="grid-item-box" @click="getBusListFn(2)" v-if="checkPermi(['system:application:list'])">
						<view class="img"><image :src="topaimg" class="imga"></image></view>
						<view>申报审核</view>
					</view>
					<view class="grid-item-box" @click="getBusListFn(3)" v-if="checkPermi(['system:application:list'])">
						<view class="img"><image :src="topbimg" class="imgb"></image></view>
						<view>担保初审</view>
					</view>
					<view class="grid-item-box" @click="getMoreFn" v-if="checkPermi(['system:hyperlink:list'])">
						<view class="img"><image :src="topcimg" class="imgc"></image></view>
						<view>外部工具</view>
					</view>
					<view class="grid-item-box" @click="getBusListFn(4)" v-if="checkPermi(['system:application:list'])">
						<view class="img"><image :src="topdimg" class="imgd"></image></view>
						<view>尽职调查</view>
					</view>
					<view class="grid-item-box" @click="getBusListFn(6)" v-if="checkPermi(['system:application:list'])">
						<view class="img"><image :src="topeimg" class="imga"></image></view>
						<view>评审会</view>
					</view>
					<view class="grid-item-box" @click="getBusListFn(7)" v-if="checkPermi(['system:application:list'])">
						<view class="img"><image :src="topfimg" class="imgc"></image></view>
						<view>签署合同</view>
					</view>
					<view class="grid-item-box" @click="getLedgerFn">
						<view class="img"><image :src="topgimg" class="imge"></image></view>
						<view>台账表</view>
					</view>
					<view class="grid-item-box" @click="getFileFn" v-if="checkPermi(['system:application:listOss'])">
						<view class="img"><image :src="tophimg" class="imgf"></image></view>
						<view>文件管理</view>
					</view>
				</view>
				<!-- v-if="checkPermi(['zxNotice:notice:list'])" -->
				<view class="mlrbox">
					<view class="mb24">
						<h-notice :noticelist="noticelist" :autoplay='autoplay' @getNoticeDet="getNoticeDet"></h-notice>
					</view>
					<view class="addbox mb26">
						<view class="adda bga" v-if="checkPermi(['system:application:add'])&&checkPermi(['system:registered:user'])" @click="getProveFn">
							<image :src="haddaimg"></image>
							<view class="tit">业务申报</view>
							<view class="txt">在线填写</view>
						</view>
						<view class="adda bgb" @click="getBuszcListFn" v-if="checkPermi(['system:application:list'])&&checkPermi(['system:registered:user'])">
							<image :src="haddbimg"></image>
							<view class="tit">暂存申报</view>
							<view class="txt">继续填报</view>
						</view>
						<!-- 普通客户  -->
						<view class="adda bgc" @click="getBusListFn(0,'my')" v-if="checkPermi(['system:application:list'])&&checkPermi(['system:registered:user'])">
							<image :src="haddcimg"></image>
							<view class="tit">我的申报</view>
							<view class="txt">查看进度</view>
						</view>
						<view class="adda bgd" @click="getBushszListFn" v-if="checkPermi(['system:system:user'])">
							<image :src="hadddimg"></image>
							<view class="tit">回收站</view>
							<view class="txt">一键找回</view>
						</view>
					</view>
					<view class="flexcj tabt pb12" v-if="checkPermi(['system:remind:list'])">
						<view class="left">待办提醒(<text>{{total}}</text>)</view>
						<view class="right flexc" @click="getBusListFn(0)" v-if="checkPermi(['system:application:list'])">更多<image :src="rimg"></image></view>
					</view>
				</view>
			</view>
		</view>
		<!-- 代办提醒 -->
		<view class="hnbox" v-if="checkPermi(['system:remind:list'])">
			<view class="hntabs flexc" :class="fixedflag?'tabfix':''"  :style="fixedflag?'top:'+nvaHeight+'px;':''">
				<block v-for="(ite,idx) in tabList" :key="idx">
					<!-- v-if="checkPermi([ite.limit])" -->
					<view class="tit"   :class="tabval==ite.val?'act':''" @click="getTab(ite.val)">{{ite.tit}}</view>
				</block>
			</view>
			<view style="height:98rpx;" v-if="fixedflag"></view>
			<!-- 列表 -->
			<view class="mt2 plr12" :style="'min-height: ' + minheight + 'px;'">
				<wait-list type='dbtx' :datalist="list" :wtdt="wtdt"  @getDetail="getDetail"></wait-list>
				<view class="shax" v-if="wtdt" @click="getMoreDataFn">{{wtdt}}</view>
			</view>
		</view>
	<view class="bgbox" @click="getClose" v-if="mtype" style="z-index: 100;"></view>
	<view v-if="mtype" class="morebox">
		<view class="molists">
			<view v-for="(ite,idx) in linkList" :key="idx" @click="getWebUel(ite.url)">{{ite.name}}</view>
		</view>
	</view>
	<pop-up :type="type" :initFace="initFace" @getFaFn="getFaFn" @getClose="getClose" @getXxwsFn="getXxwsFn"></pop-up>
	<footers v-if="isfootflag"  :footerindex="footerindex"  :isHomeIndex="true"></footers>
  </view>
</template>

<script>
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	import waitList from "@/components/wait/list.vue"
	let { calendar } = require("@/components/lunc-calendar/calendar.js");
	import {getRemindList,getNoticeList,getbannerList} from "@/api/common.js"
	import {getChangeFace} from "@/api/mine/card.js"
	import {getDictionaryFn} from "@/api/mine/register.js"
	import {getHyperlinkList} from "@/api/mine/work.js"
	import popUp from "@/components/popup/popup.vue"
	import banner from "@/components/toptab/banner.vue"
	import hNotice from '@/components/swiper/notice.vue'
	import footers from '@/components/footer/footer.vue'
	import self from '@/utils/location.js';
	import config from '@/config'
	const baseUrl = config.baseUrl
  export default {
	components:{banner,hNotice,waitList,footers,popUp},
	data(){
		return{
			footerindex:'home',
			isfootflag:true,
			backgroundColor:'transparent',
			bgimg:require("@/static/images/navbg.png"),
			adrimg:require("@/static/images/home/adr.png"),
			noticeimg:require("@/static/images/home/notice.png"),
			secimg:require("@/static/images/home/search.png"),
			topaimg:require("@/static/images/home/topa.png"),
			topbimg:require("@/static/images/home/topb.png"),
			topcimg:require("@/static/images/home/topc.png"),
			topdimg:require("@/static/images/home/topd.png"),
			topeimg:require("@/static/images/home/tope.png"),
			topfimg:require("@/static/images/home/topa.png"),
			topgimg:require("@/static/images/home/topg.png"),
			tophimg:require("@/static/images/home/toph.png"),
			haddaimg:require("@/static/images/home/hadda.png"),
			haddbimg:require("@/static/images/home/haddb.png"),
			haddcimg:require("@/static/images/home/haddc.png"),
			hadddimg:require("@/static/images/home/haddd.png"),
			codeimg:require("@/static/images/home/scan.png"),
			rimg:require("@/static/images/home/rimg.png"),
			noticelist:[],
			autoplay:true,
			
			list:[],
			pageSize: 10,
			pageNum: 1,
			reachflag: true,
			wtdt:'加载更多',
			nvaHeight:44,
			minheight:0,
			listTop:0,//距离顶部的距离
			fixedflag:false,
			tabval:0,
			total:0,
			tabList:[{tit:'全部',val:0},{tit:'申报审核',val:1},{tit:'担保初审',val:2},{tit:'尽职调查',val:3},{tit:'评审会',val:4},{tit:'签署合同',val:5},],
			usename:'',
			type:'',//zcta 暂存信息
			zcid:'',//暂存id
			userId:this.$store.state.user.userId,
			initFace:'Y',//initFace Y不需要,N需要人脸认证
			bannerlist:[],
			metaInfo:'',
			mtype:false,
			city:'',
		}
	},
	onPageScroll(e) {
		var scrollTop = Number(e.scrollTop);
		var listTop=Number(this.listTop)-Number(this.nvaHeight)
		if (scrollTop <=this.nvaHeight) {
			const opacity = scrollTop / 100 // 计算透明度值
			const color = `rgba(4, 145, 253, ${opacity})`
			this.backgroundColor = color // 更新盒子背景颜色
		} else {
			this.backgroundColor = '#00A9F0'
		}
		if(scrollTop>listTop){
			this.fixedflag=true
		}else{
			this.fixedflag=false
		}
	},
	onUnload() {
		uni.$off('refreshdatalist')
	},
	onShow() {
		if(checkPermi(['system:registered:user'])&&!checkPermi(['system:system:user'])){
			this.initFace=this.$store.state.user.initFace;
		}	
	},
	onLoad: function() {
		// uni.$on('refreshdatalist',(e) => {
		// 	this.reachflag=false;
		// 	this.pageNum=1;
		// 	this.list=[];
		// 	this.getDataFn();
		// })
		
		// this.init()
		var that=this;
		// #ifndef H5
		self.getLocation(function(res){
			if(res==-1){
				
			}else{
				that.city=res.city;
				// that.temperature=res.temperature;
				// that.weather=res.weather;
				// that.weathericon=res.icon;
			}			
		})
		// #endif
		if(checkPermi(['system:remind:list'])){
			this.getDataFn()
		}
		if(checkPermi(['system:hyperlink:list'])){
			this.getHyperlinkList()
		}
		this.getNoticeFn()
		this.getbannerList()
		uni.getSystemInfo({
			success: (e) => {
				this.nvaHeight = Number(e.statusBarHeight)+44;
				this.minheight = e.screenHeight - Number(this.nvaHeight)- 100;
			}
		})
		 
	},
	mounted() {
		var that=this;
		setTimeout(function(){
			that.getHeightFn()
		},200)
		
	},
	// 上拉触底加载更多触发事件
	onReachBottom() {
		// if (this.reachflag) {
		// 	this.pageNum++
		// 	this.getDataFn()
		// }
	},
	methods:{
		checkPermi, checkRole,
		getClose(){
			this.type='';
			this.mtype=false;
		},
		getXxwsFn(){
			this.$tab.navigateTo(`/work/pages/prove/index`)
		},
		getMoreDataFn(){
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		getMoreFn(){
			console.log(123)
			this.mtype=true;
		},
		getWebUel(url){
			this.mtype=false;
			this.$tab.navigateTo("/pages/common/webview/index?url="+url)
		},
		// 外部链接
		getHyperlinkList(){
			var params={
				type:1
			}
			getHyperlinkList(params).then(res=>{
				if(res.code==200){
					this.linkList=res.rows
				}
			})
		},
		getFaFn(type,ptype){
			if(ptype=='zcta'){
				if(type=='new'){
					this.$tab.navigateTo("/work/pages/prove/zctype")
				}else{
					var obj={
						type:'edit',
						id:this.zcid,
					}
					this.$tab.navigateTo('/work/pages/business/add?data='+encodeURIComponent(JSON.stringify(obj)))
				}
			}
			this.type='';
		},
		getFace(){
			var that=this;
			var resparams={
				userId:that.userId,
				initFace:'N'
			 }
			getChangeFace(resparams).then(v=>{
				if(v.code==200){
					that.$store.dispatch('GetInfo').then(vres => {
						// 添加企业
						// this.$tab.reLaunch('/pages/index/index') 
						console.log(vres,2)
					})
				}
			}) 
			return
		},
		getConfirm(){
			this.$tab.reLaunch('/pages/custom/index?name='+this.usename)
		},
		getProveFn(){
			this.$tab.navigateTo("/work/pages/prove/zctype")
		},
		getBusListFn(type,from){
			// this.$tab.navigateTo("/work/pages/business/list?type="+type)
			if(from){
				this.$tab.navigateTo("/work/pages/business/list?from=my&type=0")
			}else{
				this.$tab.navigateTo("/work/pages/business/list?type="+type)
			}
			
		},
		getBuszcListFn(){
			this.$tab.navigateTo("/work/pages/business/zclist")
		},
		getBushszListFn(){
			this.$tab.navigateTo("/work/pages/business/hszlist")
		},
		getDown(e){
			uni.showLoading({
				title: '加载中'
			});
			var url=baseUrl+e;
			uni.downloadFile({
				url: url,//文件的下载路径
				success(result) {
						uni.hideLoading()
					var filePath = result.tempFilePath;
					   uni.openDocument({
					     filePath: filePath,
					     showMenu: true,
					     success: function (res) {
					       // console.log('打开文档成功');
					     }
					   });
				},
				fail(res) {uni.hideLoading()}
			})
		},
		getScanFn(){
			// 扫码识别
			var that = this;
			uni.scanCode({
				onlyFromCamera: true,
				autoZoom:false,
				scanType: ['qrCode'],
				success: function(red) {
					let result = red.result;
					console.log(result,1)
					if (typeof result == 'string') {
						try {
							//type1,认证,2 文件
							if(result.type==1){
								that.$tab.navigateTo(`/work/pages/prove/index`)
							}else if(result.type==2){
								that.getDown(result.url)
							}else{
								
							}
						} catch (e) {
							uni.navigateBack({
								delta: 1
							})
							uni.showToast({
								title: '扫码查询失败,请检查二维码是否正确',
								icon: "none"
							})
							return
						}
					}
					
				},
				fail: function(e) {
					if (e && e.errMsg && e.errMsg.indexOf('scanCode:fail cancel') != -1) {
						return;
					}
					uni.showToast({
						title: '扫码失败',
						icon: "none"
					})
				},
			});
		},
		getLedgerFn(){
			this.$tab.navigateTo("/work/pages/file/ledgertable")
		},
		getFileFn(){
			this.$tab.navigateTo("/work/pages/file/list")
		},
		getNoticeDet(e){
			this.$tab.navigateTo("/pages/index/noticedetail?type=xttz&id="+e)
		},
		getDetail(e){
			this.$tab.navigateTo("/pages/index/noticedetail?type=dbtz&id="+e)
		},
		getTab(idx){
			this.tabval=idx;
			this.getrefreshData()
		},
		getrefreshData(){
			this.pageNum=1;
			this.list=[];
			this.reachflag=true;
			this.getDataFn()
		},
		getHeightFn(){
			let query = uni.createSelectorQuery().in(this);
			//需要给黄色区域设置一个id标识,在这里是demo
			query.select('.zxtop').boundingClientRect(data => {
				console.log(data)
				var top=data.top<0 ? -data.top : data.top;
				this.listTop = data.height//赋值,待会要用
				if (top <=this.nvaHeight) {
					const opacity = top / 100 // 计算透明度值
					const color = `rgba(4, 145, 253, ${opacity})`
					this.backgroundColor = color // 更新盒子背景颜色
				} else {
					this.backgroundColor = '#00A9F0'
				}
			}).exec();
		},
		init(){
			// 记录来源
			getDictionaryFn('jluly').then(res=>{
				if(res.code==200){
					this.adrlist = res.data.map(v => {
						return {
							dictLabel: v.dictLabel,
							dictValue: v.dictValue
						}
					})
				}
			})
		},
		time() {
			var date = new Date();
			var y = date.getFullYear();
			var m = date.getMonth() + 1;
			var d = date.getDate();
			let lunar = calendar.solar2lunar(y, m, d); //农历
			this.lunar=lunar.IMonthCn+lunar.IDayCn;
			this.daytime=m+'月'+d+"日";
			// var h = date.getHours();
			// var min = date.getMinutes();
			// var s = date.getSeconds();
			// var week = date.getDay(); //获取当前星期X(0-6,0代表星期天)
			// var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
			// var yearStr = y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d)
			// var timeStr = (h < 10 ? ('0' + h) : h) + ':' + (min < 10 ? ('0' + min) : min) + ':' + (s < 10 ? (
			// 	'0' + s) : s);
			// this.kaTime = yearStr + ' ' + timeStr;
		},
		getNoticeFn(){
			var params={
				pageSize:10,
				pageNum: 1,
			}
			getNoticeList(params).then(res=>{
				if(res.code==200){
					this.noticelist = res.rows;
				}else{
					this.$toast(res.msg)
				}
			}) 
		},
		getbannerList(){
			getbannerList().then(res=>{
				if(res.code==200){
					var data=res.rows;
					var newArr=[];
					data.forEach(ite=>{
						if(ite.imgUrl){
							newArr=newArr.concat(ite.imgUrl.split(','))
						}
					})
					this.bannerlist=newArr;
				}
			})
		},
		getDataFn(){
			var params={
				pageSize:this.pageSize,
				pageNum: this.pageNum,
				userId:this.userId,
			}
			if(this.tabval&&this.tabval!=0){
				params.remindType=this.tabval
			}
			getRemindList(params).then(res=>{
				if(res.code==200){
					this.total=res.total||0
					if (res.rows.length < this.pageSize) {
						this.reachflag = false
						this.wtdt = '到底了~';
					} else {
						var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum -	1)
						if (num < res.total) {
							this.reachflag = true
							this.wtdt = '加载更多'
						} else {
							this.reachflag = false
							this.wtdt = '到底了~';
						}
					}
					if (this.pageNum == 1) {
						this.list = res.rows;
					} else {
						this.list = this.list.concat(res.rows)
					}
				}else{
					this.$toast(res.msg)
				}
			}) 
			
		},
	},
	
  }
</script>
<style>
	page{background-color: #FFFFFF;}
</style>
<style lang="scss" scoped>
.navbox /deep/ .uni-navbar__header-container {align-items: center;padding-left: 0;}
.navbox{position: fixed;left: 0;right: 0;top: 0;z-index: 4;
	.topl{padding-left: 16rpx;overflow: hidden;
		image{width: 30rpx;height: 38rpx;margin-right: 18rpx;flex: 0 0 auto;}
		view{font-weight: bold;font-size: 26rpx;color: #FFFFFF;}	
	}
	.topc{border-radius: 34rpx;height:68rpx;box-sizing: border-box;padding:0 32rpx 0 32rpx ;position: relative;flex:1;background-color: #FFFFFF;
	 input{font-weight: 500;font-size: 26rpx;color: #222327;}
	 image{width: 30rpx;height: 30rpx;margin-right: 24rpx;flex: 0 0 auto;}
	 }
	.topr{width: 48rpx;height: 38rpx;position: relative;
		image{width: 36rpx;height: 38rpx;margin: 0 auto;}
		// .cir{background: #FF4747;font-size: 14rpx;color: #FFFFFF;border-radius: 50%;border: 2rpx solid #FFFFFF;min-width: 20rpx;height: 20rpx;
		// 	position: absolute;right: -5rpx;top: -5rpx;text-align: center;line-height: 16rpx;
		// }
		// .cir{width: 14rpx;height: 14rpx;background: #DF0024;border-radius: 50%;position: absolute;right: -7rpx;top: -7rpx;}
	}
}

.zxbox{
	.bgimg{width: 100%;height: 450rpx;}
	.zxmain{
		margin-top: -270rpx;position: relative;
		.banbox{width: 678rpx;height: 246rpx;margin: 0 auto;}
		.grid{
			display: flex;align-items: center;flex-wrap: wrap;
			.grid-item-box {display: flex;flex-direction: column;align-items: center;justify-content: center;padding: 24rpx 0 36rpx;width: 25%;box-sizing: border-box;
				.img{width: 46rpx;height: 46rpx;display: flex;align-items: center;justify-content: center;margin-bottom: 22rpx;
					.imga{width: 46rpx;height: 46rpx;}
					.imgb{width: 46rpx;height: 40rpx;}
					.imgc{width: 44rpx;height: 46rpx;}
					.imgd{width: 40rpx;height: 46rpx;}
					.imge{width: 42rpx;height: 46rpx;}
					.imgf{width: 44rpx;height: 40rpx;}
				}
				view{font-weight: bold;font-size: 26rpx;color: #222327;}
			}
		}
		
		.mlrbox{margin: 8rpx 36rpx 0;}
		.addbox{
			display: flex;
			.adda{width: 154rpx;height: 190rpx;border-radius: 20rpx;box-sizing: border-box;padding: 28rpx 0 0 20rpx;margin-right: 22rpx;
				&.bga{background: #FFF6F5;}
				&.bgb{background: #F6F8FF;}
				&.bgc{background: #FFF6E7;}
				&.bgd{background: #EFF9F6;}
				&:nth-child(4n){margin-right: 0;}
				image{width: 52rpx;height: 52rpx;margin-bottom: 12rpx;}
				.tit{font-weight: bold;font-size: 28rpx;color: #222327;margin-bottom: 4rpx;}
				.txt{font-size: 22rpx;color: #AAAAAA;}
			}
		}
		.tabt{
			.left{font-weight: bold;font-size: 36rpx;color: #222327;
				text{color: #FF6969;font-size: 30rpx;}
			}
			.right{font-size: 26rpx;color: #AAAAAA;
				image{width: 12rpx;height: 18rpx;margin-left: 14rpx;}
			}
		}
	}
	.hnbox{background-color: #ffffff;padding-bottom: 32rpx;
		.hntabs{padding:20rpx 12rpx 20rpx 34rpx;background-color: #ffffff;overflow: auto;
			&.tabfix{position: fixed;left: 0;right: 0;z-index: 4;box-shadow:  0rpx 4rpx 12rpx 0rpx rgba(196,191,191,0.22);}
			.tit{font-weight: 500;font-size: 26rpx;color: #252736;position: relative;margin-right: 22rpx;height: 58rpx;text-align: center;padding: 0 26rpx;background: #F6F6F6;
				border-radius: 30rpx;flex: 0 0 auto;line-height: 58rpx;
				&.act{font-weight: 500;color: #FFFFFF;background: #00A9F0;
				}
			}
		}
	}
}
.morebox{
	position: fixed;left: 0;right: 0;bottom: 0;z-index: 110;
	.molists{
		view{width: 100%;background: #ffffff;font-weight: 500;font-size: 30rpx;color: #222327;border-bottom: 2rpx solid #E6E6E6;min-height: 100rpx;display: flex;align-items: center;justify-content: center;padding: 10rpx;
		box-sizing: border-box;
		 &.mcoa{color: #00A9F0;}
		}
	}
}
</style>