<template>
	<view class="container">
		<!-- <scroll-view @scrolltolower="scrollTolower" :scroll-top="userScrollTop" scroll-y="true" class="container"
		@scroll="userScroll"> -->
		<view class="top-cont u-f es-ver">
			<view :class="fixedTop?'inner fixed':'inner'">
				<!-- 状态栏 -->
				<view :class="fixedTop?'status-bar es-bc-theme':'status-bar'" :style="{ background:headerBG }"></view>
				<view class="top-title-box show" :style="{ background:headerBG }">
					<view>个人中心</view>
				</view>
			</view>

			<view class="my-header-right inner fixed">
				<!-- <image src="@/static/image/my/set_icon.png" mode="aspectFill" @tap="navTo('./about')"></image> -->
				<image :class="isNew ? 'badge':''" @tap="goToMsg()" src="@/static/image/hall/new_hall_icon.png"
					mode="aspectFill"></image>
			</view>

			<!-- 用于顶部固定定位后占位 -->
			<view :class="fixedTop?'seat show':'seat'"></view>

			<view class="mybox">
				<view class="mybox-info">
					<image class="heads es-br-ban" @tap="navToUserInfo('./userInfo')" :src="user&&user.avatar||avatar"
						mode="aspectFill"></image>

					<view>
						<view class="flexBetween">
							<view class="flex-center es-c-22 fs20" @tap="navToUserInfo('./userInfo')">
								<text class="mybox-info-name">{{ isLogin&&user&&user.nickName || '请登录' }}</text>
								<!-- <image class="arrow_black" src="@/static/image/my/right_arrow_black_icon.png"
									mode="aspectFill"></image> -->
							</view>
							<image v-if="isOpen" class="es-w-40 es-h-40 es-mr-10" src="@/static/svg/code_icon20.svg"
								@tap="toSelfQr()" mode="aspectFill"></image>
						</view>
						<view class="flexBetween es-mt-10" @tap="toSelfQr()" v-if="isOpen">
							<view class="qyh es-c-75">
								用户号：U{{user.userId}}
							</view>
							<image class="arrow_black" src="@/static/image/my/right_arrow_black_icon.png"
								mode="aspectFill"></image>
						</view>
						<view class="flex-center" style="margin-top: 14rpx;" v-if="false">
							<view class="flex-center vipbox" v-if="user.isVip==1&&(!isIos || (isIos&&showIOSPay==1))"
								@click="loginNavTo('/pages/course/vipBuy')">
								<image class="arrow_black" src="@/static/image/my/lv_icon.png" mode="aspectFill">
								</image>
								<text class="es-c-FEF5EA">会员</text>
							</view>
							<view class="flex-center vipbox intelligentBox" style="margin-left: 16rpx;"
								v-if="user.vipLevel">
								<image class="arrow_black" src="@/static/image/my/intelligent_icon.png"
									mode="aspectFill">
								</image>
								<text class="es-c-FEF5EA">LV.{{user.vipLevel}}</text>
							</view>
						</view>
					</view>
				</view>

				<!-- 福币，币，券信息 -->
				<view class="mybox-integral">
					<view class="mybox-integral-item" @click="loginNavTo('/pages/user/integral/points')">
						<view class="num">{{user.integral}}</view>
						<view>福币</view>
					</view>
					<view class="mybox-integral-item" @click="loginNavTo('/pages/user/coupon/myCouponList?type=0')">
						<view class="num">{{coupons.notUsedCount}}</view>
						<view>待用券</view>
					</view>
					<view class="mybox-integral-item" @click="loginNavTo('/pages/user/coupon/myCouponList?type=1')">
						<view class="num">{{coupons.usedCount}}</view>
						<view>已用券</view>
					</view>
					<view class="mybox-integral-item" @click="loginNavTo('/pages/user/coupon/myCouponList?type=2')">
						<view class="num">{{coupons.expiredCount}}</view>
						<view>过期券</view>
					</view>
				</view>

				<!-- vip会员 -->
				<!-- <view class="vip-card" v-if="false && user.userId&&(!isIos || (isIos&&showIOSPay==1))">
		    		<view>
		    			<view class="flex-center vip-card-info">
		    				<image src="@/static/image/my/VIP_member.png" mode="aspectFill"></image>
		    				<text>{{getDayMix(user.vipEndDate)}}</text>
		    			</view>
		    			<view class="flex-center vip-card-price">续费享季卡会员约<text>6.5</text>折</view>
		    		</view>
		    		<view class="buyvip" @click="loginNavTo('/pages/course/vipBuy')" >立即续费</view>
		    	</view> -->

				<!-- 我的订单 医疗服务等 -->
				<view class="menuBox">
					<view class="mybox-menu" v-for="(item, index) in menuList" :key="index">
						<view class="u-f-jsb u-f">
							<view class="mybox-menu-title">{{item.menuTitle}}</view>
							<!-- <view class="es-c-99 es-fs-24 u-f-ajc" v-if="index==0" @tap="myOrderFun">
							<view class="es-mr-10">我的订单</view>
							<view class="u-f-ajc">
								<u-icon name="arrow-right" size="24rpx" color="#999999"></u-icon>
							</view>
						</view> -->
						</view>
						<view class="mybox-menu-box">
							<!-- :class="[index==0?'w20':'']" -->
							<view class="mybox-menu-item" v-for="(menu, idx) in item.menus" :key="idx"
								@click="handleMenu(menu)">
								<view class="mybox-menu-itemImage">
									<image :src="menu.icon" mode="aspectFill"></image>
									<view v-if="index==0 && 0" class="numBox es-c-white es-fs-20">8</view>
								</view>
								<text>{{menu.name}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="btns es-mt-40" v-if="isLogin">
					<view class="login-btn" @click="showLogout">退出登录</view>
				</view>
			</view>
		</view>
		<u-popup :show="inviteShow" @close="inviteShow=false" round="32rpx">
			<view class="popupBox">
				<view class="u-f-ajc u-f-jsb">
					<view class="es-fs-36 es-c-00 es-fw-500">
						填写朋友邀请码
					</view>
					<view class="" @tap="scanCodeFun">
						<image class="es-icon-48" src="/static/img/scan_icon24.eb4f6feb.svg" mode=""></image>
					</view>
				</view>
				<input type="text" v-model="inviteCode" class="es-mt-42 es-fs-32" placeholder="请输入邀请码"
					placeholder-style="{color: #B2B2B2;}" />
				<view class="u-f-ajc es-mt-56">
					<view class="popupBox-btn es-mr-32 u-f-ajc colorE62129" @tap="inviteShow=false">
						取消
					</view>
					<view class="popupBox-btn u-f-ajc bgE62129 es-c-white" @tap="invitationCodeFun">
						确认
					</view>
				</view>
			</view>
		</u-popup>
		<!-- </scroll-view> -->
	</view>
</template>

<script>
	import {
		getConfigByKey,
		getIOSPayStatus
	} from '@/api/common.js';
	import {
		startDrugReport,
		getUserFollowDoctor
	} from '@/api/drugReport';
	import {
		getUserInfo,
		bindSales,
		getMyCouponCount
	} from '@/api/user'
	// #ifdef APP-PLUS
	import permision1 from "@/utils/permission.js"
	// #endif
	const avatar = "/static/image/hall/my_heads_icon.png";
	import IMSDK, {
		SessionType
	} from "openim-uniapp-polyfill";
	import {
		navigateToDesignatedConversation,
		callingModule,
		meetingModule,
		setConversation
	} from "@/pages_im/util/imCommon";
	import {
		Igexin
	} from '@/pages_im/util/common.js';
	import {
		isMiOpen
	} from '@/api/common.js';
	export default {
		data() {
			return {
				inviteCode: '',
				inviteShow: false,
				isLogin: false,
				coupons: {
					expiredCount: 0,
					notUsedCount: 0,
					usedCount: 0
				},
				show: false,
				avatar: avatar,
				defUser: {
					avatar: avatar,
					nickName: "请登录",
					userName: "请登录",
					phone: "",
					integral: 0,
					balance: 0
				},
				user: {
					avatar: "/static/image/hall/my_heads_icon.png",
					userName: "",
					phone: "",
					nickName: "",
					integral: 0,
					balance: 0,
					userId: null
				},
				isNew: false,
				top: 0,
				userScrollTop: 0,
				isOpen: true,
				fixedTop: false, // 是否固定头部
				statusBarHeight: uni.getStorageSync('statusBarHeight'),
				menuList: [],
				isIos: false,
				showIOSPay: 0
			}
		},
		onLoad() {
			let that = this;
			uni.$on('refreshUserInfo', function() {
				if (that.$isLogin()) {
					that.getUserInfo();
					that.$updateMsgDot()
				} else {
					that.isLogin = that.$isLogin()
				}
			});
			if (!this.$qconfig.isAppStore) { //应用市场版本隐藏福币商城
				let integralMenus = (this.menuList[2]).menus;
				let integralSubMenu = {
					name: '福币商城',
					icon: "../../static/image/my/my_points_icon.png",
					pageUrl: "/pages/user/integral/integralGoodsList"
				};
				integralMenus.splice(2, 0, integralSubMenu);
			}
			// #ifdef APP-PLUS
			permision1.checkPush();
			this.isIos = (plus.os.name == "iOS")
			if (this.isIos) {
				this.getIOSPayStatusFun()
			}
			// #endif
		},
		onUnload() {
			uni.$off('refreshUserInfo');
		},
		onShow() {
			uni.showTabBar();
			this.isLogin = this.$isLogin()
			let token = uni.getStorageSync('AppToken');
			if (this.$isLogin()) {
				this.getUserInfo();
				this.getMyCouponCount();
				this.$updateMsgDot()
			} else {
				this.user = this.defUser;
				uni.navigateTo({
					url: '/pages/auth/loginIndex'
				})
				return;
			}

		},
		created() {
			this.initMenu();
		},
		methods: {
			async initMenu() {
				this.menuList = [
					// {
					// 	menuTitle: "我的订单",
					// 	menus: [{
					// 		name: '待付款',
					// 		icon: "/static/image/mall/payment.png",
					// 		myOrder: true
					// 	}, {
					// 		name: '待发货',
					// 		icon: "/static/image/mall/send_goods.png",
					// 		myOrder: true
					// 	}, {
					// 		name: '待收货',
					// 		icon: "/static/image/mall/sou_goods.png",
					// 		myOrder: true
					// 	}, {
					// 		name: '已完成',
					// 		icon: "/static/image/mall/completed.png",
					// 		myOrder: true
					// 	}, {
					// 		name: '售后/退款',
					// 		icon: "/static/image/mall/after_sales.png",
					// 		pageUrl: "/pages_user/user/refundOrderList"
					// 	}]
					// },
					// {
					// 	menuTitle: "医疗服务",
					// 	menus: [
					// 		{
					// 			name: '我的处方',
					// 			icon: "../../static/image/my/my_prescription_icon.png",
					// 			pageUrl:"/pages/store/prescribeList"
					// 		},{
					// 			name: '我的医生',
					// 			icon: "../../static/image/my/my_doctor_icon.png",
					// 			pageUrl:"./myDoctorList"
					// 		},{
					// 			name: '随访服务',
					// 			icon: "../../static/image/my/follow_up_icon.png",
					// 			pageUrl:"/pages/user/followList"
					// 		},{
					// 			name: '用药咨询',
					// 			icon: "../../static/image/my/medical_consultation_icon.png",
					// 			pageUrl:"/pages/store/inquiryOrderList",
					// 			isIm:true
					// 		},{
					// 			name: '用药报告',
					// 			icon: "../../static/image/my/medication_report_icon.png",
					// 			pageUrl:"/pages/user/drugReportList"
					// 		}
					// 	]
					// },
					{
						menuTitle: "我的应用",
						menus: [
							// {
							// 	name: '健康档案',
							// 	icon: "../../static/image/my/my_order_icon.png",
							// 	pageUrl: "/pages/user/healthRecords/index"
							// }
							// ,{
							// 	name: '就诊管理',
							// 	icon: "../../static/image/my/visit_icon.png",
							// 	pageUrl:"./patient"
							// },
							{
								name: '地址管理',
								icon: "../../static/image/my/address_management_icon.png",
								pageUrl: "./address"
							},
							// {
							// 	name: '福币管理',
							// 	icon: "/static/image/my/my_points_icon.png",
							// 	pageUrl: "/pages_user/user/integral"
							// },
							{
								name: '优惠券',
								icon: "../../static/image/my/coupon_collection.png",
								pageUrl: "/pages_shopping/shopping/myCoupon"
							},
							// {
							// 	name: '购物车',
							// 	icon: "/static/image/mall/cart.png",
							// 	pageUrl: "/pages/shopping/cart"
							// },
							// {
							// 	name: '我的足迹',
							// 	icon: "/static/image/mall/footprint.png",
							// 	pageUrl: "/pages_user/user/storeProductRelation"
							// },
							// {
							// 	name: '制单管理',
							// 	icon: "/static/image/my/my_cforder_icon.png",
							// 	documentPreparation: true
							// }
							// {
							// 	name: '专属客服',
							// 	icon: "/static/image/my/drzy_icon.png",
							// 	isService: true
							// },
							// {
							// 	name: '领券中心',
							// 	icon: "../../static/image/my/coupon_collection.png",
							// 	pageUrl: "/pages/company/couponList?couponType=6"
							// }
							// ,{
							// 	name: '健康产品',
							// 	icon: "../../static/image/my/my_points_icon.png",
							// 	pageUrl:"/pages/shopping/index"
							// }
							// ,{
							// 	name: '会员中心',
							// 	icon: "../../static/image/my/member_icon.png",
							// 	isUserService:true,
							// 	pageUrl:""
							// }
							// ,{
							// 	name: '健康管家',
							// 	icon: "../../static/image/my/my_doctor_icon.png",
							// 	pageUrl: "/pages/user/addHealthButler"
							// }
							// ,{
							// 	name: '开票历史',
							// 	icon: "../../static/image/my/invoicing_icon.png",
							// 	pageUrl:"/pages/store/invoice/invoiceList",
							// }
							// ,{
							// 	name: '客服中心',
							// 	icon: "../../static/image/my/service_center_icon.png",
							// 	pageUrl:""
							// },
							{
								name: '看课通知',
								icon: "../../static/image/my/my_order_icon.png",
								pageUrl: "/pages/courseAnswer/list"
							}, {
								name: '投诉建议',
								icon: "../../static/image/my/tsjy.png",
								pageUrl: "/pages/user/feedback"
							},
							{
								name: '直播',
								icon: "/static/images/live/live.png",
								pageUrl: "/pages_live/livingList",
								isShow: true
							},
							{
								name: '直播订单',
								icon: "../../static/image/my/my_cforder_icon.png",
								pageUrl: "/pages_live/shopping/order",
								isShow: true
							},
							{
								name: '直播售后',
								icon: "../../static/images/live/live_sale.png",
								pageUrl: "/pages_live/shopping/storeOrderRefundList",
								isShow: true
							},
							{
								name: '商城订单',
								icon: "../../static/image/my/my_cforder_icon.png",
								pageUrl: "/pages_user/user/storeOrder?status=",
								isShow: true
							},
							{
								name: '商城售后',
								icon: "../../static/images/live/live_sale.png",
								pageUrl: "/pages_user/user/refundOrderList",
								isShow: true
							},
						]
					},
					{
						menuTitle: "我的视频",
						menus: [{
							name: '我的收藏',
							icon: "../../static/image/my/collect_icon.png",
							pageUrl: "./myFavoriteVideo"
						}, {
							name: '我的评论',
							icon: "../../static/image/my/evaluate_icon.png",
							pageUrl: "/pages/store/inquiryOrderPingList"
						}]
					},
					{
						menuTitle: "管理应用",
						menus: [
							// {
							// 	name: '医生入驻',
							// 	icon: "../../static/image/my/doctor_entrance_icon.png",
							// 	pageUrl:"/pages/user/registerDoctor?type=1"
							// },{
							// 	name: '药师入驻',
							// 	icon: "../../static/image/my/pharmacist_entrance_icon.png",
							// 	pageUrl:"/pages/user/registerDoctor?type=2"
							// },
							{
								name: '达人主页',
								icon: "../../static/image/my/drzy_icon.png",
								pageUrl: "/pages/expert/index"
							},
							// {
							// 	name: '销售登录',
							// 	icon: "../../static/image/my/login_icon.png",
							// 	isSale: true,
							// 	pageUrl: "",
							// },
							// {
							// 	name: '客服登录',
							// 	icon: "../../static/image/my/login_icon.png",
							// 	isService: true,
							// 	pageUrl: "",
							// },
							{
								name: '关于我们',
								icon: "../../static/image/my/feedback_icon.png",
								pageUrl: "./about"
							}
						]
					}
				]
				let param = {
					key: "app.config"
				};
				let result = await getConfigByKey(param)
				result = result.data && JSON.parse(result.data)
				if (result.tongueFlag && result.tongueFlag != '0') {
					const menuExists3 = this.menuList[0].menus.some(menu => menu.name === '舌苔报告');
					if (!menuExists3) {
						this.menuList[0].menus.push({
							name: '舌苔报告',
							icon: "../../static/image/my/shetai.png",
							pageUrl: "/pages/user/tongue/tongueList"
						})
					}
					const menuExists4 = this.menuList[0].menus.some(menu => menu.name === 'AI舌诊');
					if (!menuExists4) {
						this.menuList[0].menus.push({
							name: 'AI舌诊',
							icon: "/static/image/my/tongue.png",
							pageUrl: "/pages/user/tongue/index"
						})
					}
				}

				if (this.user && !this.user.invitedBySalesId) {
					const isExist = this.menuList.some(item => item.name === '填写邀请码');
					if (!isExist) {
						this.menuList[2].menus.push({
							name: '填写邀请码',
							icon: "../../static/image/my/my_cforder_icon.png",
							isIinvitation: true
						})
					}
				}
				if (this.user && this.user.isCompanyUser) {
					const menuExists = this.menuList[2].menus.some(menu => menu.name === '客服登录');
					if (!menuExists) {
						this.menuList[2].menus.push({
							name: '客服登录',
							icon: "../../static/image/my/login_icon.png",
							isService: true,
							pageUrl: "",
						})
					}
					const menuExists1 = this.menuList[2].menus.some(menu => menu.name === '销售登录');
					if (!menuExists1) {
						this.menuList[2].menus.push({
							name: '销售登录',
							icon: "../../static/image/my/login_icon.png",
							isSale: true,
							pageUrl: "",
						})
					}
				}
			},

			scanCodeFun() {
				let that = this
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						console.log('条码内容：' + res.result);
						const uIndex = res.result.indexOf('U');
						that.inviteCode = uIndex !== -1 ? res.result.slice(uIndex + 1) : res.result;
						that.invitationCodeFun()
					}
				});
			},
			async invitationCodeFun() {
				let params = {
					userId: this.user.userId,
					inviteCode: this.inviteCode
				}
				const res = await bindSales(params)
				if (res.code == 200) {
					uni.showToast({
						icon: 'none',
						title: '绑定成功！'
					})
					this.inviteShow = false
					this.getUserInfo()
					this.menuList[2].menus.pop();
				} else {
					uni.showToast({
						icon: 'none',
						title: res.msg
					})
				}
			},
			getIOSPayStatusFun() {
				getIOSPayStatus().then(res => {
					if (res.code == 200) {
						this.showIOSPay = res.iosPayStatus
					}
				})
			},
			doIM() {
				uni.showLoading({
					title: "处理中..."
				});
				getUserFollowDoctor().then(res => {
						if (res.code == 200) {
							if (res.data != null) {
								let data = res.data;
								var params = {
									followId: data.followId
								};
								console.log(data);
								startDrugReport(params).then(res => {
										uni.hideLoading();
										var that = this;
										var user = JSON.parse(uni.getStorageSync('userInfo'));
										var uid = 'U' + user.userId;
										var did = 'D' + data.followDoctorId;
										var conversationID = `si_${did}_${uid}`;
										this.$store.commit("timStore/setOrderId", data.orderId);
										this.$store.commit("timStore/setFollowId", data.followId);
										this.$store.commit("timStore/setImType", 2);
										this.$store.commit("timStore/setConversationID", conversationID);
										navigateToDesignatedConversation(did, SessionType.Single, false).then((
											res) => {
											// setConversation(conversationID,JSON.stringify(ex)).then(() => {
											// 	console.log("qxj setConversation ex:"+JSON.stringify(ex));		
											// }).catch(() => {});
										}).catch(() => uni.$u.toast("操作失败"));
									},
									rej => {}
								);

							} else {
								uni.hideLoading()
								uni.showToast({
									icon: 'none',
									title: "当前没有药师为您服务",
								});
							}
						} else {
							uni.showToast({
								icon: 'none',
								title: "请求失败",
							});
						}
					},
					rej => {}
				);
			},
			toIM() {
				if (this.$isLogin()) {
					this.doIM();
				} else {
					this.$showLoginPage();
				}
			},
			toCompany() {
				if (this.$isLogin()) {
					var token = uni.getStorageSync('CompanyUserToken');
					if (token) {
						uni.navigateTo({
							url: '/pages/company/index'
						})
					} else {
						uni.navigateTo({
							url: '/pages/company/login'
						})
					}
				} else {
					this.$showLoginPage();
				}
			},
			showLogout() {
				//this.show=true;
				let that = this;
				uni.showActionSheet({
					title: "确认退出吗",
					itemList: ["确定"],
					success: function(res) {
						that.logout();
						that.isLogin = that.$isLogin()
						// uni.navigateTo({
						// 	url: '/pages/auth/loginIndex'
						// })
					}
				});
			},
			hideLogout() {
				this.show = false;
			},
			logout() {
				uni.clearStorage()
				this.$logout();
				let IMUserID = uni.getStorageSync('IMUserID');
				IMSDK.asyncApi(IMSDK.IMMethods.Logout, IMSDK.uuid()).then(() => {
						callingModule?.endCall();
						meetingModule?.endCall();
					}).catch((err) => console.log(err))
					.finally(() => {
						Igexin.unbindAlias(IMUserID);
						uni.removeStorage({
							key: "IMToken"
						});
						uni.removeStorage({
							key: "IMUserID"
						});
						uni.removeStorage({
							key: "IMHasLogin"
						});

					});

				this.user = this.defUser;
				this.coupons.expiredCount = 0;
				this.coupons.notUsedCount = 0;
				this.coupons.usedCount = 0;
			},
			toSale() {
				if (this.$isLogin()) {
					var token = uni.getStorageSync('ManageToken');
					if (token) {
						uni.navigateTo({
							url: '/pages_manage/index'
						})
					} else {
						uni.navigateTo({
							url: '/pages_manage/login'
						});
					}
				} else {
					this.$showLoginPage();
				}
			},
			documentPreparationFun() {
				if (this.$checkCompanyUserLoginState()) {
					uni.navigateTo({
						url: '/pages_company/index'
					})
				} else {
					uni.navigateTo({
						url: '/pages_company/auth/login'
					})
				}
			},
			myOrderFun(item) {
				const arr = ['待付款', '待发货', '待收货', '已完成']
				let status = ''
				if (item.name) {
					arr.indexOf(item.name)
				}
				uni.navigateTo({
					url: '/pages_user/user/storeOrder?status=' + status
				})
			},
			handleMenu(item) {
				if (item.isIm != undefined && item.isIm) {
					this.toIM();
				} else if (item.isIinvitation != undefined && item.isIinvitation) {
					this.inviteShow = true
				} else if (item.documentPreparation != undefined && item.documentPreparation) {
					this.documentPreparationFun();
				} else if (item.myOrder != undefined && item.myOrder) {
					this.myOrderFun(item);
				} else if (item.isService != undefined && item.isService) {
					this.toCompany();
				} else if (item.isSale != undefined && item.isSale) {
					this.toSale();
				} else if (item.isUserService != undefined && item.isUserService) {
					this.loginNavTo('/pages/course/vipBuy')
				} else if (item.isServerCenter != undefined && item.isServerCenter) {
					this.gotoMiniProgram("/page_user/service");
				} else if (item.name == '客服中心') {
					const url = getApp().globalData.kfurl //企业微信客服链接
					const corpId = getApp().globalData.corpId //企业id
					this.openCustomerServiceChat(url, corpId)
				} else {
					this.loginNavTo(item.pageUrl)
				}
			},
			navTo(url) {
				console.log(url);
				uni.navigateTo({
					url: url
				});
			},
			loginNavTo(url) {

				if (!this.$isLogin()) {
					this.$showLoginPage();
					return;
				}
				uni.navigateTo({
					url: url
				});
			},
			navToUserInfo(url) {
				if (!this.$isLogin() || !this.user.userId) {
					this.$showLoginPage();
					return;
				}
				uni.navigateTo({
					url: "./userInfo?userId=" + this.user.userId
				});
			},
			navToServerCenter() {
				if (!this.$isLogin()) {
					this.$showLoginPage();
					return;
				}

			},
			getUserInfo() {
				let that = this;
				getUserInfo().then(res => {
						if (res.code == 200) {
							if (res.user != null) {
								uni.setStorageSync('userInfo', JSON.stringify(res.user));
								this.user = res.user;
								this.initMenu()
							} else {
								uni.showToast({
									icon: 'none',
									title: res.msg,
								});
							}
						}
					},
					rej => {}
				);
			},
			getMyCouponCount() {
				let that = this;
				getMyCouponCount().then(res => {
						if (res.code == 200) {
							this.coupons = res.data;
						}
					},
					rej => {}
				);
			},
			getUserNickName() {
				let nickName = "";
				if (!this.$isLogin()) { //已登录
					nickName = "请登录";
					return nickName;
				}
				nickName = this.$isEmpty(this.user.nickName) ? "请登录" : this.user.nickName;
				return nickName;
			},
			userScroll(e) {
				if (e.detail.scrollTop >= 50) {
					this.fixedTop = true
				} else {
					this.fixedTop = false
				}
				this.top = e.detail.scrollTop;
			},
			scrollTolower() {

			},
			getDayMix(vipEndDate) {
				// 假设 vipEndDate 字符串
				//let vipEndDate = "2024-09-06T14:43:36.000+0800";
				// 将 vipEndDate 解析为日期对象
				let endDate = new Date(vipEndDate);
				// 获取当前日期
				let currentDate = new Date();
				// 计算时间差（毫秒）
				let timeDiff = endDate - currentDate;
				// 计算天数差
				let dayDiff = Math.ceil(timeDiff / (1000 * 3600 * 24));
				let dayStr = "";
				// 输出结果
				if (dayDiff > 0) {
					dayStr = `VIP到期还有${dayDiff}天`;
				} else if (dayDiff === 0) {
					dayStr = "今天是VIP到期日";
				} else {
					dayStr = `VIP已过期${Math.abs(dayDiff)}天`;
				}
				return dayStr;
			},
			goToMsg() {
				uni.switchTab({
					url: '/pages_im/pages/conversation/conversationList/index'
				});
			},
			async openCustomerServiceChat(url, corpId) {
				// #ifdef H5
				window.location.href = url
				// #endif 
				// #ifdef MP-WEIXIN 
				wx.openCustomerServiceChat({
					extInfo: {
						url
					},
					corpId,
					success(res) {
						console.log('成功');
					},
					fail(err) {
						console.log(err, '报错');
					}
				})
				// #endif 

				// #ifdef APP-PLUS 
				let shares = await this.getAppShare().catch(err => {
					throw Error(err)
				});
				shares['weixin'].openCustomerServiceChat({
					corpid: corpId,
					url
				}, suc => {
					console.log("客服打开成功", JSON.stringify(res))
				}, err => {
					console.log("error", JSON.stringify(err))
				})
				// #endif   
			},
			getAppShare() {
				// #ifdef APP-PLUS
				return new Promise((re, rj) => {
					let shares = null;
					var pusher = plus.share.getServices(function(s) {
						shares = {};
						s.forEach(e => shares[e.id] = e);
						re(shares)
					}, function(e) {
						rj(e);
					});
				});
				// #endif 
			},
			gotoMiniProgram(pageUrl) {
				plus.share.getServices(function(res) {
					var sweixin = null;
					for (var i = 0; i < res.length; i++) {
						var t = res[i];
						if (t.id == 'weixin') {
							sweixin = t;
						}
					}
					if (sweixin) {
						//唤起微信跳转小程序
						sweixin.launchMiniProgram({
							id: getApp().globalData.miniprogamId,
							path: pageUrl,
							type: 0
						}, function() {
							console.log("微信唤起成功");
							return true;
						}, function(e) {
							console.log("微信唤起失败", e);
							uni.showToast({
								title: '微信唤起失败，请检查是否有微信应用',
								icon: 'none'
							})
							return false;
						})

					} else {
						uni.showToast({
							title: '微信唤起失败，请检查是否有微信应用',
							icon: 'none',
							duration: 3000
						})
						return false;
					}

				}, function(res) {

				});
			},
			toSelfQr() {
				uni.navigateTo({
					url: '/pages_im/pages/common/userOrGroupQrCode/index',
				});
			},
			userIsDel() {
				return this.user.status == 0;
			},
			isMiOpen() {
				isMiOpen().then((res) => {
					if (res.code == 200) {
						uni.setStorageSync('isOpen', res.data);
						this.isOpen = res.data;
					}
				});
			},

		},
		computed: {
			// 计算属性的 getter
			headerBG: function() {
				var top = this.top / 88;
				return 'rgba(253,224,204, ' + top + ')';
			},
		}

	}
