<template>
	<view class="" style="width: 100%;">
		<view class="header-bg ">
			<view class=" flew flew-start flew-align-center margin0-auto" style="width: 85%;">
				<image class="border-radius-50 headImage" :src="userInfo.avatar || '../../static/image/pic_mine_hp.png'" mode=""></image>
				<view class="" style="margin-left: 25rpx;">
					<text class="txt">{{userInfo.userName||''}}</text>
					<view class="man-bg" v-if="userInfo.dept.deptName">
						{{userInfo.dept.deptName||''}}
					</view>
				</view>
			</view>
			<view style="margin-top: 80rpx;">
				<!-- 疫苗 -->
				<uni-card  extra="额外信息" v-for="(item,index) in card_listpeo" :key="index" :isShadow="true" @click="goNavs(index)">
				    <view class="flew flew-between flew-align-center margin0-auto" style="width: 95%;">
				    	<view class="flew flew-start flew-align-center" style="width:80%;">
				    		<image class="card-image" :src="item.url" mode=""></image>
							<view class="" style="margin-left: 20rpx;">
								<text class="txt2">{{item.txt2}}</text>
								<view class="txt3" v-if="index !== 1">
									{{item.txt3}}
								</view>
								<view class="txt3" v-else>
									{{getTimeNow()}}
								</view>
							</view>
				    	</view>
						<view class="">
							<image style="width: 22rpx;height: 38rpx;" src="../../static/image/icon_mine_listenter.png" mode=""></image>
						</view>
				    </view>
				</uni-card>
				<!-- 人口 -->
			</view>
		</view>
		<u-toast ref="uToast" />
		
		<uni-popup ref="logoutPopup" type="center">
			<uni-popup-dialog-logout type="info" title="退出登录" content="是否确认退出当前账号？" @confirm="logoutConfirm" ></uni-popup-dialog-logout>
		</uni-popup>
	</view>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	import uniPopupDialogLogout from '@/components/uni-popup/uni-popup-dialog-logout.vue'
	import hostUrl from "@/util/url";
	let {host, imgDomain} = hostUrl
	export default { 
		components: {
			uniPopup,
			uniPopupDialogLogout
		},
		data() {
			return {
				userInfo: {
					dept:{
						deptName:'',
					}
				},
				// 疫苗
				card_list: [
					{url:'../../static/image/icon_mine_ymxx.png',txt2: '疫苗信息',txt3:'查看/修改我提交的疫苗信息'},
					{url:'../../static/image/icon_mine_jzqk.png',txt2: '疫苗接种情况',txt3:'查看/修改人员接种疫苗信息'},
					{url:'../../static/image/icon_mine_jztj.png',txt2: '疫苗接种情况统计表',txt3:'截止至 2021年9月6日10时'},
					{url:'../../static/image/scan.png',txt2: '扫码登录',txt3:'扫描二维码一键登录'},
					{url:'../../static/image/logout.png',txt2: '退出登录',txt3:'退出当前账号登录状态'}
				],
				// 人口
				card_listpeo: [
					{url:'../../static/image/icon_mine_ymxx.png',txt2: '人口信息',txt3:'查看/修改我提交的人口信息'},
					{url:'../../static/image/icon_mine_jztj.png',txt2: '常住人口统计',txt3:''},
					{url:'../../static/image/scan.png',txt2: '扫码登录',txt3:'扫描二维码一键登录'},
					{url:'../../static/image/logout.png',txt2: '退出登录',txt3:'退出当前账号登录状态'}
				]
			}
		},
		onShow() {
			
		},
		mounted() {
			// console.log('mounted')
			this.getUserInfo()
		},
		methods:{
			checkLogin() {
				var token = uni.getStorageSync('token')
				// var token = "df057579-73c8-4bdd-8312-f64db8efd699"
				if (token == undefined || token == '') {
					uni.navigateTo({
						url: '/pages/login/login'
					})
					return false
				}
				return true
			},
			getUserInfo() {
				this.$http.get('system/user/getInfo').then(res=>{
					// console.log(JSON.stringify(res))
					if(res.code == 200 ) {
						this.userInfo = res.user
						
						// 手机号是否展示
						// var d=['city01','queryApp','queryApp','city02']
						var roles=res.roles.some((ite,idx)=>{
							if(ite=='queryApp'){
								return true
							}
						})
						uni.setStorageSync('roles', roles)   
						
						// var regexp = new RegExp("((http|ftp|https)://)(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,4})*/?", "g");
						// this.userInfo.avatar = this.userInfo.avatar.replace(regexp, imgDomain + '/');
						// console.log('avatar ' + this.userInfo.avatar)
						// console.log('hone ' + this.userInfo.phonenumber)
						uni.setStorageSync('phone', this.userInfo.phonenumber)   
					} 
				})
			},
			logoutConfirm(done) {
				done()
				uni.clearStorage()
				uni.navigateTo({
					url: '/pages/login/login'
				})
			},
			/* 获取当前时间 */
			getTimeNow () {
				let re = this.h_util.getDateTime('yyyy年MM月dd日hh时',new Date())
				return re
			},
			/* 跳转路由 */
			goNav(index) {
				if(index == 0) {
					uni.navigateTo({
						url:'/home/pages/recordthree/recordthree'
					})
				}else if (index == 1) {
					uni.navigateTo({
						url:'/home/pages/recordthree/recordthree'
					})
				}else if (index == 2) {
					this.$refs.uToast.show({
						title: '该功能暂未开放',
						type: 'error'
					})
				}else if (index == 3) {
					if (!this.checkLogin()) {
						return
					}
					uni.navigateTo({
						url:'/add/pages/addvacfrom/scan'
					})
				}else if (index == 4) {
					this.$refs.logoutPopup.open()
				}else{
					this.$refs.uToast.show({
						title: '该功能暂未开放',
						type: 'error'
					})
				}
			},
			goNavs(index){
				if(index == 0) {
					uni.navigateTo({
						url:'/home/pages/recordthree/recordpeople'
					})
				}else if (index == 1) {
					uni.navigateTo({
						url:'/pages/home/resident'
					})
				}else if (index == 2) {
					if (!this.checkLogin()) {
						return
					}
					uni.navigateTo({
						url:'/add/pages/addvacfrom/scan'
					})
				}else if(index == 3){
					this.$refs.logoutPopup.open()
				}else{
					this.$refs.uToast.show({
						title: '该功能暂未开放',
						type: 'error'
					})
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.header-bg {
		background-image: url(data:image/png;base64,[encoded data, 165428 characters]);
		background-size: 100% 300upx;
		width: 100%;
		height: 300rpx;
	}
	.headImage {
		width: 150rpx;
		height: 150rpx;
	}
	.txt{
		font-size: 38rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #FFFFFF;
		line-height: 18rpx;
	}
	.man-bg{
		background-image: url(../../static/image/pic_mine_bq_bg.png);
		background-size: 100% 70upx;
		width: 100%;
		margin-top: 10rpx;
		padding:5rpx 10rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #3196E2;
		line-height: 18px
	}
	.card-image{
		width:80rpx;
		height:80upx;;
	}
	.txt2{
		font-size: 34rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #343434;
		line-height: 18px;
	}
	.txt3{
		margin-top: 15rpx;
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 400;
		color: #AAAAAA;
		line-height: 18px;
	}
</style>
