<template>
	<view>
		<view class="background">
			<!-- 个人信息 -->
			<!-- <view class="person-infos" @click="gotoUrl('/pages/mine/personInfos')"> -->
			<view class="person-infos">
				<view class="photo">
					<!-- <u-avatar class="avatar"
						src="@/assets/img/photo@x1.png" size="112">
					</u-avatar> -->
					<image class="img" src="@/assets/img/默认头像.png" mode=""></image>
				</view>
				<view class="else">
					<view class="name">
						{{personInfo.name}}
					</view>
					<view class="company">
						{{companyInfo.fullName}}
					</view>

				</view>
				<u-picker  v-model="changeUserShow" mode="selector" :range="userList"
					 :default-selector="[defaultIndex]" 
					 range-key="name" 
					 @confirm="selector1confirm" ></u-picker>
					
					<view class="change" @click="changeUserShowBtn" v-if="userList&&userList.length>1">
						切换
					</view>
			</view>
			<!-- 地址 -->
			<view class="address-box">
				<view class="address">
					<view class="address-title">
						{{companyInfo.fullName}}
					</view>
					<view class="address-value">
						<u-icon name="map" v-if="companyInfo.address"></u-icon>{{companyInfo.address}}
					</view>
				</view>

				<view class="image">
					<image class="img" src="@/assets/img/mineBackground.svg" mode=""></image>
				</view>
			</view>
		</view>
		<!-- 功能 -->
		<view class="function-group">
			<view class="function-item" @click="gotoUrl('/pages/mine/filialeList')"  v-if="false" >
				<view class="icon">
					<image class="img" src="@/assets/img/riLine-function-line.svg" mode=""></image>
				</view>
				<view class="name">
					设备列表
				</view>
				<view class="arrow">
					<u-icon name="arrow-right" color="#b2b2b2"></u-icon>
				</view>
			</view>
			<view class="function-item" @click="gotoUrl('/pages/mine/message')" v-if="false">
				<view class="icon">
					<image class="img" src="@/assets/img/riLine-message-2-line.svg" mode=""></image>
				</view>
				<view class="name">
					我的消息
				</view>
				<view class="arrow">
					<u-icon name="arrow-right" color="#b2b2b2"></u-icon>
				</view>
			</view>



			<view class="function-item" @click="gotoUrl('/pages/mine/feedbackRecord')"  v-if= "false">
				<view class="icon">
					<image class="img" src="@/assets/img/riLine-feedback-line.svg" mode=""></image>
				</view>
				<view class="name">
					意见反馈
				</view>
				<view class="arrow">
					<u-icon name="arrow-right" color="#b2b2b2"></u-icon>
				</view>
			</view>

			<view class="function-item" @click="gotoUrl('/pages/mine/contactService')">
				<view class="icon">
					<image class="img" src="@/assets/img/riLine-customer-service-2-line.svg" mode=""></image>
				</view>
				<view class="name">
					客服热线
				</view>
				<view class="arrow">
					<u-icon name="arrow-right" color="#b2b2b2"></u-icon>
				</view>
			</view>

		</view>



		<view class="function-group">
			<view class="function-item" @click="gotoUrl('/pages/mine/setting')">
				<view class="icon">
					<image class="img" src="@/assets/img/riLine-settings-2-line.svg" mode=""></image>
				</view>
				<view class="name">
					设置
				</view>
				<view class="arrow">
					<u-icon name="arrow-right" color="#b2b2b2"></u-icon>
				</view>
			</view>

		</view>

		<energyCenterTabbar :current="2"></energyCenterTabbar>
	</view>
</template>

