<template>
	<view class="je">
		<view class="sheader" :style="'height:'+headerHeight+'px'">
			<view class="sheader_a" @click="side">
				<image src="https://ldc365.cn/assets/static/index_icon.png" class="sheader_b" mode=""></image>
				<view class="title">宠365</view>
			</view>
		</view>
		<u-popup v-model="show" mode="left" v-if="type">
			<view class="indexa" :style="'top:'+headerHeight+'px'">
				<view class="sheader_a" @click="side">
					<image src="https://ldc365.cn/assets/static/index_icon.png" class="sheader_b" mode=""></image>
					<image src="https://ldc365.cn/assets/static/index_logo.png" class="sheader_img" mode="">
					</image>
				</view>
				<view class="indexb">
					<view class="indexc">
						<image
							:src="hasLogin && userinfo.avatar ? userinfo.avatar :'https://ldc365.cn/assets/static/moren.png'"
							class="indexc_img" mode=""></image>
						<view class="indexd" @click="GoLogin">
							<view class="indexd_p">{{ hasLogin? (userinfo.nickname || '未设置昵称') : '立即登录' }}</view>
							<view class="indexd_p1" v-if="hasLogin">{{userinfo.mobile}}</view>
						</view>
					</view>
					<view class="indexe">
						<view class="indexe_a" @click="GoIndex">
							<view class="indexe_box">
								<image src="https://ldc365.cn/assets/static/1/49.png" class="indexe_icon" mode="">
								</image>
							</view>
							<view class="indexe_p">代办事项</view>
						</view>
						<view class="indexe_a" @click="GoOrder">
							<view class="indexe_box">
								<image src="https://ldc365.cn/assets/static/1/50.png" class="indexe_icon" mode="">
								</image>
							</view>
							<view class="indexe_p">订单管理</view>
						</view>
						<view class="indexe_a" @click="GoMarket">
							<view class="indexe_box">
								<image src="https://ldc365.cn/assets/static/1/51.png" class="indexe_icon" mode="">
								</image>
							</view>
							<view class="indexe_p">营销设置</view>
						</view>
						<view class="indexe_a" @click="GoDelivery">
							<view class="indexe_box">
								<image src="https://ldc365.cn/assets/static/1/38.png" class="indexe_icon" mode="">
								</image>
							</view>
							<view class="indexe_p">配送员管理</view>
						</view>
						<view class="indexe_a">
							<u-radio-group v-model="checkIndex" @change="radioGroupChange" active-color="#F6B301">
								<u-radio v-for="(item, index) in list" :key="index" :name="item.name"
									:disabled="item.disabled">
									{{item.name}}
								</u-radio>
							</u-radio-group>
						</view>
					</view>
				</view>

			</view>
		</u-popup>
		<u-popup v-model="show" mode="left" v-if="!type">
			<view class="indexa" :style="'top:'+headerHeight+'px'">
				<view class="sheader_a" @click="side">
					<image src="https://ldc365.cn/assets/static/index_icon.png" class="sheader_b" mode=""></image>
					<image src="https://ldc365.cn/assets/static/index_logo.png" class="sheader_img" mode="">
					</image>
				</view>
				<view class="indexb">
					<view class="indexc">
						<image
							:src="hasLogin && userinfo.avatar ? userinfo.avatar :'https://ldc365.cn/assets/static/moren.png'"
							class="indexc_img" mode=""></image>
						<view class="indexd" @click="GoLogin">
							<view class="indexd_p">{{ hasLogin? (userinfo.nickname || '未设置昵称') : '立即登录' }}</view>
							<view class="indexd_p1" v-if="hasLogin">{{userinfo.mobile}}</view>
						</view>
					</view>
					<view class="indexe">
						<view class="indexe_a" @click="GoPassword">
							<view class="indexe_box">
								<image src="https://ldc365.cn/assets/static/1/52.png" class="indexe_icon" mode="">
								</image>
							</view>
							<view class="indexe_p">修改密码</view>
						</view>
						<view class="indexe_a" @click="GoWithdeawal">
							<view class="indexe_box">
								<image src="https://ldc365.cn/assets/static/1/54.png" class="indexe_icon" mode="">
								</image>
							</view>
							<view class="indexe_p">我的钱包</view>
						</view>
						<view class="indexe_a" @click="GoMine">
							<view class="indexe_box">
								<image src="https://ldc365.cn/assets/static/1/56.png" class="indexe_icon" mode="">
								</image>
							</view>
							<view class="indexe_p">完善资料</view>
						</view>
						<view class="indexe_a" @click="loginOut">
							<view class="indexe_box">
								<image src="https://ldc365.cn/assets/static/1/55.png" class="indexe_icon" mode="">
								</image>
							</view>
							<view class="indexe_p">退出登录</view>
						</view>
					</view>
				</view>

			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		getToken,
		removeToken
	} from '@/utils/auth';
	export default {
		name: "u-header",
		data() {
			return {
				headerHeight: 0,
				show: false,
				hasLogin: false,
				userinfo: {},
				type: false,
				list: [{
						name: "自动派单",
						disabled: false
					},
					{
						name: "手动派单",
						disabled: false
					}
				],
				checkIndex: "自动派单"
			};
		},
		created() {
			uni.getSystemInfo({
				success: (res) => {
					const menuButton = uni.getMenuButtonBoundingClientRect() // 胶囊
					const navBarPadding = (menuButton.top - res.statusBarHeight) * 2
					let statusBarHeight = res.statusBarHeight
					let navHeight = menuButton.height + navBarPadding
					this.headerHeight = navHeight + statusBarHeight
				}
			})
			this.GetUser()
			let data = getApp().globalData
			this.type = data.isAdmin;
			if (this.type) {
				this.getAdminConfig()
			}
		},
		methods: {
			// 获取当前的配置
			getAdminConfig(e) {
				this.request('/admin_config/get_config', '', 'get').then(res => {
					if (res.data.order_way === 'manual') {
						console.log('手动派单')
						this.checkIndex = "手动派单"
					} else {
						this.checkIndex = "自动派单"
					}
				});
			},
			// 切换
			radioGroupChange(e) {
				console.log(e)
				let type = "";
				if (e === '手动派单') {
					type = 'manual'
				} else {
					type = "auto"
				}
				this.request('/admin_config/set_config', {
					order_way: type
				}, 'get').then(res => {
					if (res.code === 1) {
						uni.showToast({
							title: '配置成功',
							icon: 'none'
						})
					}
				});
			},
			// 点击退出登录
			loginOut() {
				getApp.globalData = {
					isAdmin: false
				}
				removeToken()
				uni.reLaunch({
					url: "/pages/login/login"
				})
				this.show = false
			},
			// 点击完善信息
			GoMine() {
				uni.navigateTo({
					url: '/pages/order/perfect'
				})
				this.show = false
			},
			// 点击我的钱包
			GoWithdeawal() {
				uni.navigateTo({
					url: '/pages/mine/mine'
				})
				this.show = false
			},
			// 点击修改密码
			GoPassword() {
				uni.navigateTo({
					url: "/pages/mine/password"
				})
				this.show = false
			},
			// 代办事项
			GoIndex() {
				uni.navigateTo({
					url: '/pages/index/index'
				})
				this.show = false
			},
			GoDelivery() {
				uni.navigateTo({
					url: '/pages/Delivery/Delivery'
				})
				this.show = false
			},
			// 点击营销设置
			GoMarket() {
				uni.navigateTo({
					url: '/pages/Marketing/Marketing'
				})
				this.show = false
			},
			// 点击前往订单页面
			GoOrder() {
				uni.navigateTo({
					url: '/pages/order/order'
				})
				this.show = false
			},
			//去登陆
			GoLogin() {
				var token = getToken();
				if (!token) {
					this.side()
					uni.navigateTo({
						url: '../login/login'
					})
				}else{
					uni.navigateTo({
						url:"/pages/mine/editMine"
					})
				}
				this.show = false
			},
			//获取用户信息
			GetUser() {
				this.request('/user/index', '', 'post').then(res => {
					var token = getToken();
					if (token) {
						this.userinfo = res.data
						this.hasLogin = true
						console.log(this.userinfo)
					}
					if (!res.data.wx_authed) {
						uni.login({
							provider: 'weixin',
							success: (code) => {
								console.log(code.code);
								this.request('/user/wx_auth', {
									code: code.code
								}, "GET")
							}
						})
					}

				});
			},
			side() {
				this.show = !this.show
				var token = getToken();
				if(token){
					this.GetUser()
				}
			},
		}
	}
