<template>
	<view class="my-page">

		<view class="card-common user-info">
			<!--			<image-->
			<!--				class="user-edit-icon"-->
			<!--				@click="linkToUserInfo"-->
			<!--				src="/static/ic_edit@2x.png"-->
			<!--			/>-->
			<view class="user">
				<view class="user-avatar">
					<!--          <image-->
					<!--            src="/static/img_person@2x.png"-->
					<!--          />-->
					<u-avatar :text="userInfo.NAME.slice(1)" fontSize="20" size="64" randomBgColor></u-avatar>
				</view>
				<view class="info">
					<view class="user-name">{{`${userInfo.NAME}（${userInfo.CODE}）`}}</view>
					<!-- <view class="user-phone">{{userInfo.PHONE}}</view> -->
					<view class="dep-num">
						<text class="dep-num-name" v-if="userInfo.Nav_Department">{{userInfo.Nav_Department.NAME}}</text>
						<text v-if="userInfo.PHONE">{{userInfo.PHONE}}</text>
						<!-- <text>|</text>
						<text>工号:{{userInfo.CODE}}</text> -->
					</view>
					<!--					#ifdef APP-PLUS-->
					<view class="dep-num">
						<text class="dep-num-name">版本：</text>
						<text>{{version}}</text>
					</view>
					<!--					#endif-->
				</view>
			</view>
			<view class="message">
				<!-- <view class="msg">
          <view class="num">10</view>
          <view class="text">待办任务</view>
        </view>
        <view class="msg last">
          <view class="num">10</view>
          <view class="text">未读消息</view>
        </view> -->
				<!-- <view class="msg last">
          <view class="num">10</view>
          <view class="text">其它任务</view>
        </view> -->
			</view>
		</view>
		<view class="menu-list">
			<view class="menu-list-ab">
				<view class="row" @click="linkToUserInfo">
					<view class="left">
						<i class="iconfont icon-bianji5" style="font-size: 20px;color: #2979ff;margin-right: 15px;"></i>
						<!-- <image src="/static/ic_edit@2x.png" /> -->
						<text>我的资料</text>
					</view>
					<view class="right">
						<image src="/static/ic_more@2x.png" />
					</view>
				</view>
				<view class="row" @click="linkToFeedBack">
					<view class="left">
						<i class="iconfont icon-yijianfankui1" style="font-size: 20px;color: #2979ff;margin-right: 15px;"></i>
						<!-- <image src="/static/icon_feedback@2x.png" /> -->
						<text>意见反馈</text>
					</view>
					<view class="right">
						<image src="/static/ic_more@2x.png" />
					</view>
				</view>
				<view class="row" @click="linkToEditPassword">
					<view class="left">
						<i class="iconfont icon-xiugaimima1" style="font-size: 20px;color: #2979ff;margin-right: 15px;"></i>
						<!-- <image src="/static/ic_key@2x.png" /> -->
						<text>修改密码</text>
					</view>
					<view class="right">
						<image src="/static/ic_more@2x.png" />
					</view>
				</view>
				<!-- #ifdef APP-PLUS -->
				<view class="row" @click="linkToUpdate">
					<view class="left">
						<i class="iconfont icon-jianchagengxin" style="font-size: 20px;color: #2979ff;margin-right: 15px;"></i>
						<!-- <image src="/static/ic_key@2x.png" /> -->
						<text>立即更新</text>
						<u-badge :isDot="true" type="error" style="margin-left: 5px;" v-if="updateNow == true"></u-badge>
					</view>
					<view class="right">
						<!-- <image src="/static/ic_more@2x.png" /> -->
						<!-- <u-badge :isDot="true" type="error"></u-badge> -->
						<text style="font-size: 12px;color:#909399 ;" v-if="updateNow == true">检测到有新版本！</text>
						<image src="/static/ic_more@2x.png" />
						<!-- <view style="width: 20px;height: 20px;background-color: #e45656;border-radius: 20px;"></view> -->
					</view>
				</view>
				<!-- #endif -->
				<view class="row" @click="handleLogout">
					<view class="left">
						<i class="iconfont icon-guanji" style="font-size: 20px;color: #2979ff;margin-right: 15px;"></i>
						<!-- <image src="/static/icon_logout@2x.png" /> -->
						<text>退出登录</text>
					</view>
					<!-- <view class="right">
					<image src="/static/ic_more@2x.png" />
				</view> -->
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		getTasksUpdate
	} from '../.././services/app.js'
	import {
		initFilter
	} from '../.././utils/common.js'
	import config from '../.././config/common.js'
	export default {
		data() {
			return {
				version: '',
				userInfo: {},
				updateNow: false,
				updateData: '',
			}
		},
		onShow() {
			const appInfoData = uni.getStorageSync('appInfo')
			const {
				User
			} = appInfoData
			this.userInfo = User

			// #ifdef APP-PLUS
			plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
				// 增量版本： widgetInfo.version
				// 全量版本：plus.runtime.version
				this.version = widgetInfo.version
			})
			const orgId = uni.getStorageSync('orgId')
			const json = initFilter(orgId)
			getTasksUpdate(json).then(res => {
				if (res.Data.AppVersion) {
					if (res.Data.AppVersion.Code !== this.version) {
						this.updateNow = true
						this.updateData = res.Data.AppVersion
					}

				}
			})
			// #endif
		},
		methods: {
			// #ifdef APP-PLUS
			linkToUpdate() {
				if (this.updateNow == false) {
					uni.$showErrorInfo('当前已是最新版，暂无更新', '温馨提示')
				} else {
					if (this.updateData.Upgrade === 0) {
						uni.showLoading({
							title: "下载资源包",
							mask: true,
						})
						uni.downloadFile({ // 下载资源包
							url: config.uni_app_web_source_url +
								this.updateData.Url,
							success: (downloadResult) => {
								uni.hideLoading()
								if (downloadResult.statusCode ===
									200) {
									plus.runtime.install(downloadResult
										.tempFilePath, { // 安装资源包
											force: false
										},
										function() {
											console.log(
												'install success...'
											);
											plus.runtime
												.restart(); // 重启APP
										},
										function(e) {
											console.error(e,
												'install fail...'
											);
										})
								}
							}
						})
					} else if (this.updateData.Upgrade === 1) {
						var appurl = ''
						if (plus.os.name === 'Android') {
							appurl = config.uni_app_web_source_url + this.updateData
								.Url;
						} else {
							// 其它平台
							// appurl = versionInfo.pathIos;
						}
						plus.runtime.openURL(appurl); // 跳转应用发布平台
					}
				}


			},
			// #endif
			handleLogout() {
				uni.removeStorageSync('accessToken')
				uni.removeStorageSync('refreshToken')
				uni.removeStorageSync('orgId')
				uni.removeStorageSync('Tenant')
				uni.removeStorageSync('appInfo')
				uni.removeStorageSync('MineType')
				uni.redirectTo({
					url: '/pages/login/index'
				})
			},
			linkToEditPassword() {
				uni.navigateTo({
					url: '/pages/my/subPages/editPassword'
				})
			},
			linkToUserInfo() {
				uni.navigateTo({
					url: '/pages/my/subPages/userInfo1'
				})
			},
			linkToFeedBack() {
				uni.navigateTo({
					url: '/pages/my/subPages/feedBack'
				})
			}
		}
	}
