<template>
	<view class="zxbox">
		<view class="navbox">
			<uni-nav-bar color="#ffffff"  :background-color="backgroundColor" :border="false"
				statusBar='true' fixed="true">
				<!-- #ifndef MP-WEIXIN -->
				<block slot="right">
				<!-- #endif -->
				<!-- #ifdef MP-WEIXIN -->
				<block slot="left">
				<!-- #endif -->
					<view class="topr" @click='getNoticeFn'>
						<image :src="noticimg"></image>
						<view class="cir"></view>
						<!-- <block v-if="noticenum>99">99+</block>
						<block v-else>{{noticenum}}</block> -->
					</view>
				</block>
			</uni-nav-bar>
		</view>
		<image :src="bgimg" class="bgimg"></image>
		<view class="mbox">
			<view class="infobox flexc" @click="handleToInfo">
				<image v-if="avatar" @click.stop="handleToAvatar" :src="avatar" class="limg" mode="aspectFill"></image>
				<image v-else @click.stop="handleToAvatar" :src="avatarimg" class="limg" mode="aspectFill"></image>
				<view class="cbox">
					<view class="tit">{{name?name:'登录账号'}}</view>
					<view class="flexc pr" v-if="deptName">
						<image :src="headl"></image>
							<view class="txt">{{deptName}}</view>
						<image :src="headr"></image>
					</view>
				</view>
				<image :src="wrimg" class="rimg"></image>
			</view>
			<view class="conts" v-if="checkPermi(['system:statistics:loan'])">
				<view class="conta">
					<view class="flexcj mb19">
						<view class="f15 fw co23 flex0 ml8">月份放款统计 <text class="coa ml4">/万元</text></view>
						<picker mode="date" fields="month"   @change='bindDateChangea'>
							<view class="f12 coa fw5 flexc">
								<view>{{monthtime}}</view>
								<image :src="rimg" class="rimg"></image>
							</view>
						</picker>
					</view>
					<view class="flexc">
						<view class="contn">
							<view class="img">
								<image :src="mconta" class="imga"></image>
							</view>
							<view class="ctit">待放款</view>
							<view class="ctxt co1l">{{monthcont.dfk}}</view>
						</view>
						<view class="line"></view>
						<view class="contn">
							<view class="img">
								<image :src="mcontb" class="imgb"></image>
							</view>
							<view class="ctit">已放款</view>
							<view class="ctxt co1l">{{monthcont.yfk}}</view>
						</view>
					</view>
				</view>
				<view class="conta">
					<view class="flexcj mb19">
						<view class="f15 fw co23 flex0 ml8">年度申报<text class="coa ml4">/个</text></view>
						<picker mode="date" fields="year"   @change='bindDateChangeb'>
							<view class="f12 coa fw5 flexc">
								<view>{{year}}年度</view>
								<image :src="rimg" class="rimg"></image>
							</view>
						</picker>
					</view>
					<view class="flexc">
						<view class="contn">
							<view class="img">
								<image :src="mcontc" class="imgc"></image>
							</view>
							<view class="ctit">待完成</view>
							<view class="ctxt co1y">{{yearcont.ywsh}}</view>
						</view>
						<view class="line"></view>
						<view class="contn">
							<view class="img">
								<image :src="mcontd" class="imgd"></image>
							</view>
							<view class="ctit">已归档</view>
							<view class="ctxt co1y">{{yearcont.ywwj}}</view>
						</view>
					</view>
				</view>
			</view>
			<view class="mbgbox">
				<view class="flexc mine_list" @click="handleToAddYwsb" v-if="checkPermi(['system:application:add'])&&checkPermi(['system:registered:user'])">
					<view class="limg">
						<image :src="listimga" class="imga"></image>
					</view>
					<view class="tit flex1">业务申报</view>
					<image :src="rimg" class="rimg"></image>
				</view>
				<view class="flexc mine_list" @click="handleToMysb" v-if="checkPermi(['system:application:list'])&&checkPermi(['system:registered:user'])">
					<view class="limg">
						<image :src="listimgb" class="imga"></image>
					</view>
					<view class="tit flex1">我的申报</view>
					<image :src="rimg" class="rimg"></image>
				</view>
				<view class="flexc mine_list" @click="handleToDbsx" v-if="checkPermi(['system:remind:list'])">
					<view class="limg">
						<image :src="listimgc" class="imga"></image>
					</view>
					<view class="tit flex1">待办事项</view>
					<image :src="rimg" class="rimg"></image>
				</view>
				<view class="flexc mine_list" @click="handleToAddQy" v-if="checkPermi(['enterprise:enterprise:list'])">
					<view class="limg">
						<image :src="listimgk" class="imgc"></image>
					</view>
					<view class="tit flex1">添加企业</view>
					<image :src="rimg" class="rimg"></image>
				</view>
				<view class="flexc mine_list" @click="handleToMyzc" v-if="checkPermi(['system:application:list'])&&checkPermi(['system:registered:user'])">
					<view class="limg">
						<image :src="listimgd" class="imga"></image>
					</view>
					<view class="tit flex1">我的暂存</view>
					<image :src="rimg" class="rimg"></image>
				</view>
				<view class="flexc mine_list" @click="handleToHsz" v-if="checkPermi(['system:system:user'])">
					<view class="limg">
						<image :src="listimge" class="imgb"></image>
					</view>
					<view class="tit flex1">回收站</view>
					<image :src="rimg" class="rimg"></image>
				</view>
			</view>
			<view class="mbgbox">
				
				<view class="flexc mine_list" @click="handleToAddNews" v-if="checkPermi(['zxConference:conference:list'])">
					<view class="limg">
						<image :src="listimgf" class="imga"></image>
					</view>
					<view class="tit flex1">台账表</view>
					<image :src="rimg" class="rimg"></image>
				</view>
				<view class="flexc mine_list" @click="handleToDbcy" v-if="checkPermi(['system:document:list'])">
					<view class="limg">
						<image :src="listimgg" class="imga"></image>
					</view>
					<view class="tit flex1">担保材料清单</view>
					<image :src="rimg" class="rimg"></image>
				</view>
			</view>
			<view class="mbgbox">
				<view class="flexc mine_list" @click="handleUpassword">
					<view class="limg">
						<image :src="listimgh" class="imga"></image>
					</view>
					<view class="tit flex1">修改密码</view>
					<image :src="rimg" class="rimg"></image>
				</view>
				<!-- #ifdef APP-PLUS -->
				<view class="flexc mine_list"@click="onlineWgt">
					<view class="limg">
						<image :src="listimgi" class="imga"></image>
					</view>
					<view class="tit flex1">版本号</view>
					 <view  class="txt">{{wgtcode}}</view>
				</view>
				<!-- #endif -->
				
				<view class="flexc mine_list" @click="handleLogout">
					<view class="limg">
						<image :src="listimgj" class="imga"></image>
					</view>
					<view class="tit flex1">退出登录</view>
					<image :src="rimg" class="rimg"></image>
				</view>
			</view>
		</view>
		<view class="ztit">安徽中新云计算有限公司提供支持</view>
		<pop-up :initFace="initFace"  @getClose="getClose" @getXxwsFn="getXxwsFn"></pop-up>
		<footers v-if="isfootflag" :footerindex="footerindex" :isHomeIndex="false"></footers>

	</view>
