<template>
	<view>
		<!-- 个人信息 -->
		<view class="person-infos">
			<view class="main">
				<view class="photo">
					<img v-if="userInfo.headImg" :src="userInfo.headImg" alt="">
					
					<u-avatar  v-else  size="120" ></u-avatar>
				</view>
				<view class="infos">
					<view class="name">
						{{userInfo.name}}
					</view>
					<view class="department-position">
						<view class="department" v-if="userInfo.orgName">
							<view class="icon">
								
								<img src="../../assets/img/department.png" alt="">
							</view>
							<view class="text">
								{{userInfo.orgName}}
							</view>
						</view>
						<view class="position">
							<text class="icon">
								<img src="../../assets/img/position.png" alt="">
							</text>
							<text class="text">
								员工
							</text>
						</view>
					</view>
				</view>
				<view class="to-homepage" v-if="false" >
					<text class="text">个人主页</text><text>
						<u-icon size="32" name="arrow-right" color="#80FFFFFF"></u-icon>
					</text>
				</view>
			</view>
			<view class="grid">
				<view class="item">
					<view class="amout">
						0
					</view>
					<view class="text">
						发布
					</view>
				</view>
				<view class="item">
					<view class="amout">
						0
					</view>
					<view class="text">
						点赞
					</view>
				</view>
				<view class="item" @click="gotoUrl('pages/mine/myComment')" >
					<view class="amout">
						0
					</view>
					<view class="text">
						  评论

					</view>
				</view>
				<view class="item">
					<view class="amout">
						{{plusInfo.userPoints}}
					</view>
					<view class="text">
						积分
					</view>
				</view>
			</view>

		</view>
		<!-- 功能 -->
		<view class="function-group group1" v-if="false">
			<view class="item">
				<view class="title">
					<view class="icon">
						<img src="../../assets/img/riLine-gift-2-line@2x.png" alt="">
					</view>
					<view class="text">
						我的获奖记录
					</view>
				</view>
				<view class="right">
					<u-icon name="arrow-right" size="32" color="#cccccc"></u-icon>
				</view>
			</view>

			<view class="item">
				<view class="title">
					<view class="icon">
						<img src="../../assets/img/riLine-coin-line@2x.png" alt="">
					</view>
					<view class="text">
						积分兑换
					</view>
				</view>
				<view class="right">
					<u-icon name="arrow-right" size="32" color="#cccccc"></u-icon>
				</view>
			</view>

		</view>

		<view class="function-group ">
			<view class="item" @click="gotoUrl('pages/mine/data')">
				<view class="title">
					<view class="icon">
						<img src="../../assets/img/riLine-account-box-line@2x.png" alt="">
					</view>
					<view class="text">
						个人资料
					</view>
				</view>
				<view class="right">
					<u-icon name="arrow-right" size="32" color="#cccccc"></u-icon>
				</view>
			</view>

			<view class="item"  @click="gotoUrl('pages/mine/phone')" >
				<view class="title">
					<view class="icon">
						<img src="../../assets/img/riLine-smartphone-line@2x.png" alt="">
					</view>
					<view class="text">
						绑定手机
					</view>
				</view>
				<view class="right">
					<text class="value">{{userPhone}}</text>
					<u-icon name="arrow-right" size="32" color="#cccccc"></u-icon>
				</view>
			</view>
			<view class="item"   @click="gotoUrl('pages/mine/feedback')" >
				<view class="title">
					<view class="icon">
						<img src="../../assets/img/riLine-file-edit-line@2x.png" alt="">
					</view>
					<view class="text">
						意见反馈
					</view>
				</view>
				<view class="right">
					<u-icon name="arrow-right" size="32" color="#cccccc"></u-icon>
				</view>
			</view>
			<view class="item" v-if="false">
				<view class="title">
					<view class="icon">
						<img src="../../assets/img/riLine-customer-service-2-line@2x.png" alt="">
					</view>
					<view class="text">
						联系我们
					</view>
				</view>
				<view class="right">
					<text class="value">0716-8888888</text>
					<u-icon name="arrow-right" size="32" color="#cccccc"></u-icon>
				</view>
			</view>
			<view class="item"  @click="logout" >
				<view class="title">
					<view class="icon">
						<img src="../../assets/img/riLine-logout-box-r-line@2x.png" alt="">
					</view>
					<view class="text">
						退出账号
					</view>
				</view>
				<view class="right">
					<u-icon name="arrow-right" size="32" color="#cccccc"></u-icon>
				</view>
			</view>
		</view>

		<tabbar current="2"></tabbar>
	</view>
</template>