</script>

<style>
	.my-page {
		/* padding: 16px; */
		background: linear-gradient(360deg, #ffffff, #77b0c8);
	}

	.card-common {
		border-radius: 8px;
		/* border: 1px solid rgba(72, 160, 247, 1); */
		box-shadow: 0 0px 4px 0 rgba(0, 0, 0, 0.1);
		margin-bottom: 16px;
		overflow: hidden;
	}

	.user-info {
		/* padding: 24px; */
		box-sizing: border-box;
		position: relative;
		/* background: url('../../static/restaurant.webp'); */
		opacity: 0.8;
		padding: 64px 34px 84px 34px;
		/* padding-bottom: 84px; */
		/* border-radius:0px 0px 18px 18px; */
	}

	.user-info .user {
		display: flex;
		margin-bottom: 24px;
		justify-content: center;
	}

	.user-info .user .info {
		flex: 1;
		padding-left: 18px;
		display: flex;
		flex-direction: column;
		justify-content: center;
		/* align-items: center; */
		font-size: 12px;
		color: rgba(51, 51, 51, 1);
	}

	.user-info .user .info .user-name {
		font-size: 18px;
		font-weight: 500;
		line-height: 24px;
		margin-bottom: 8px;
		color: #000000;
		display: flex;
		align-items: center;
		/* justify-content: center; */
	}


	.user-info .user .info .user-phone {
		font-weight: 400;
		line-height: 16px;
	}

	.user-info .user .info .dep-num {
		line-height: 16px;
		font-size: 12px;
		color: #666;
	}

	.dep-num-name {
		margin-right: 10px;
	}

	.user-info .user-edit-icon {
		position: absolute;
		width: 16px;
		height: 16px;
		top: 24px;
		right: 24px;
	}

	/*.user-info .user-avatar image {*/
	/*  width: 64px;*/
	/*  height: 64px;*/
	/*  border-radius: 50%;*/
	/*  overflow: hidden;*/
	/*}*/
	.user-info .user-avatar {
		display: flex;
		align-items: center;
		justify-content: center;
		/* border: #fff 1px solid; */
		border-radius: 64px;
		height: 100%;
		box-shadow: 0px 0px 10px 5px #fff;
	}

	.user-info .message {
		display: flex;
		justify-content: space-between;
	}

	.user-info .message .msg {
		border-right: 1px solid #C9C9C9;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		font-size: 16px;
		color: #333;
		width: 50%;
		font-weight: 500;
		line-height: 22px;
	}

	.user-info .message .text {
		font-size: 14px;
		font-weight: 400;
		line-height: 20px;
	}

	.user-info .message .last {
		border-right: none;
	}

	.menu-list {
		padding: 34px 0;
		border: none;
		width: 100%;
		/* transform: translate(1%,0%); */
		background-color: #fff;
		border-radius: 40px;
		position: absolute;
		top: 180px;
		box-shadow: 0 0 0 1 #333;
		/* margin: 20px; */
	}

	.menu-list-ab {
		margin: 0px 36px;
	}

	.menu-list .row {
		display: flex;
		height: 20px;
		justify-content: space-between;
		align-items: center;
		font-size: 16px;
		color: #333;
		margin-bottom: 28px;
	}

	.menu-list .row .left {
		display: flex;
		align-items: center;
	}

	.menu-list .row .left image {
		width: 20px;
		height: 20px;
		margin-right: 15px;
	}

	.menu-list .row .right image {
		width: 5px;
		height: 10px;
	}
</style>