<template>
	<view class="container">
		<view class="page">
			<!-- <view class="user" style="background-image: url('../../static/images/bg_mine.png');"> -->
			<view class="user">
				<image src="../../static/images/img01.png" class="icon"></image>
				<view class="name">{{userName}}</view>
				<view class="phone">{{userPhone}}</view>
			</view>
			<view class="service">
				<view class="item" @click="quickEntry(1)">
					<view class="left">
						<image src="../../static/images/user01.png" class="icon"></image>
						<div class="title">个人资料</div>
					</view>
					<image src="../../static/images/icon_more.png" class="arrow"></image>
				</view>
				<view class="item" @click="quickEntry(2)">
					<view class="left">
						<image src="../../static/images/user02.png" class="icon"></image>
						<div class="title">我的房屋</div>
					</view>
					<image src="../../static/images/icon_more.png" class="arrow"></image>
				</view>
				<view class="item" @click="quickEntry(3)">
					<view class="left">
						<image src="../../static/images/user03.png" class="icon"></image>
						<div class="title">我的报修</div>
					</view>
					<image src="../../static/images/icon_more.png" class="arrow"></image>
				</view>
				<view class="item" @click="quickEntry(4)">
					<view class="left">
						<image src="../../static/images/user04.png" class="icon"></image>
						<div class="title">我的投诉</div>
					</view>
					<image src="../../static/images/icon_more.png" class="arrow"></image>
				</view>
				<view class="item" @click="quickEntry(5)">
					<view class="left">
						<image src="../../static/images/user05.png" class="icon"></image>
						<div class="title">缴费记录</div>
					</view>
					<image src="../../static/images/icon_more.png" class="arrow"></image>
				</view>
				<view class="item" @click="quickEntry(6)">
					<view class="left">
						<image src="../../static/images/user06.png" class="icon"></image>
						<div class="title">我的收据</div>
					</view>
					<image src="../../static/images/icon_more.png" class="arrow"></image>
				</view>
				<view v-if="isUser && userType === '2'" class="item" @click="quickEntry(7)">
					<view class="left">
						<image src="../../static/images/user07.png" class="icon"></image>
						<div class="title">切换业主</div>
					</view>
					<image src="../../static/images/icon_more.png" class="arrow"></image>
				</view>
				<view v-if="isEmployee && userType === '1'" class="item" @click="quickEntry(8)">
					<view class="left">
						<image src="../../static/images/user08.png" class="icon"></image>
						<div class="title">维修员</div>
					</view>
					<image src="../../static/images/icon_more.png" class="arrow"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userType: '0',
				userName: '',
				userPhone: '',
			}
		},
		computed: {
			isUser() {
				return !!uni.getStorageSync('user_house_list')
			},
			isEmployee() {
				return !!uni.getStorageSync('employee_house_list')
			}
		},
		methods: {
			onDetail(url) {
				uni.navigateTo({url});
			},
			quickEntry(type) {
				if (type == 1) {
					uni.navigateTo({
						url: '/pages/myInformation/index',
					});
				} else if (type == 2) {
					uni.navigateTo({
						url: '/pages/myHouse/index',
					});
				} else if (type == 3) {
					uni.navigateTo({
						url: '/pages/maintenance/index',
					});
				} else if (type == 4) {
					uni.navigateTo({
						url: '/pages/complaints/index',
					});
				} else if (type == 5) {
					uni.navigateTo({
						url: '/pages/myPaycost/index',
					});
				} else if (type == 6) {
					uni.navigateTo({
						url: '/pages/myReceipt/index',
					});
				} else if (type == 7) {
					const that = this
					uni.showModal({
						title: '提示',
						content: '确认切换到业主吗？',
						success: function (res) {
							if (res.confirm) {
								that.onChangeEmployee('1')
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				} else {
					const that = this
					uni.showModal({
						title: '提示',
						content: '确认切换到维修员吗？',
						success: function (res) {
							if (res.confirm) {
								that.onChangeEmployee('2')
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				}
			},
			onChangeEmployee(type) {
				let data = JSON.parse(uni.getStorageSync('employee_house_list'))
				uni.setStorageSync('platform_code', data[0].platformCode)
				uni.setStorageSync('user_type', type)
				uni.reLaunch({
					url: '/pages/home/index'
				})
			}
		},
		onLoad() {
			this.userType = uni.getStorageSync('user_type')
			this.userPhone = uni.getStorageSync('user_phone')
			if(this.userType === '1') {
				this.userName = uni.getStorageSync('user_name')
			} else {
				this.userName = uni.getStorageSync('employee_name')
			}
		},
		onShow() {

		}
	}
</script>
<style>
	page {
		background-color: #F8F6F9;
	}
</style>
<style lang="scss" scoped>
	.page {
		padding: 20rpx 30rpx 20rpx;
	}

	.user {
		background-image: url('http://192.168.0.118:9999/sys/common/static/scott/pic/bg_mine_1686729855474.png');
		background-position: top center;
		background-repeat: no-repeat;
		background-size: cover;
		border-radius: 16rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		padding: 30rpx ;

		.icon {
			width: 160rpx;
			height: 160rpx;
			border-radius: 160rpx;
		}

		.name {
			font-size: 36rpx;
			color: #ffffff;
			margin: 20rpx 0 10rpx;
		}

		.phone {
			font-size: 28rpx;
			color: #ffffff;
			opacity: 0.55;
		}
	}

	.service {
		background-color: #ffffff;
		padding: 0 30rpx;
		border-radius: 16rpx;
		margin: 30rpx 0;

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

			.left {
				display: flex;
				align-items: center;
				.icon {
					width: 32rpx;
					height: 32rpx;
					margin-right: 20rpx;
				}

				.title {
					font-size: 28rpx;
					color: #191A23;
				}
			}

			.arrow {
				width: 16rpx;
				height: 24rpx;
			}
		}
	}
</style>