<template>
  <view class="mine-container">
	<view class="flex1">
	  <uni-nav-bar background-color='transparent' statusBar='true' :border='border'>
		  <block slot="right" v-if="checkPermi(['system:notice:list'])"> 
			<view class="min_top" @click="getMessage">
				<image :src="noticimg"></image>
				<view v-if="noticenum">
					<block v-if="noticenum>99">99+</block>
					<block v-else>{{noticenum}}</block>
				</view>
			</view>
		  </block>
		 
	  </uni-nav-bar>
    <!--顶部个人信息栏-->
	<view class="min-topa" @click="handleToInfo">
		<view class="min-topat fw f22 cof mb12">{{name}}</view>
		<view class="f15 cof5">查看账号信息/退出登录</view>
	</view>
	
	<view >
		<view class="flexc mine_list" @click="handleTozf" v-if="checkPermi(['fgw:xmsb:list'])">
		  <image :src="listimga" class="limg"></image>
		  <view class="f17 c34 flex1">政府项目</view>
		  <image :src="rimg" class="rimg"></image>
		</view>
	  <view class="flexc mine_list" @click="handleToZsFn" v-if="checkPermi(['projectV2:sbbzb:list'])">
	    <image :src="listimgb" class="limg"></image>
	    <view class="f17 c34 flex1">招商项目</view>
	    <image :src="rimg" class="rimg"></image>
	  </view>
	  <view class="flexc mine_list" @click="handleToWtFn" v-if="checkPermi(['fgw:xmsb:list'])">
	    <image :src="listimgc" class="limg"></image>
	    <view class="f17 c34 flex1">问题项目</view>
	    <image :src="rimg" class="rimg"></image>
	  </view>
	 <!-- <view class="flexc mine_list">
	   <image :src="listimgd" class="limg"></image>
	   <view class="f17 c34 flex1">项目预警</view>
	    <image :src="rimg" class="rimg"></image>
	  </view> -->
	  <view class="flexc mine_list" @click="handleTold" v-if="checkPermi(['fgw:xmsb:ldps:list'])">
	   <image :src="listimge" class="limg"></image>
	   <view class="f17 c34 flex1">领导批示</view>
	    <image :src="rimg" class="rimg"></image>
	  </view>
	  <view class="flexc mine_list" @click="handleToPwd">
	    <image :src="listimgf" class="limg"></image>
	    <view class="f17 c34 flex1">修改密码</view>
	    <image :src="rimg" class="rimg"></image>
	  </view>
	<!-- #ifdef APP -->
	<view class="flexc mine_list" @click="onlineWgt">
	  <image :src="nlistimgh" class="limg"></image>
	  <view class="f17 c34 flex1">版本更新</view>
	  <view  class="f15 c34 mlr8">{{wgtcode}}</view>
	  <image :src="rimg" class="rimg"></image>
	</view>
	<!-- #endif -->
	  
	</view>
	</view>
	<view class="ztit">安徽中新云计算有限公司提供支持</view>
	<view class="flex0">
	<footers v-if="isfootflag" :footlist="footlist" :footerindex="footerindex" :color_checked="color_checked" :color_nochecked="color_nochecked" :isHomeIndex="false"></footers>	
	</view>
	
  </view>
</template>

