<template>
	<view class="personal-page">
		<!-- <u-navbar :is-back="false" title="个人中心" :title-color="'#FFFFFF'" :background="{ background: background }"></u-navbar> -->
		<view class="navBarBox">
			<view class="statusBar" :style="{ paddingTop: statusBarHeight + 'px' }"></view>
			<view class="navBar">
				<view class="navBar-title">个人中心</view>
			</view>
		</view>
		<view class="personal-place"></view>
		<view class="personal-info">
			<view class="personal-info-left">
				<view class="personal-name">
					<span>{{userinfo.nickName || '微信用户'}}</span>
					<span class="personal-phone">/{{userinfo.phonenumber || '-'}}</span>
				</view>
				<view class="personal-role">
					{{userinfo.roles[0].roleName || '-'}}
				</view>
			</view>
			<view class="personal-info-right">
				{{usernameFirst || '微'}}
			</view>
		</view>

		<view class="toPage">
			<view class="toPage-items" @click="toPage(0)">
				<u-icon size="40" name="order"></u-icon>
				<view class="toPage-title">
					工单上报
				</view>
				<view class="toPage-next">
					{{esOrder + ' >'}}
				</view>
			</view>
			<view class="toPage-items" @click="toPage(1)">
				<u-icon size="40" name="order"></u-icon>
				<view class="toPage-title">
					参与工单
				</view>
				<view class="toPage-next">
					{{processRecords + ' >'}}
				</view>
			</view>
		</view>
	</view> 
</template>

<script>
	import {myPrimary} from '@/uni.scss'
	export default {
		data() {
			return {
				dataList: [
					{
					  title: '工单上报',
					  path: '/pages/ucenter/mineNotes',
					  type: 0,
					},
					{
					  title: '参与工单',
					  path: '/pages/ucenter/mineNotes',
					  type: 1,
					}
				],
				dataInfo: {},
				background: null,
				userinfo: {},
				//上报工单
				esOrder: 0,
				//参与工单
				processRecords: 0,
				// 状态栏高度
				statusBarHeight: 0,
				// 导航栏高度
				navBarHeight: 82+11,
			}
		},
		computed: {
			usernameFirst: {
				get() {
			        let name = this.userinfo.nickName;
			        let first = name?.charAt(0);
			        if (new RegExp("[\u4E00-\u9FA5]+").test(first)) {
						return first;
			        } else if (new RegExp("[A-Za-z]+").test(first)) {
						return first?.toUpperCase();
			        }
			    },
			},
		},
		onLoad() {
			this.background = myPrimary;
			this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
			let systemInfoSync = uni.getSystemInfoSync();
			this.screenHeight = systemInfoSync.screenHeight - 500;
		},
		onShow() {
			let userinfo = uni.getStorageSync('user')
			if(userinfo) {
				this.userinfo = JSON.parse(userinfo)
			}
			this.getMyRecordData();
		},
		methods: {
			//跳转详情
			toPage(type) {
				let token = uni.getStorageSync('token')
				if(!token) {
					uni.navigateTo({
						url: '/pages/public/login'
					})
				} else {
					uni.navigateTo({
						url: '/pages/ucenter/mineNotes?type=' + type
					})
				}
			},
			//获取我的记录数据
			getMyRecordData() {
				const _that = this;
				_that.dataInfo = {};
				uni.showLoading({
					title: '搜索中...',
				})
				_that.$http.getMyRecord('').then(res => {
					uni.hideLoading();
					if(res.code == 200) {
						let {esOrder, processRecords} = res.data
						_that.esOrder = esOrder;
						_that.processRecords = processRecords;
					} else {
						// _that.$utils.msg(res.msg);
					}
				})
			}
		}
	}
</script>

<style>
  page {
    height: 100%;
  }
  element>.u-cell {
    padding: 18rpx 40rpx;
  }
</style>

<style lang="scss" scoped>
	.personal-page {
		background: linear-gradient(180deg, #9CC1FA 2%, #78B1FE 15%, #E5EEFD 76%, #F7F8FA 100%);
		height: 100vh;
		position: relative;
		box-sizing: border-box;
		padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
		padding-top: 15rpx;
		.personal-place {
			height: calc(200rpx + env(safe-area-inset-top));
		}
		.personal-info {
			height: 200rpx;
			display: flex;
			padding: 0 30rpx;
			.personal-info-left {
				width: 80%;
				.personal-name {
					font-size: 40rpx;
					font-family: PingFang SC-Semibold, PingFang SC;
					font-weight: 600;
					color: #1D2129;
					line-height: 50rpx;
					.personal-phone {
						font-size: 30rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						color: #4E5969;
						line-height: 50px;
					}
				}
				.personal-role {
					font-size: 30rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #4E5969;
					line-height: 50rpx;
				}
			}
			.personal-info-right {
				height: 128rpx;
				width: 128rpx;
				line-height: 128rpx;
				text-align: center;
				border-radius: 50%;
				background: #3aabf6;
				color: #FFFFFF;
				font-size: 50rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 600;
				margin-top: 20rpx;
			}
		}
		.toPage {
			height: auto;
			background: #fff;
			margin: 40rpx 30rpx 30rpx;
			border-radius: 16rpx;
			.toPage-items {
				height: 120rpx;
				line-height: 120rpx;
				display: flex;
				padding: 0 30rpx;
				position: relative;
				.toPage-title {
					font-size: 30rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #1D2129;
					line-height: 120rpx;
					margin-left: 10rpx;
				}
				.toPage-next {
					line-height: 120rpx;
					font-size: 30rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #1D2129;
					position: absolute;
					right: 30rpx;
				}
			}
		}
		.navBarBox{position: fixed;}
		.navBarBox .statusBar {}
		.navBarBox .navBar {
			padding: 3rpx 50rpx;
			padding-bottom: 8rpx;
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			position: fixed;
			.navBar-title {
				height: 24px;
				font-size: 17px;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #000000;
				line-height: 24px;
			}
		}
		.navBarBox .navBar .logo {
			width: 82rpx;
			height: 82rpx;
			margin-right: 10rpx;
		}
		.grace-loading {
			position: relative;
			text-align: center;
			padding-top: 100rpx;
			height: 300rpx;
			color: #979797;
		}
	}
</style>