<script>
	import energyCenterTabbar from '@/components/energyCenterTabbar.vue'
	import * as API from '@/apis/pagejs/index.js'

	export default {
		components: {
			energyCenterTabbar
		},
		data() {
			return {
				personInfo: {},
				companyInfo: {},
				changeUserShow:false,
				defaultIndex:0,
				userList:[],
			}
		},
		onLoad() {
			this.personInfo=this.carhelp.getPersonInfo()
			//this.userList=this.carhelp.getPersonInfoPlus().userList
			
			this.getfindByOpenId();
			this.getChangeCompanyList();
		},
		onShow() {
			
		},
		methods: {
			getChangeCompanyList(){
				API.changeCompanyList().then((response) => {
					//this.query()
					this.userList=response.data.companyInfoList
						
					//this.companyInfo=response.data.companyInfo;
				}).catch(error => {
					uni.hideLoading();
					uni.showToast({
						icon: "none",
						title: error
					})
				})
			},
			changeUserShowBtn() {
				this.defaultIndex = this.userList.findIndex(item => {
					return item.id == this.companyInfo.id
				})
			
				this.changeUserShow = true
			},
			selector1confirm(e) {
				var obj = this.userList[e[0]]
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
			
				API.changeCompany({
					companyId: obj.id,
					openId: this.carhelp.getOpenId()
				}).then((response) => {
					//this.query()
					this.getfindByOpenId();
			
					//this.companyInfo=response.data.companyInfo;
				}).catch(error => {
					uni.hideLoading();
					uni.showToast({
						icon: "none",
						title: error
					})
				})
			},
			getfindByOpenId() {
				uni.showLoading({
					title: "加载中",
					mask: true,
				})
				API.findByOpenId({
					openId: this.carhelp.getOpenId()
				}).then((response) => {
					uni.hideLoading();
					
					this.personInfo = response.data.regUser;
					this.companyInfo = response.data.companyInfo;
					
					var token = response ? response.data.token : '';
					this.carhelp.setPersonInfo(response.data.regUser );
					
					this.carhelp.setToken(token);
					this.carhelp.setPersonInfoPlus(response.data);
					this.$forceUpdate()
				}).catch(error => {
					uni.showToast({
						title: error,
						icon: "none"
					})
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.background {
		background: linear-gradient(180deg, rgba(194, 219, 255, 1) 53%, rgba(180, 211, 255, 0) 100%);
		padding: 72rpx 32rpx;

		// 个人信息
		.person-infos {
			display: flex;
			align-items: center;

			.photo {
				width: 112rpx;
				height: 112rpx;
				border-radius: 50px;

				.img {
					width: 100%;
					height: 100%;
				}
			}

			.else {
				margin-left: 24rpx;

				.name {
					color: rgb(16, 16, 16);
					font-size: 36rpx;
					font-weight: bold;
				}

				.company {
					color: rgba(16, 16, 16, 1);
				}
			}
			
			// 切换
			.change {
				border: 1px solid rgba(22, 119, 255, 1);
				min-width: 128rpx;
				height: 64rpx;
				line-height: 64rpx;
				border-radius: 50px;
				margin-left: auto;
				color: rgba(22, 119, 255, 1);
				text-align: center;
			}

		}

		// 地址
		.address-box {
			border-radius: 8px;
			background: linear-gradient(90deg, rgba(49, 110, 207, 1) 2%, rgba(20, 73, 159, 1) 100%);
			color: #fff;
			padding: 40rpx 32rpx;
			margin-top: 40rpx;
			display: flex;
			align-items: center;
			position: relative;

			.address {
				.address-title {
					font-size: 40rpx;
				}

				.address-value {
					font-size: 24rpx;
					margin-top: 8rpx;
				}
			}


			.image {
				width: 174rpx;
				height: 174rpx;
				position: absolute;
				right: 0;
				top: 20rpx;

				.img {
					width: 100%;
					height: 100%;
				}
			}
		}
	}


	// 功能
	.function-group {
		border-radius: 8px;
		background-color: #fff;
		margin: 0 32rpx 24rpx;

		.function-item {
			display: flex;
			align-items: center;
			padding: 26rpx 26rpx 26rpx 0;
			margin-left: 26rpx;
			border-bottom: 1px solid rgba(221, 221, 221, 1);

			.icon {
				width: 40rpx;
				height: 40rpx;

				.img {
					width: 100%;
					height: 100%;
				}
			}

			.name {
				color: rgba(51, 51, 51, 1);
				font-size: 30rpx;
				margin-left: 26rpx;
			}

			.arrow {
				margin-left: auto;
			}
		}
	}
</style>