</script>


<style scoped lang="scss">
	page {
		height: 100%;
		background: #f7f7f7;
	}

	.top-cont {
		height: 100vh;
		// overflow: hidden;
		// height: 370rpx;
		position: relative;
		display: flex;
		flex-direction: column;

		&::after {
			content: '';
			width: 100%;
			height: 370rpx;
			position: absolute;
			z-index: -1;
			left: 0;
			top: 0;
			border-radius: 0 0 50rpx 50rpx;
		}

		.inner.fixed {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 999;
		}

		.seat {
			display: none;
			height: var(--status-bar-height);

			&.show {
				display: block;
			}
		}

		.status-bar {
			background-color: rgba(253, 224, 204, 1);
			height: var(--status-bar-height);
		}

		.status-bar.main-bg {
			background-color: #fff;
		}

		.top-title-box {
			height: 88rpx;
			line-height: 88rpx;
			text-align: center;
			background-color: #fff;
			font-size: 18px;
			color: #333;
			font-weight: 550;
			display: none;

			&.show {
				display: block;
			}
		}
	}

	.top-section {
		.bg-img {
			position: fixed;
			width: 100%;
			top: 0;
			left: 0;
			right: 0;
			height: 524rpx;
			z-index: 0;
		}
	}

	@mixin u-flex($flexD, $alignI, $justifyC) {
		display: flex;
		flex-direction: $flexD;
		align-items: $alignI;
		justify-content: $justifyC;
	}

	.flex-center {
		@include u-flex(row, center, flex-start);
	}

	.flexBetween {
		width: calc(100vw - 192rpx);
		@include u-flex(row, center, space-between);
	}

	.container {
		background-image: url("@/static/image/hall/home_top_bg.png");
		background-repeat: no-repeat;
		background-size: 100%;
		font-family: PingFang SC, PingFang SC;
		// padding-top: var(--status-bar-height);
		padding-bottom: 20rpx;
		// height: 100%;
	}

	.my-header-right {
		height: 88rpx;
		padding-right: 28rpx;
		margin-top: var(--status-bar-height);
		@include u-flex(row, center, flex-end);

		image {
			margin-left: 32rpx;
			width: 48rpx;
			height: 48rpx;
			position: relative;
		}

		.badge::after {
			content: "";
			width: 16rpx;
			height: 16rpx;
			background: #2583EB;
			border-radius: 50%;
			position: absolute;
			right: 0;
			top: 0;
		}
	}

	.mybox {
		flex: 1;
		overflow-y: auto;
		overflow-x: hidden;
		padding: 12rpx 24rpx;

		&-info {
			@include u-flex(row, center, flex-start);

			&-name {
				font-weight: 600;
				font-size: 40rpx;
				color: #222222;
			}

			.heads {
				width: 128rpx;
				height: 128rpx;
				border-radius: 50%;
				margin-right: 16rpx;
			}

			.arrow_black {
				width: 48rpx;
				height: 48rpx;
			}

			.vipbox {
				background: linear-gradient(90deg, #F26F00 0%, #FF9D1F 100%);
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				border: 1rpx solid #FEDDB9;
				font-weight: 500;
				font-size: 22rpx;
				color: #FEF5EA;
				padding: 0 22rpx 0 12rpx;
			}
		}

		&-integral {
			margin-top: 48rpx;
			@include u-flex(row, center, flex-start);

			&-item {
				width: 25%;
				text-align: center;
				font-weight: 400;
				font-size: 24rpx;
				color: #757575;
			}

			.num {
				margin-bottom: 12rpx;
				font-family: DIN, DIN;
				font-weight: 500;
				font-size: 40rpx;
				color: #313131;
			}
		}

		&-menu {
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			padding: 32rpx 32rpx 36rpx 32rpx;
			margin: 20rpx 0;

			&-title {
				font-weight: 600;
				font-size: 36rpx;
				color: #222222;
				margin-bottom: 42rpx;
			}

			&-box {
				@include u-flex(row, center, flex-start);
				margin-bottom: -40rpx;
				flex-wrap: wrap;
			}

			.w20 {
				width: 20% !important;
			}

			&-item {
				width: 25%;
				margin-bottom: 40rpx;
				@include u-flex(column, center, center);
				font-weight: 400;
				font-size: 24rpx;
				color: #222222;

				.mybox-menu-itemImage {
					position: relative;

					.numBox {
						position: absolute;
						top: -16rpx;
						right: -16rpx;
						border-radius: 50%;
						padding: 8rpx;
						background: #FF7163;
					}
				}

				image {
					height: 48rpx;
					width: 48rpx;
					margin-bottom: 10rpx;
				}
			}
		}
	}

	.vip-card {
		height: 172rpx;
		margin-top: 28rpx;
		background: url("@/static/image/my/vip_bg_left.png") no-repeat left / 128rpx 172rpx,
			url("@/static/image/my/vip_bg_right.png") no-repeat right / 324rpx 172rpx,
			linear-gradient(90deg, #FFF3DF 0%, #FADBA9 100%);
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 0 32rpx;

		box-sizing: border-box;
		@include u-flex(row, center, space-between);

		&-info {
			font-weight: 400;
			font-size: 24rpx;
			color: #834F00;
			margin-bottom: 26rpx;

			image {
				width: 126rpx;
				height: 30rpx;
				margin-right: 34rpx;
			}
		}

		&-price {
			font-weight: 500;
			font-size: 32rpx;
			color: #885201;
			line-height: 38rpx;

			text {
				font-family: Roboto, Roboto;
				font-weight: bold;
				font-size: 40rpx;
				color: #EA8F07;
				margin: 0 8rpx;
			}
		}

		.buyvip {
			height: 72rpx;
			background: #885201;
			border-radius: 36rpx 36rpx 36rpx 36rpx;
			font-weight: 600;
			font-size: 28rpx;
			color: #FFF6E7;
			line-height: 72rpx;
			padding: 0 32rpx;
			display: inline-block;
		}
	}


	.btns {
		// height: 110rpx;
		padding-bottom: 88rpx;
	}

	.login-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		flex: 1;
		margin: 0 30rpx;
		height: 80rpx;
		background: #fff;
		// box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
		border-radius: 40rpx;
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #333;
	}

	.popupBox {
		padding: 36rpx 40rpx;

		input {
			padding: 30rpx 0;
			border-bottom: 1rpx solid #EAEAEA;
			margin-top: 42rpx;
		}

		.es-mt-56 {
			margin-top: 56rpx;
		}

		.popupBox-btn {
			width: 282rpx;
			height: 104rpx;
			border-radius: 12rpx;
			background: #F2F2F2;
		}

		.colorE62129 {
			color: #E62129;
		}

		.bgE62129 {
			background: #E62129;
		}
	}

	.menuBox {
		// flex: 1;
		// overflow-y: scroll;
		// overflow-x: hidden;
	}
</style>