<script>
  import storage from '@/utils/storage'
  import footers from '@/components/footer/footer.vue'
  import {getNoticenumber} from "@/api/work/index.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 {
		 noticimg:require("@/static/images/mine/notice.png") ,
		 listimga:require('@/static/images/new/index/minea.png'),
		 listimgb:require('@/static/images/new/index/mineb.png'),
		 listimgc:require('@/static/images/new/index/minec.png'),
		 listimgd:require('@/static/images/new/index/mined.png'),
		 listimge:require('@/static/images/new/index/minee.png'),
		 listimgf:require('@/static/images/new/index/minef.png'),
		 nlistimgh:require('@/static/images/mine/nmineh.png'),
		rimg:require("@/static/images/mine/rimg.png"),
		border:false,
		  
        name: this.$store.state.user.name,
        version: getApp().globalData.config.appInfo.version,
		footlist:[
			{module:'zdhome',title:'首页',icon_checked:require('@/static/images/new/tabbar/home_.png'),icon_nochecked:require('@/static/images/new/tabbar/home.png')},
			{module:'zdcount',title:'统计分析',icon_checked:require('@/static/images/new/tabbar/tong_.png'),icon_nochecked:require('@/static/images/new/tabbar/tong.png')},
			{module:'zdmine',title:'我的',icon_checked:require('@/static/images/new/tabbar/mine_.png'),icon_nochecked:require('@/static/images/new/tabbar/mine.png')},
			],
		 footerindex:'zdmine',
		 showfooter: 0,
		 isfootflag:true,
		 color_checked :'FA5F03',
		 color_nochecked :'666666',
		 noticenum:0,
		 deptId:this.$store.state.user.deptId,
		 wgtcode:this.$store.state.user.wgtcode,
		 platform:'Android'
      }
    },
	components:{footers},
    computed: {
      avatar() {
        return this.$store.state.user.avatar
      },
      windowHeight() {
        return uni.getSystemInfoSync().windowHeight - 50
      }
    },
	onLoad() {
		if(checkPermi(['system:notice:number'])){
			this.getNoticenumber()
		}
	},
    methods: {
		checkPermi, checkRole,
	getNoticenumber(){
		var params={
			deptId:this.deptId
		}
		getNoticenumber(params).then(res=>{
			if(res.code==200){
				this.noticenum=Number(res.data)
			}else{
				this.$toast(res.msg)
			}
		})
	},
	onlineWgt() {
		let that = this;
		plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
			that.$store.dispatch('SetwgtFn',widgetInfo.version).then(()=>{
			})
			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 (versionNos != 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; //
		});
	},
	// 项目进展
		handleToAdd(){
			this.$tab.navigateTo('/pages/work/addclues')
			// this.$tab.navigateTo('/pages/work/addcluelist') 
		},
		// 账号信息
      handleToInfo() {
        this.$tab.navigateTo('/pages/mine/info/index')
      },
	  // 修改密码
	  handleToPwd(){
		this.$tab.navigateTo('/pages/mine/pwd/index')  
	  },
	  //消息
	  getMessage(){
		  if(checkPermi(['system:notice:list'])){
		  	this.$tab.navigateTo('/pages/work/message')
		  } 
	  },
	  //审核进度pages/work/shprogres
	  // 政府项目
	  handleTozf(){
	  	 this.$tab.navigateTo('/pages/zdpages/work/zfitems?idx=0')
	  },
	  // 招商项目
	  handleToZsFn(){
	  	 this.$tab.navigateTo('/pages/work/allitems?idx=0')
	  },
	  //问题项目
	  handleToWtFn(){
	  	this.$tab.navigateTo('/pages/zdpages/work/wtitems')
	  },
	  handleTold(){
		  this.$tab.navigateTo('/pages/zdpages/work/lditems')
	  },
	  
      // handleToSetting() {
      //   this.$tab.navigateTo('/pages/mine/setting/index')
      // },
      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')
          })
        })
      },
      handleHelp() {
        this.$tab.navigateTo('/pages/mine/help/index')
      },
      handleAbout() {
        this.$tab.navigateTo('/pages/mine/about/index')
      },
      handleJiaoLiuQun() {
        this.$toast('QQ群：133713780')
      },
      handleBuilding() {
        this.$toast('模块建设中~')
      }
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #FFFFFF;
  }
.min_top{position: relative;width: 44rpx;height: 44rpx;display: flex;align-items: center;justify-content: center;margin-right: 32rpx;
	image{width: 38rpx;height: 40rpx;}
	view{position: absolute;background: #ffffff;box-shadow: 0px 2rpx 6rpx 0px rgba(198,78,0,0.49);border-radius: 10rpx;color: #FF0000;font-size: 18rpx;right: -50%;top: -12rpx;border-radius: 50%;min-width: 40rpx;height: 40rpx;text-align: center;padding: 0 4rpx;box-sizing: border-box;line-height: 40rpx;}
}
.min-topa{padding: 64rpx 48rpx 108rpx;}
.min-topat{font-weight: bold;color: #FFFFFF;}
.mine_list{padding: 30rpx 48rpx;}
.limg{width: 56rpx;height: 56rpx;margin-right: 30rpx;flex: 0 0 auto;}
.rimg{width: 14rpx;height: 28rpx;flex: 0 0 auto;}

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





  .mine-container {
    width: 100%;
    height: 100vh;
	display: flex;flex-direction: column;
	background: url('~@/static/images/mine/minebg.png') top center no-repeat;background-size: 100% 360rpx;

    .header-section {
      padding: 15px 15px 45px 15px;
      background-color: #3c96f3;
      color: white;

      .login-tip {
        font-size: 18px;
        margin-left: 10px;
      }

      .cu-avatar {
        border: 2px solid #eaeaea;

        .icon {
          font-size: 40px;
        }
      }

      .user-info {
        margin-left: 15px;

        .u_title {
          font-size: 18px;
          line-height: 30px;
        }
      }
    }

    .content-section {
      position: relative;
      top: -50px;

      .mine-actions {
        margin: 15px 15px;
        padding: 20px 0px;
        border-radius: 8px;
        background-color: white;

        .action-item {
          .icon {
            font-size: 28px;
          }

          .text {
            display: block;
            font-size: 13px;
            margin: 8px 0px;
          }
        }
      }
    }
  }
</style>