</script>

<style lang="scss">
	.u-drawer-content {
		width: 68% !important;
	}

	.indexa {
		position: relative;
		min-width: 68vw;

		.sheader_a {
			margin-top: -60rpx;
			width: 100%;
			height: 60rpx;
			padding: 0 24rpx;
			box-sizing: border-box;
			display: flex;
			justify-content: flex-start;
			align-items: center;

			.sheader_b {
				width: 48rpx;
				height: 38rpx;
			}

			.sheader_img {
				width: 132rpx;
				height: 50rpx;
				margin-left: 36rpx;
			}
		}
	}

	.indexb {
		width: 100%;
		padding: 30rpx;
		box-sizing: border-box;

		.indexc {
			display: flex;
			justify-content: flex-start;
			align-items: center;
			margin-top: 30rpx;

			.indexc_img {
				width: 130rpx;
				height: 130rpx;
				border-radius: 50%;
				opacity: 1;
			}

			.indexd {
				margin-left: 20rpx;

				.indexd_p {
					font-size: 36rpx;
					font-family: PingFangSC-Semibold;
					line-height: 50rpx;
					color: #111111;
					opacity: 1;
				}

				.indexd_p1 {
					font-size: 32rpx;
					font-family: PingFangSC-Regular;
					line-height: 44rpx;
					color: #111111;
					opacity: 1;
					margin-top: 6rpx;
				}
			}
		}

		.indexe {
			margin-top: 40rpx;

			.indexe_a {
				display: flex;
				justify-content: flex-start;
				align-items: center;
				padding: 32rpx 15rpx;
				box-sizing: border-box;

				.indexe_box {
					width: 49rpx;
					text-align: center;

					.indexe_icon {
						width: 40rpx;
						height: 40rpx;
					}

					.indexe_icona {
						width: 41rpx;
						height: 47rpx;
					}

					.indexe_iconb {
						width: 49rpx;
						height: 47rpx;
					}

					.indexe_iconc {
						width: 39rpx;
						height: 45rpx;
					}

					.indexe_icond {
						width: 43rpx;
						height: 49rpx;
					}
				}

				.indexe_p {
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: 400;
					line-height: 42rpx;
					color: #111111;
					opacity: 1;
					margin-left: 30rpx;
				}
			}
		}

	}

	.je {
		position: fixed;
		left: 0;
		top: 0;
		// height: 100vh;
		width: 100%;
		background: #ffffff;
		z-index: 999;

		.sheader {
			position: absolute;
			top: -5rpx;
			left: 0;
			width: 100%;
			color: #000000;
			z-index: 99;
			// background: linear-gradient(360deg, rgba(236, 236, 236, 0) 0%, #FFFFFF 100%);
			background-color: #FFFFFF;

			.sheader_a {
				position: absolute;
				bottom: 0;
				left: 0;
				width: 100%;
				height: 60rpx;
				padding: 0 24rpx;
				box-sizing: border-box;
				display: flex;
				justify-content: flex-start;
				align-items: center;

				.title {
					width: 100%;
					text-align: center;
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #111111;
					opacity: 1;
					padding-right: 50rpx;
					box-sizing: border-box;
				}

				.sheader_b {
					width: 48rpx;
					height: 38rpx;
				}

				.sheader_img {
					width: 132rpx;
					height: 50rpx;
					margin-left: 36rpx;
				}
			}
		}





	}
</style>