</template>

<script>
	import storage from '@/utils/storage'
	import footers from '@/components/footer/footer.vue'
	import popUp from "@/components/popup/popup.vue"
	import {getCount} from "@/api/common.js"
	import {updateUserProfile,findVersion} from "@/api/system/user.js"
	import {checkPermi,checkRole} from "@/utils/permission"; // 权限判断函数
	import config from '@/config'
	const baseUrl = config.baseUrl
	export default {
		data() {
			return {
				bgimg: require("@/static/images/bg.png"),
				avatarimg:require("@/static/images/mine/profile.png"),
				noticimg: require("@/static/images/home/notice.png"),
				mconta:require("@/static/images/mine/mconta.png"),
				mcontb:require("@/static/images/mine/mcontb.png"),
				mcontc:require("@/static/images/mine/mcontc.png"),
				mcontd:require("@/static/images/mine/mcontd.png"),
				
				listimga: require('@/static/images/mine/minea.png'),
				listimgb: require('@/static/images/mine/mineb.png'),
				listimgc: require('@/static/images/mine/minec.png'),
				listimgd: require('@/static/images/mine/mined.png'),
				listimge: require('@/static/images/mine/minee.png'),
				listimgf: require('@/static/images/mine/minef.png'),
				listimgg: require('@/static/images/mine/mineg.png'),
				listimgh: require('@/static/images/mine/mineh.png'),
				listimgi: require('@/static/images/mine/minei.png'),
				listimgj: require('@/static/images/mine/minej.png'),
				listimgk: require('@/static/images/mine/minek.png'),
				
				headl:require('@/static/images/mine/headl.png'),
				headr:require('@/static/images/mine/headr.png'),
				wrimg:require("@/static/images/mine/wrimg.png"),
				rimg:require("@/static/images/mine/rimg.png"),
				border: false,
				backgroundColor: 'transparent',

				name: this.$store.state.user.name,
				deptName:this.$store.state.user.deptName,
				// version: getApp().globalData.config.appInfo.version,
				footerindex: 'mine',
				isfootflag: true,
				noticenum: 0,
				deptId: this.$store.state.user.deptId,
				wgtcode: this.$store.state.user.wgtcode,
				platform: 'Android',
				nvaHeight:44,
				beginTime:'2024',
				year:'',//年度
				monthtime:'',//月份
				yearcont:{},
				monthcont:{},
				initFace:'Y',//initFace Y不需要,N需要人脸认证
			}
		},
		components: {
			footers,popUp
		},
		computed: {
			avatar() {
				return this.$store.state.user.avatar
			},
			windowHeight() {
				return uni.getSystemInfoSync().windowHeight - 50
			}
		},
		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(29, 100, 226, ${opacity})`
				this.backgroundColor = color // 更新盒子背景颜色
			} else {
				this.backgroundColor = '#00A9F0'
			}
		}, 
		onLoad() {
			var that=this;
			this.nvaHeight=uni.getSystemInfoSync().statusBarHeight+44;
			if (checkPermi(['system:notice:number'])) {
				// this.getNoticenumber()
			}
			if(checkPermi(['system:statistics:loan'])){
				this.time()
			}
			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
				that.$store.dispatch('SetwgtFn', widgetInfo.version).then(() => {
					that.wgtcode=widgetInfo.version
				})
			});
			// #endif
		},
		mounted() {
			this.getHeightFn()
		}, 
		
		methods: {
			checkPermi,
			checkRole,
			time() {
				var date = new Date();
				var y = date.getFullYear();
				var m = date.getMonth() + 1;
				var yearStr = y + '-' + (m < 10 ? ('0' + m) : m);
				this.year=y;
				this.monthtime=yearStr;
				this.getCount(1)
				this.getCount(2)
			},
			getCount(type){
				var params={
					type:type,
					params:{
						beginTime:type==1?this.year:this.monthtime
					}
				}
				getCount(params).then(res=>{
					if(res.code==200){
						if(type==1){
							this.yearcont=res.data;
						}else{
							this.monthcont=res.data;
						}
					}
				})
			},
			bindDateChangea(e){
				var val=e.detail.value;
				this.monthtime=val;
				this.getCount(2)
			},
			bindDateChangeb(e){
				var val=e.detail.value;
				this.year=val;
				this.getCount(1)
			},
			getNoticeFn(){
				this.$tab.navigateTo("/pages/index/notice")
			},
			getHeightFn(){
				let query = uni.createSelectorQuery().in(this);
				//需要给黄色区域设置一个id标识,在这里是demo
				query.select('.zxbox').boundingClientRect(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();
			},
			getClose(){
				this.initFace='Y';
				this.$store.dispatch('checkInitFace', this.initFace).then(() => {
					
				})
			},
			getXxwsFn(){
				this.$tab.navigateTo(`/work/pages/prove/index`)
			},
			//业务申报
			handleToAddYwsb(){
				if(checkPermi(['system:registered:user'])&&!checkPermi(['system:system:user'])){
					this.$store.dispatch('GetInfo').then(vres => {
						this.initFace=this.$store.state.user.initFace;
						if(this.initFace=='Y'){
							this.$tab.navigateTo("/work/pages/prove/zctype")
						}
					})
				}else{
					this.$tab.navigateTo("/work/pages/prove/zctype")
				}	
				
			},
			//我的申报
			handleToMysb(){
				this.$tab.navigateTo("/work/pages/business/list?from=my&type=0")
			},
			//待办事项
			handleToDbsx(){
				this.$tab.navigateTo("/pages/index/notice?type=dbtz")
			},
			//我的暂存
			handleToMyzc(){
				this.$tab.navigateTo("/work/pages/business/zclist")
			},
			//回收站
			handleToHsz(){
				this.$tab.navigateTo("/work/pages/business/hszlist")
			},
			//担保材料
			handleToDbcy(){
				this.$tab.navigateTo("/work/pages/prove/dbcltips")
			},
			// 修改密码
			handleUpassword(){
				this.$tab.navigateTo(`/pages/mine/pwd/index`)  
			},
			// 账号信息
			handleToInfo() {
				this.$tab.navigateTo('/pages/mine/info/index')
			},
			handleToAddNews(){
				this.$tab.navigateTo('/work/pages/news/add')
			},
			//添加企业
			handleToAddQy(){
				this.$tab.navigateTo('/work/pages/prove/qylist')
			},
			handleToLogin() {
				this.$tab.reLaunch('/pages/login')
			},
			handleToAvatar() {
				this.$tab.navigateTo('/pages/mine/avatar/index')
			},
			handleLogout() {
				this.$modal.confirm('确定注销并退出系统吗?').then(() => {
					this.$store.dispatch('LogOut').then(() => {
						this.$tab.reLaunch('/pages/index')
					})
				})
			},
			onlineWgt() {
				let that = this;
				plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
					that.$store.dispatch('SetwgtFn', widgetInfo.version).then(() => {
						that.wgtcode=widgetInfo.version
					})
					that.comparisonVersionNo(widgetInfo.versionCode);
				});
				// that.comparisonVersionNo()
			},
			comparisonVersionNo(versionCode) {
				let that = this;
				// console.log("aaaaaaa===versionCode", versionCode);
				const parmas = {
					model: that.platform
				}
				findVersion(parmas).then(res => {
					if (res.code == "200") {
						let versionNos = res.data.code;
						console.log(versionNos, 'versionNos')
						// console.log(res.data.path);
						let filePath = res.data.path;
						if (Number(versionNos) > Number(versionCode)) { //服务器返回1更新,0则不更新
							uni.showModal({
								title: '提示',
								content: '发现新版本,是否升级',
								success: function(res) {
									// console.log(widgetInfo.version);
									if (res.confirm) {
										console.log('用户点击确定');
										that.getProperty(filePath);
									} else if (res.cancel) {
										console.log('用户点击取消');
									}
								}
							});
						} else {
							this.$toast('该版本已是最新版')
						}
					}
				}).catch(error => {
					uni.hideLoading()
					console.log(error)
				})
			},
			getProperty(getProperty) {
				// console.log("bbbbbbbbb----------->", getProperty)
				let that = this;
				// 在线升级app/热更新
				that.showwri = true;
				const downloadTask = uni.downloadFile({ //下载文件
					url: baseUrl + getProperty,
					success: (downloadResult) => {
						// console.log(downloadResult);
						if (downloadResult.statusCode == 200) {
							// 更新升级
							plus.runtime.install(downloadResult.tempFilePath, {
								force: true
							}, function() {
								// console.log('install success...');
								that.showwri = false;
								plus.nativeUI.alert("应用资源更新完成!", function() {
									plus.runtime.restart();
								});
							}, function(e) {
								that.showwri = false;
								plus.nativeUI.alert("更新失败,请稍后再试");
							});
						}
					}
				});
				downloadTask.onProgressUpdate((res) => { //下载文件的进度
					that.totalBytesWritten = res.totalBytesWritten; //当前下载大小
					that.progress = res.progress; //当前下载比例
					that.totalBytesExpectedToWrite = res.totalBytesExpectedToWrite; //
				});
			},
			
			getNoticenumber() {
				var params = {
					deptId: this.deptId
				}
				getNoticenumber(params).then(res => {
					if (res.code == 200) {
						this.noticenum = Number(res.data)
					} else {
						this.$toast(res.msg)
					}
				})
			},
		}
	}
</script>

<style lang="scss">
page{background-color: #f6f6f6;}
.navbox{position: fixed;left: 0;right: 0;top: 0;z-index: 4;
	.topl{width: 274rpx;height: 50rpx;margin-left: 14rpx;}
	.topr{width: 36rpx;height: 36rpx;position: relative;margin-right: 10rpx;
		image{width: 100%;height: 100%;}
		// .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: 680rpx;}
	.mbox{margin-top: -540rpx;padding: 0 36rpx;z-index: 1;position: relative;
		.infobox{margin-bottom: 60rpx;
			.limg{width: 140rpx;height: 140rpx;flex: 0 0 auto;margin-right: 26rpx;border-radius: 50%;}
			.cbox{flex: 1;z-index: 1;
				image{width: 32rpx;height: 38rpx;}
				.tit{font-weight: bold;font-size: 40rpx;color: #ffffff;margin-bottom: 14rpx;}
				.txt{font-weight: bold;font-size: 24rpx;background-color: #2973C7;color: #FFFFFF;height: 38rpx;line-height: 38rpx;margin: 0 -2rpx;padding:0 2rpx;}
			}
			.rimg{width: 12rpx;height: 20rpx;flex: 0 0 auto;margin-left: 20rpx;}
		}
		.conts{margin-bottom: 24rpx;background: #FFFFFF;box-shadow: 0px 0px 10rpx 0px rgba(216,216,216,0.4);border-radius: 20rpx;
			padding: 0 20rpx;box-sizing: border-box;
			.conta{border-bottom: 2rpx dashed #E6E6E6;padding: 38rpx 0 44rpx;
				.rimg{width: 16rpx;height: 22rpx;margin-left: 22rpx;flex: 0 0 auto;}
				.contn{
					display: flex;align-items: center;flex: 0 0 auto;width: 286rpx;
					.img{width: 42rpx;height: 40rpx;display: flex;align-items: center;justify-content: center;margin-right: 18rpx;flex: 0 0 auto;
						.imga{width: 42rpx;height: 40rpx;}
						.imgb{width: 30rpx;height: 40rpx;}
						.imgc{width: 38rpx;height: 40rpx;}
						.imgd{width: 34rpx;height: 40rpx;}
					}
					.ctit{font-weight: 500;font-size: 26rpx;color: #222327;flex: 0 0 auto;}
					.ctxt{flex: 1;text-align: right;font-weight: bold;font-size: 32rpx;word-break: break-all;}
				}
				.line{width: 2rpx;height: 28rpx;background: #E6E6E6;margin: 0 32rpx;flex: 0 0 auto;}
			}
		}
		.mbgbox{width: 100%;background: #FFFFFF;border-radius: 10rpx;margin-bottom: 24rpx;
			.mine_list{
				padding: 34rpx 22rpx;
				.limg{flex: 0 0 auto;width: 42rpx;height: 42rpx;margin-right: 26rpx;display: flex;align-items: center;justify-content: center;
					.imga{width: 40rpx;height: 40rpx;}
					.imgb{width: 38rpx;height: 40rpx;}
					.imgc{width: 42rpx;height: 42rpx;}
				}
				.tit{font-weight: bold;font-size: 30rpx;color: #222327;}
				.txt{font-weight: 500;font-size: 30rpx;color: #666666;margin-left: 20rpx;flex: 0 0 auto;}
				.rimg{width: 16rpx;height: 22rpx;margin-left: 20rpx;flex: 0 0 auto;}
			}
		}
	}
}

.ztit{font-size: 24rpx;color:#c6c6c9;text-align: center;flex:0 0 auto;margin-bottom: 28rpx;margin-top: 40rpx;}

</style>