<script>
	import * as API from '@/apis/pagejs/user.js'
	
	import tabbar from "../../components/Tabbar.vue"
	export default {
		components: {
			tabbar
		},
		data() {
			return {
				plusInfo:{},
				userInfo:{},
				userPhone:"",
			}
		},
		onLoad() {
			
			this.init()
		},
		onShow(){
			this.findByOpenId()
		},
		methods: {
			init(){
				this.plusInfo=this.carhelp.getPersonInfoPlus();
				this.userInfo=this.carhelp.getPersonInfo();
				
				
				if(this.userInfo&&this.userInfo.phone){
					var phone = this.userInfo.phone;
					var phone1 = phone.slice(0,3);
					var phone2 = phone.slice(-4);
					this.userPhone = phone1 + '****' + phone2;
				}
			},
			findByOpenId(){
				API.findByOpenId({
					noerror:true,
					openId: this.carhelp.getOpenId(),
					
				}).then((response) => {
					
					this.carhelp.setPersonInfo(response.data.regUser);
					this.carhelp.setPersonInfoPlus(response.data)
					this.init();
				}).catch(error => {
					uni.hideLoading();
					
				})
			},
			logoutApi(){
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				var data = {
					
				};
				 
				API.logout(data).then((res) => {
					this.carhelp.setToken("",);
					this.carhelp.set("token_tdate","")
					this.carhelp.setPersonInfo("");
					this.carhelp.setPersonInfoPlus(""  )
					
					uni.reLaunch({
						url:"/"
					})
					
				}).catch(error => {
					uni.showToast({
						title: error
					})
				})
			},
			phone(){
				uni.makePhoneCall({
				    phoneNumber:this.tel //仅为示例
				});
			},
			logout(){
						uni.showModal({
							title: '提示',
							content: '确认是否退出？',
							success: res=> {
								if (res.confirm) {
								   //付钱  改为组件
								   this.logoutApi();
								   
								} else if (res.cancel) {
									console.log('用户点击取消');
								}
							}
						});
					},
		}
	}
</script>

<style lang="scss" scoped>
	// 个人信息
	.person-infos {
		background: linear-gradient(45.45deg, rgba(6, 50, 130, 1) -0.45%, rgba(0, 88, 209, 1) 23.41%, rgba(0, 53, 153, 1) 52.12%, rgba(0, 66, 178, 1) 77.4%, rgba(0, 20, 130, 1) 100.65%);
		color: rgba(255, 255, 255, 1);
		padding: 40rpx 32rpx 116rpx 32rpx;

		.main {
			display: flex;
			align-items: center;

			.photo {
				img {
					width: 120rpx;
					height: 120rpx;
					border-radius: 50px;
				}

			}

			.infos {
				margin-left: 24rpx;

				.name {
					line-height: 28px;
					font-size: 20px;
				}

				.department-position {
					display: flex;
					align-items: center;
					margin-top: 16rpx;


					.icon {
						margin-right: 8rpx;

						img {
							width: 28rpx;
							height: 28rpx;
							
						}
					}

					.department {
						display: flex;
						
						.text{
							line-height: 16px;
						}


					}

					.position {
						display: flex;
						
						margin-left: 24rpx;
                .text{
                	line-height: 16px;
                }


					}
				}
			}

			.to-homepage {
				margin-left: auto;

				.text {
					font-size: 16px;
					margin-right: 8rpx;

				}
			}
		}

		.grid {
			width: 100%;
			display: flex;
			flex-direction: row;
			flex-wrap: wrap;
			align-items: center;
			margin-top: 24rpx;

			.item {
				width: 25%;
				text-align: center;

				.amout {
					font-size: 48rpx;
					line-height: 64rpx;

				}

				.text {
					font-size: 32rpx;
					line-height: 44rpx;
				}
			}
		}

	}

	// 功能
	.group1 {
		margin-top: -72rpx !important;
	}

	.function-group {
		border-radius: 8px 8px 0px 0px;
		background-color: rgba(255, 255, 255, 1);
		padding: 0 0 0 24rpx;
		margin: 0 32rpx;
		margin-top: 24rpx;

		.item {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 96rpx;
			border-bottom: 1px solid #E6E6E6;

			.title {
				display: flex;
				align-items: center;

				.icon {
					margin-right: 24rpx;

					img {
						width: 40rpx;
						height: 40rpx;
						vertical-align: middle;
					}
				}

				.text {
					color: rgba(51, 51, 51, 1);
					font-weight: bold;
				}
			}

			.right {
				margin-right: 16rpx;
				margin-left: 8rpx;
				display: flex;
			}
		}
	}
</style>
