<template>
	<view class="content">
		<view class="banner" v-if="images.length>0">
			<swiper autoplay :duration="1000">
				<swiper-item v-for="(item, index) in images" :key="index">
					<image :src="item" @click="toPage(item)"></image>
				</swiper-item>
			</swiper>
			<!-- <img src="../../static/index/banner.png" alt=""> -->
		</view>

		<!-- 物业考核临时入口
		 <view class="xxx" v-if="false">
			  <view class="xoo" @click="wykpJumpPage('yg')">员工</view>
			  <view class="xoo" @click="wykpJumpPage('admin')">后勤部</view>
			  <view class="xoo" @click="wykpJumpPage('ywh')">业委会</view>
			  <view class="xoo" @click="wykpJumpPage('wy')">物业公司</view>
			  <view class="xoo" @click="wykpJumpPage('admin')">后勤部总务处(考评管理员)</view>
			</view> -->
		<!-- 一级入口 -->
		<view class="routeAreaA" v-if="showFirstMenus">
			<view class="routeBox" v-for="(item,index) in firstMenus" @click="banJump(item)" v-if="item.visible">
				<image :src="item.icon"></image>
				<view class="title">{{item.name}}</view>
			</view>
		</view>
		<!-- 二级入口 -->
		<view class="routeAreaB" v-if="showTodoApply">
			<view class="routeBox" @click="routeTo('db')">
				<image src="../../static/index/area2_wait.png" alt=""></image>
				<view class="msg" v-if="todo_apply_info.myWaitHandleListCount == 0">暂无待办事项</view>
				<view class="msg" v-else>待办事项
					<span class="num">{{ todo_apply_info.myWaitHandleListCount }}</span>
				</view>
			</view>
			<view class="routeBox" @click="routeTo('sq')">
				<image src="../../static/index/area2_apply.png" alt=""></image>
				<view class="msg" v-if="todo_apply_info.myApplyListCount == 0">暂无申请事项</view>
				<view class="msg" v-else>提交申请
					<span class="num">{{ todo_apply_info.myApplyListCount }}</span>
				</view>
			</view>
		</view>
		<!-- 三级入口 -->
		<view class="areaCBox">
			<swiper class="my-swipe" indicator-color="#2191ff" :indicator-dots="true">
				<swiper-item v-for="(item,index) in secondMenus" :key="index">
					<view class="routeAreaC">
						<view class="routeBox" :class="[item1.grayFlag?'gray':'']" v-for="(item1,index1) in item"
							@click="banJump(item1)" v-if="item1.visible">
							<image :src="item1.icon"></image>
							<view class="title">{{item1.name}}</view>
						</view>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<!-- 餐厅统计 -->
		<transition name="fade" v-if="enableTransition">
			<view class="areaDBox" v-if="showCanteenInfo && showCanteenStatis">
				<view class="areaDBox_title">
					<view> 食堂实时人流量 </view>
				</view>
				<view class="areaDBox_content">
					<view class="areaDBox_canteen">
						<view class="areaDBox_label label_mr" :class="[canteenFlag == 1?'activeLabel':'']"
							@click="canteenFlag = 1">
							西单
							<img v-if="canteenFlag == 1" src="@/static/background/icon1.png">
						</view>
						<view class="areaDBox_label label_ml" :class="[canteenFlag == 2?'activeLabel':'']"
							@click="canteenFlag = 2">
							银座
							<img v-if="canteenFlag == 2" src="@/static/background/icon1.png">
						</view>
					</view>
					<view class="areaDBox_count">
						<view class="areaDBox_name">空闲座位<span
								class="areaDBox_num">{{canteenFlag == 1?canteenInfo.xd:canteenInfo.yz}}</span></view>
						<view>就餐人数<span
								class="areaDBox_num">{{canteenFlag == 1?canteenInfo.xd_jc:canteenInfo.yz_jc}}</span>
						</view>
					</view>
				</view>
			</view>
		</transition>
		<!-- 公告 -->
		<view class="noticeMode" v-if="showNotice">
			<view class="title">信息公告
				<view class="more" @click="noticeMore">查看更多
					<van-icon class="icon" name="arrow" />
				</view>
			</view>
			<view class="msgList" v-for="(item,index) in noticeData" @click="toDetail(item.noticeSn)">
				<view class="listMsg">
					<view class="msgContant">{{item.title}}</view>
					<view class="dept">{{item.releaseDeptName}}
						<view class="date">{{item.updateTime}}</view>
					</view>
				</view>
				<view class="msgImg" v-if="item.thumbnail">
					<img :src="item.thumbnail" alt="">
				</view>
			</view>
		</view>
		<!-- 底部 -->
		<!-- <view class="footer indexFooter">
			<view class="footerTab" :class="switchCurrent==index?'footerAct':''" v-for="(item,index) in switchTab"
				:key="index" @click="toSwitch(index)">
				<van-icon class="icon" :name="item.icon" />
				<view class="tabName">{{item.title}}</view>
			</view>
		</view> -->
		<!-- 弹窗通知 -->
		<view class="maskBox" v-if="popupList.length>0 && popupShow">
			<view class="contentTc" v-if="popupData.popupType==1">
				<view class="title margin-bottom-12">{{popupData.popupTitle}}</view>
				<view class="text">
					{{popupData.popupContent}}
				</view>
				<view class="ppBtn margin-bottom-12"
					@click="popupData.jumpUrl ==''|| popupData.jumpUrl ==undefined?closePopup(popupData.popupId):jumpUrl(popupData.jumpUrl)">
					{{popupData.jumpUrl ==''|| popupData.jumpUrl ==undefined?'知道了':'立即查看'}}
				</view>
				<view class="flex-box" @click="isRejectPrompt==1?isRejectPrompt=2:isRejectPrompt=1">
					<view class="radio" v-if="isRejectPrompt==1"></view>
					<img class="radio-active" v-if="isRejectPrompt==2" src="../../static/common/radio5.png" alt="">
					<view class="text-notice">下次不再提醒</view>
				</view>
			</view>

			<img :style="'width:'+img_width+';' + 'height:'+ img_height+';border-radius: .2703*37*2upx;'"
				v-if="popupData.popupType==2" :src="popupData.popupUid" alt="">
			<view class="btn-box" v-if="popupData.popupType==2">
				<view class="ppBtn margin-bottom-12"
					@click="popupData.jumpUrl =='' || popupData.jumpUrl ==undefined ?closePopup(popupData.popupId):jumpUrl(popupData.jumpUrl)">
					{{popupData.jumpUrl == '' || popupData.jumpUrl ==undefined?'知道了':'立即查看'}}
				</view>
				<view class="flex-box" @click="isRejectPrompt==1?isRejectPrompt=2:isRejectPrompt=1">
					<view class="radio" v-if="isRejectPrompt==1"></view>
					<img class="radio-active" v-if="isRejectPrompt==2" src="../../static/common/radio5.png" alt="">
					<view class="text-notice">下次不再提醒</view>
				</view>
			</view>
			<!-- <img class="close" @click="closePopup()" src="../../static/common/close3.png" alt=""> -->
		</view>
		<view class="tips" v-if="showInfoTip">
			<view class="t-content">
				<view class="t-title">完善个人信息</view>
				<view class="t-flex-con">
					<van-field class="t-iput" v-model="formData.phone" placeholder="请输入手机号"></van-field>
					<van-field class="t-iput" v-model="formData.idCard" placeholder="请输入身份证号"></van-field>
				</view>
				<view class="tips-con">为了您的用户体验，请您完善个人信息</view>
				<view class="t-flex-btn">
					<view class="confire" @click="exit">取消</view>
					<view class="confire" @click="confire">确定</view>
				</view>
			</view>
		</view>
		<!-- 身份授权弹窗 -->
		<view>
			<van-popup v-model="show" round closeable :style="{width:'90%', height: '260px' }">
				<h3 class="popup_h3">身份授权</h3>

				<view v-if="cardstuas == 0">
					<span class="popup_span">请输入您的身份证号进行授权</span>
					<view class="popup_rate">
						<van-field maxlength="18" v-model="IdCard" @input="e => IdCard = validForbadAll(e)"
							placeholder="请输入身份证号" />
					</view>
					<i class="popup_value">
						温馨提示:个人身份信息仅用于查询便捷办公出行，不用于其他用途！
					</i>

					<view style="margin-top: 20px;padding: 15px;text-align: center;width: 100%;">
						<button class="submit-button" @click="confire(IdCard)">提交</button>
					</view>
				</view>


				<view v-if="cardstuas == 1" class="popup_true">
					<img style="width: 100upx;" :src="require('@/static/imgs/payscess.png')">
					<span>您已授权</span>

					<view class="popup_button" style="padding: 0;margin-top: 20px;">
						<button class="submit-button" @click="reauthorization">重新授权</button>
						<button class="submit-button" @click="show = false">确定</button>
					</view>
				</view>

			</van-popup>
		</view>
	</view>
</template>
<script>
	import {
		mapState
	} from 'vuex';
	import listCell from '@/components/mix-list-cell';
	import uniPopup from '@/components/uni-popup/uni-popup.vue';
	import uniIcons from '@/components/uni-icons/uni-icons.vue';
	import {
		getBannerList,
		getPopupDataOfIndex,
		readPopupDataOfIndex,
		getAuthenTokenOfHnb,
		getAuthenTokenOfJdsc,
		getAppUserPermissionInfo,
		getUserInfo,
		getNoticeData,
		waitApplyNum,
		updateUserInfo,
		getCanteenInspectionData
	} from '@/common/api.js';
	import {
		callbackRequest,
		callbackRequestNoLoading,
		setStorage,
		getStorage,
		alertTip,
		wxSdk,
		devEnv
	} from '@/common/util.js';
	import {
		Encrypt2
	} from "@/common/utils";
	export default {
		components: {
			uniIcons,
			listCell,
			uniPopup
		},
		data() {
			return {
				bannerList: //getStorage('bannerList'),
					[{
							src: "/static/images/indexbanner/bannerfwzn.png",
							url: "/pages/service-guide/service-guide"
						},
						{
							src: "/static/images/indexbanner/bannermrcp.png",
							url: "/pages/weekmenu/weekcarte"
						},
					],
				permissions: [], // 权限列表(所有菜单)
				userInfo: getStorage('userInfo'),
				// 待办申请数量
				todo_apply_info: {
					myApplyListCount: 0,
					myWaitHandleListCount: 0
				},
				images: [
					'../../static/index/banner.png',
					'../../static/index/banner1.png',
				],
				switchTab: [{
						title: '首页',
						icon: 'wap-home'
					},
					{
						title: '消息',
						icon: 'chat'
					},
					{
						title: '我的',
						icon: 'manager'
					},
				],
				switchCurrent: 0,
				// 一级入口
				routeA: [],
				routeC: [],
				noticeData: [], // 公告列表
				isRejectPrompt: 1,
				popupList: [],
				popupShow: false,
				popupData: {},
				img_width: '',
				img_height: '',
				firstMenus: [], // 一级菜单
				secondMenus: [], // 二级菜单
				formData: {
					phone: '',
					idCard: '',
				},
				showFirstMenus: true, // 是否显示一级菜单
				showTodoApply: true, // 是否显示待办申请
				showCanteenStatis: false, // 是否显示餐厅统计
				showNotice: true, // 是否显示公告
				showInfoTip: false,
				defaultBanner: '../../static/index/banner1.png', // 上方默认轮播图
				enableTransition: false,
				showCanteenInfo: false,
				canteenFlag: 1,
				canteenInfo: {
					xd: 0,
					yz: 0,
					xd_jc: 0,
					yz_jc: 0
				},
				show: false,
				cardstuas: 0,
				IdCard: '',
			};
		},
		onNavigationBarButtonTap(v) {
			console.log(v);
			if (!v.path) {
				return;
			}
			uni.navigateTo({
				url: v.path
			})
		},
		onShow() {
			uni.setStorageSync('haircutId', {
				id: '',
				openType: 7
			});
		},
		async onLoad() {
			await this.getUserInfo()
			this.canteenFlag = uni.getStorageSync('userInfos').ownerLocation
			this.getAppUserPermissionInfo()
			this.getWaitApplyNumFn()
			this.getNoticeDataFn()
			this.popupReminder();
			// this.getCanteenInfoOfInterval();
			this.enableTransition = true;
			// this.getSwipeData();

		},
		computed: {
			...mapState(['authUrl'])
		},
		methods: {
			// 弹窗通知 知道了
			closePopup() {
				this.popupRecord(this.isRejectPrompt);
				this.popupShow = false;
				this.popupReminder();
			},
			// 跳转立即查看
			jumpUrl(url) {
				this.popupRecord(this.isRejectPrompt);
				window.location.href = url;
			},
			// 新增弹窗记录
			popupRecord(isRejectPrompt) {
				let params = {
					method: readPopupDataOfIndex,
					isRejectPrompt: isRejectPrompt,
					popupId: this.popupData.popupId
				}
				callbackRequest(params).then(res => {
					console.log('新增弹窗记录=>', res);
				})
			},
			// 弹窗查询
			popupReminder() {
				let params = {
					method: getPopupDataOfIndex,
				}
				callbackRequest(params).then(res => {
					console.log('弹窗查询==>', res);
					if (res.returnCode == 1 && res.returnData.length > 0) {
						let originalWidth = res.returnData[0].imgWidth; // 原始图片宽度
						let originalHeight = res.returnData[0].imgHeight; // 原始图片高度
						// console.log('原尺寸宽高', originalWidth, originalHeight);
						let containerWidth = window.innerWidth - 148; // 移动端宽度 也是缩放后的宽度
						// console.log("移动端设备宽度：", containerWidth);
						let scaleFactor = containerWidth / originalWidth; // 缩放比例
						let scaledHeight = originalHeight * scaleFactor; // 缩放后的高度
						this.img_width = containerWidth / 1 + 'px';
						this.img_height = scaledHeight / 1 + 'px';
						console.log('宽高=>', this.img_width, originalHeight, scaleFactor);
						this.popupList = res.returnData;
						this.popupShow = true;
						this.popupData = this.popupList[0];
						this.isRejectPrompt = 1;
					}
				})
			},
			exit() {
				wxSdk.invoke("multiWindows_close", {}, function(res) {
					console.log("WINDOW CLOSE END", res);
				});
			},
			//身份证号验证
			idCardTest: function(text) {
				var self = this
				var reg = new RegExp(
					/^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/)
				if (text.indexOf("*") == -1) {
					if (reg.test(text) == false && text != "") {
						if (text == self.formData.idCard) self.formData.idCard = ""
						return false
					}
					return true
				}
			},
			//手机号验证
			teltest: function(text) {
				console.log('124', text)
				var self = this
				var reg = new RegExp(/^1[3456789]\d{9}$/)
				if (text.indexOf("*") == -1) {
					if (reg.test(text) == false && text != "") {
						if (text == self.formData.phone) self.formData.phone = ""
						return false
					}
					return true
				}
			},
			// 完善用户信息
			confire() {
				let that = this
				// if (!that.formData.phone) {
				// 	uni.showToast({
				// 		title: '请填写手机号',
				// 		icon: 'none',
				// 		duration: 2000
				// 	})
				// 	return
				// }
				// if (!that.teltest(that.formData.phone)) {
				// 	uni.showToast({
				// 		title: "请输入正确的11位手机号码",
				// 		icon: 'none',
				// 		duration: 2000
				// 	})
				// 	return
				// }
				if (!that.idCardTest(that.IdCard)) {
					uni.showToast({
						title: "请输入正确的身份证号",
						icon: 'none',
						duration: 2000
					})
					return
				}
				that.formData.idCard = that.IdCard
				let params = {
					idCard: Encrypt2(that.formData.idCard), // 身份证
					mobile: that.formData.phone, // 手机
					method: updateUserInfo,
				}
				console.log(params, '更新入参');

				callbackRequest(params).then(res => {
					console.log(res, '返回参数');
					let msg;
					if (res.returnCode == 1) {
						msg = res.returnMsg
						setTimeout(() => {
							window.history.go(-1)
						}, 2000);
						msg = '授权成功'
						this.getUserInfo()
					} else {
						msg = '授权失败，请重试...'
					}
					// that.showLoading = false;
					that.show = false
					uni.showToast({
						title: msg,
						icon: 'none',
						duration: 2000
					})
				})
			},
			// 新待办申请数量查询
			getWaitApplyNumFn() {
				let params = {
					method: waitApplyNum,
				}
				callbackRequest(params).then(res => {
					console.log('111', res.returnData);
					if (res.returnCode == 1) {
						console.log('新待办申请数量查询', res.returnData);
						if (res.returnData && res.returnData.myApplyListCount && res.returnData
							.myWaitHandleListCount) {
							this.todo_apply_info = res.returnData;
						}
					}
				})
			},
			// 信息公告详情
			toDetail(id) {
				uni.navigateTo({
					url: '/pages/notice/noticeDetail?id=' + id
				})
			},
			getNoticeDataFn(title) {
				const that = this;
				let params = {
					method: getNoticeData,
					pageNum: 1,
					pageSize: 3,
				};
				callbackRequest(params).then(res => {
					let resData = res.returnData;
					that.noticeData = resData
				})
			},
			noticeMore() {
				console.log(1);
				uni.navigateTo({
					url: '/pages/notice/notice'
				})
			},
			// ...mapMutations(['updateAuthUrl', 'login']),
			// 获取用户信息
			getUserInfo() {
				return new Promise((resove, reject) => {
					let params = {
						method: getUserInfo,
					}
					callbackRequest(params).then(res => {
						let userinfo = res.returnData
						uni.setStorageSync('userInfos', userinfo)
						let userInfoA
						if (devEnv) {
							// 模拟单点登陆 session的存入数据 for 便捷出入/实物id
							userInfoA = {
								userId: "8a84a22982034e8e0182c8c62b564cda",
								account: "0050789700",
								name: "侯鹏飞",
								nameCode: "ywyy_houpengfei",
								baseOrgId: "0A5EE2630A1E75E0E0530100007FD2BA",
							};
						} else {
							// 模拟单点登陆 session的存入数据 for 便捷出入/实物id
							userInfoA = {
								userId: userinfo.userId,
								account: userinfo.account, //account 没有
								name: userinfo.realName,
								nameCode: userinfo.nameCode, //
								baseOrgId: userinfo.baseorgId,
							};
						}
						sessionStorage.setItem('1000092_uinfo', JSON.stringify(userInfoA))
						if (res.returnCode == 1) {
							if (!userinfo.idCard) {
								// this.showInfoTip = true
								this.show = true
							} else {
								// this.showInfoTip = false
								this.show = false
							}
							resove(userinfo)
						} else {}
					});
				})
			},
			getBannerInfo(useri) {
				let data = {
					method: getBannerList,
					data: {
						userId: useri.userId,
						roleId: useri.role
					}
				};
				callbackRequestNoLoading(data).then(res => {
					if (res.returnCode == 1) {
						uni.setStorageSync('bannerList', res.returnData);
						this.bannerList = res.returnData;
					} else {}
				});
			},
			// 更新用户信息
			/*getUinfoSync(pnum) {
				let data = {
					method: iOpenidGetUserInfo,
					data: {
						wxOpenId: pnum,
					}
				};
				let useri = uni.getStorageSync("userInfo");
				let userInfo = {};
				callbackRequestNoLoading(data).then(res => {
					if (res.returnCode == 1) {
						userInfo = res.returnData;
						//this.role = res.returnData.role;
						userInfo.userId = res.returnData.id == null ? '' : res.returnData.id;
						//userInfo.headportrait = this.currentUser.headimgurl;
						userInfo.telnumber = res.returnData.mobile == null ? '' : res.data
							.returnData.mobile;
						userInfo.username = res.returnData.realName == null ? '' : res.data
							.returnData
							.realName;
						userInfo.userName = res.returnData.realName == null ? '' : res.data
							.returnData
							.realName;
						userInfo.deptName = res.returnData.departmentName == null ? '' : res.data
							.returnData
							.departmentName;
						userInfo.deptId = res.returnData.department_id == null ? '' : res.data
							.returnData
							.department_id;
						userInfo.orgName = res.returnData.orgName == null ? '' : res.data
							.returnData.orgName;
						//this.userId = this.userInfo.userId;
						//this.deptId = this.userInfo.deptId;
						userInfo.identityAuth = res.returnData.identityAuth == null ? '' : res
							.data.returnData
							.identityAuth;
						userInfo.face_Pic1 = res.returnData.face_Pic1 == null ? '' : res.data
							.returnData
							.face_Pic1;
						userInfo.idnumber = res.returnData.id_card == null ? '' : res.data
							.returnData.id_card;
						userInfo.userLevel = res.returnData.userLevel == null ? '' : res.data
							.returnData
							.userLevel;
						userInfo.deptNameUrl = res.returnData.deptNameUrl == null ? '' : res.data
							.returnData
							.deptNameUrl;
						userInfo.deptIdUrl = res.returnData.deptIdUrl == null ? '' : res.data
							.returnData
							.deptIdUrl;
						useri = userInfo;
						uni.setStorage({
							key: "userInfo",
							data: useri
						})
						this.login(useri); //缓存用户信息
						this.getBannerInfo(useri); //获取banner信息
						this.getUserPermissions();
						this.getBacklogData();
					} else {
						uni.showLoading({
							title: '您还没有使用权限，请联系管理员处理'
						})
						return
					}
				});
			},*/

			async banJump(item) {
				if (!item.alwaysShow) {
					uni.showToast({
						title: '您还没有使用权限，请联系管理员处理',
						icon: 'none',
						duration: 3000,
					})
					return
				}
				let url = item.path
				if (!url) {
					alertTip('敬请期待');
					return
				}
				// 惠农帮
				if (url == 'huinongBang') {
					let result = await this.getTokenOfHnb();
					if (result.returnCode == 1) {
						window.location.href = 'https://gh.esgcc.com.cn/zhhq/?token=' + result.returnData.token;
					} else {
						uni.showToast({
							title: result.returnMsg,
							icon: 'none',
							duration: 2000
						})
					}
					return;
				} else if (url == 'jingdongMall') {
					let result = await this.getTokenOfJdsc();
					if (result.returnCode == 1) {
						window.location.href = 'https://shopapp.echargenet.com/vuegwcsweb/index.html#/common?token=' +
							result.returnData.endToken;
					} else {
						uni.showToast({
							title: result.returnMsg,
							icon: 'none',
							duration: 2000
						})
					}
					return;
				}
				if (url && url.startsWith('/')) {
					if (item.children && item.children.length > 0) {
						// url = url + '?permissions=' + JSON.stringify(item.children);
						url
					}
					uni.navigateTo({
						url
					});
				} else if (url) {
					uni.navigateTo({
						url
					});
				}
			},
			getTokenOfHnb() {
				return new Promise((resove, reject) => {
					let params = {
						method: getAuthenTokenOfHnb,
						id: uni.getStorageSync('userId')
					}
					callbackRequest(params).then(res => {
						console.log("获取惠农帮token===>", res);
						resove(res);
					});
				})
			},
			getTokenOfJdsc() {
				return new Promise((resove, reject) => {
					let params = {
						method: getAuthenTokenOfJdsc,
						id: uni.getStorageSync('userId')
					}
					callbackRequest(params).then(res => {
						console.log("获取京东商城token===>", res);
						resove(res);
					});
				})
			},
			routeTo(item, page) {
				console.log(item);
				let url = item.hbg_url
				if (item == 'db') {
					url = '/pages/easyOption/myWait'
				} else if (item == 'sq') {
					url = '/pages/easyOption/myApply'
				} else if (item == 'firstMenus') {
					window.location.href = page.hbg_url;
				} else if (typeof item == 'object') {
					uni.navigateTo({
						url: item.href + '?type=' + item.type
					})
				}

				if (url) {
					let permissions = this.permissions.filter(i => i.name == item.title)
					let permissionsChildren = permissions.length > 0 && permissions[0].children ? permissions[0].children :
						''
					url = url + '?type=st&permissions=' + JSON.stringify(permissionsChildren);
					uni.navigateTo({
						url
					});
				}
			},
			goNoticeView(id) {
				var url = "/pages/hqfb/hqfbDetail?id=" + id;
				uni.navigateTo({
					url
				});
			},
			goNotice() {
				var url = "/pages/notice/notice";
				uni.reLaunch({
					url
				});
			},
			getUserPermissions() {
				let that = this;
				// if (!that.userId) {
				// 	return;
				// }
				let userId = getStorage('userInfo').userId;
				let deptId = getStorage('userInfo').deptId;
				callbackRequestNoLoading({
					method: getUserPers,
					data: {
						userId: userId,
						deptId: deptId
					}
				}).then(res => {
					if (res.returnCode == 1) {
						that.permissions = res.returnData;
						// that.updateAuthUrl(res.returnData);
						uni.hideLoading();
					} else {
						console.log('获取权限失败');
					}
				});
			},
			// 控制菜单权限
			getAppUserPermissionInfo() {
				setStorage('userInfo', 'a866a82704044ae0a1a12ddc2a2e4346')
				let userId = getStorage('userInfo') ? getStorage('userInfo') :
					'a866a82704044ae0a1a12ddc2a2e4346';
				callbackRequest({
					method: getAppUserPermissionInfo,
					userId: userId,
				}).then(res => {
					uni.hideLoading();
					if (res.returnCode == 1) {
						let returnData = res.returnData;
						this.permissions = returnData.appMenus.length > 0 ? returnData.appMenus : [];
						this.roleList = returnData.roles;
						uni.setStorageSync('permissions', this.permissions);
						this.$nextTick(() => {
							this.handleMenus();
							uni.setStorageSync('roles', returnData.roles);
						});
						console.log(this.roleList, returnData.roles);
					} else {
						uni.showToast({
							title: '权限获取失败',
							icon: 'none',
							duration: 2000
						})
					}
				});
			},
			handleMenus() {
				// 定义切分大小（每chunkSize个菜单为一组切分）
				let chunkSize = 8;
				// 一级菜单
				let firstMenusTemp = [];
				// 二级菜单
				let secondMenusTemp = [];
				// 首页菜单
				let permissionsOfIndex = this.permissions.filter(item => item.path == 'app_index' && item.visible);
				// 过滤掉首页菜单
				let permissionsOfOther = this.permissions.filter(item => item.path != 'app_index');
				console.log(permissionsOfIndex, '首页菜单');
				let showBanner = false;
				let showTodoApply = false;
				let showCanteenStatis = false;
				let showNotice = false;
				if (permissionsOfIndex && permissionsOfIndex.length > 0) {
					if (permissionsOfIndex[0].children && permissionsOfIndex[0].children.length > 0) {
						permissionsOfIndex[0].children.forEach(child => {
							// 首页轮播图
							if (child.path == "top_banners" && child.visible) {
								showBanner = true;
							}
							// 一级菜单
							if (child.path == "first_menus" && child.visible) {
								firstMenusTemp = child.children;
							}
							// 待办申请
							if (child.path == "todo_apply" && child.visible) {
								showTodoApply = true;
							}
							// 餐厅统计
							if (child.path == "canteenStatis" && child.visible) {
								showCanteenStatis = true;
							}
							// 信息公告
							if (child.path == "infoAnnounce" && child.visible) {
								showNotice = true;
							}
						})
					}
				}
				this.firstMenus = firstMenusTemp;
				// 使用循环切分数组
				for (var i = 0; i < permissionsOfOther.length; i += chunkSize) {
					secondMenusTemp.push(permissionsOfOther.slice(i, i + chunkSize));
				}
				this.secondMenus = secondMenusTemp;
				console.log('权限菜单原始数据', permissionsOfOther)
				// 只有一个一级菜单时，直接跳转到对应的页面
				console.log('111', this.secondMenus)
				if (this.secondMenus[0].length == 1) {
					// let params = !this.secondMenus[0][0].children ? '' : this.secondMenus[0][0].children[0].path;
					let params = this.getLastPathBtn(permissionsOfOther)
					let rolePath = this.getLastPath(permissionsOfOther)
					console.log('直跳截取处理', params, rolePath)
					if (rolePath) {
						let path = rolePath.replace(/\?+$/, ''); // 去掉结尾的所有问号
						// 检查问号，选择合适的拼接符
						let delimiter = path.includes('?') ? '&' : '?';
						// 拼接最终的 URL
						let url = path + delimiter + 'role=' + params;
						uni.redirectTo({
							url: url
						})
					}
					return;
				}
				// ==========首页各个模板的显示/隐藏控制==========
				// 1.没有配置首页菜单或者没有配置上方轮播图时，上方轮播图默认显示“温润员工”这个图片
				if (firstMenusTemp.length == 0 || !showBanner) {
					this.images = [
						this.defaultBanner
					];
				}
				// 2.没有配置一级菜单时，隐藏一级菜单
				this.showFirstMenus = firstMenusTemp.length == 0 ? false : true;
				// 3.没有配置待办申请时，隐藏待办申请
				this.showTodoApply = showTodoApply;
				// 4.没有配置餐厅统计时，隐藏餐厅统计
				this.showCanteenStatis = showCanteenStatis;
				// 5.没有配置公告时，隐藏公告
				this.showNotice = showNotice;
			},
			// 查询截取最后一个按钮path字段
			getLastPathBtn(tree) {
				if (!Array.isArray(tree) || tree.length !== 1) {
					return false;
				}

				const rootNode = tree[0];
				if (!rootNode.path || !rootNode.children || rootNode.children.length !== 1) {
					return false;
				}

				function traverse(node) {
					if (node.children && node.children.length === 1) {
						return traverse(node.children[0]);
					} else if (node.children && node.children.length > 1) {
						return false;
					} else {
						return node.path;
					}
				}

				return traverse(rootNode);
			},
			getLastPath(tree) {
				let lastPath = null;
				let _this = this

				function traverse(node) {
					// 如果当前节点是我们想要的类型，更新最后的路径 type 1目录 2菜单 3按钮
					// 如果当前节点是我们想要的类型，更新最后的路径
					if (node.type == 2) {
						lastPath = node.path;
					}

					// 递归遍历子节点
					if (node.type == 2 && node.children && node.children.length == 1) {
						// 当数组是菜单且子节点长度等于1的时候，继续往下递归数组，说明当前数组不是最后一层
						for (let child of node.children) {
							traverse(child);
						}
					} else if (node.type == 2 && node.children && node.children.length > 1 && _this.someTypeTrue(node
							.children)) {
						console.log('1111', node)
						// 当数组是菜单且子节点长度大于1的时候，就得看下面的子节点是否为都是按钮,都是按钮则返回当前路径
						lastPath = false
					} else if (node.type == 2 && node.children && node.children.length > 1 && !_this.someTypeTrue(node
							.children)) {
						console.log('2222', node)
						lastPath = node.path;
					} else {
						console.log('3333', node)
						lastPath = lastPath
					}
				}

				// 遍历每个根节点
				for (let root of tree) {
					traverse(root);
				}

				return lastPath;
			},
			// 判断下一层子节点是否全是按钮
			someTypeTrue(arr) {
				const result = arr.some(item => item.type == 3) ? false : true;
				return result
			},
			// 定时获取餐厅统计数据
			getCanteenInfoOfInterval() {
				this.getCanteenInspectionInfo();
				console.log('获取餐厅数据', this.canteenInfo)
				// 1分钟获取一次数据
				setInterval(() => {
					this.getCanteenInspectionInfo();
				}, 1000 * 60);
			},
			// 餐厅统计数据获取
			getCanteenInspectionInfo() {
				if (!this.checkShowCanteenInfo()) {
					return;
				}
				let params = {
					method: getCanteenInspectionData,
					noLoading: true,
				}
				callbackRequest(params).then(res => {
					if (res.returnCode == 1) {
						this.canteenInfo = res.returnData;
					}
				})
			},
			// 餐厅统计模块在除了下面这几个时段外，都不展示："07:30:00 - 09:30:00"、"11:30:00 - 14:00:00"、"17:30:00 - 19:30:00"
			checkShowCanteenInfo() {
				let now = new Date();
				let nowTime = now.getTime();
				let timeRanges = [
					["7:30", "9:30"],
					["11:30", "17:00"],
					["17:30", "19:30"]
				];
				let flag = timeRanges.some(range => {
					let startTime = this.getTimeStamp(range[0]);
					let endTime = this.getTimeStamp(range[1]);
					return nowTime >= startTime && nowTime <= endTime;
				});
				this.showCanteenInfo = flag;
				return flag;
			},
			getTimeStamp(time) {
				let now = new Date();
				let hour = time.split(":")[0] * 1;
				let minute = time.split(":")[1] * 1;
				return new Date(now.getFullYear(), now.getMonth(), now.getDate(), hour, minute, 0).getTime();
			},
			//【未知】重新授权
			//重新授权
			reauthorization: function(res) {
				var that = this
				that.cardstuas = 0
				that.IdCard = ''
			},
			// 某项正则
			validForbadAll: function(value, number = 100) {
				let val = value
				value = val.replace(
					/[`~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~！@#￥%……&*（）——\-+={}|《》？：“”【】、；‘'，。、]|null|undefined{1}/g,
					'').replace(/\s/g, "")

				if (value.lenght >= number) {
					mui.toast(`输入内容不能超过${{ number }}个字符`)
				}
				return value
			},
			//提交身份授权
			clickIdCake: function(val) {
				var reg =
					/^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/
				var that = this

				if (reg.test(val) == false) {
					uni.showToast({
						title: "请填写正确的18位身份证号码",
						icon: 'none',
						duration: 2000
					})
				} else {
					request.addIdCard({
						"id": storage.get("userId"),
						"idCard": val
					}, function(res) {
						if (res.returnCode == 1) {
							uni.showToast({
								title: "授权成功",
								icon: 'none',
								duration: 2000
							})
							sessionStorage.setItem('idCard', val)
							that.show = false
						} else {
							uni.showToast({
								title: "授权失败",
								icon: 'none',
								duration: 2000
							})
						}
					})
				}

			},
		}
	};
</script>
<style lang="scss">
	@import '@/static/css/common.scss';

	uni-page-body {
		background-color: #F5F5F5 !important;
		min-height: 100% !important;
		height: auto !important;
	}

	.content {
		padding: .32*37*2upx;
	}

	.banner {
		height: 3.9*37*2upx;
		border-radius: .44*37*2upx;
		margin-bottom: .32*37*2upx;
		overflow: hidden;
	}

	.van-swipe {
		height: 100%;
	}

	.banner image {
		width: 100%;
		height: 100%;
	}

	.routeAreaA {
		background-color: #fff;
		display: flex;
		flex-wrap: wrap;
		padding: .43*37*2upx 0;
		border-radius: .3*37*2upx;
		margin-bottom: .32*37*2upx;
		min-height: 200upx;
	}

	.routeAreaA .routeBox {
		flex-grow: 1;
		width: 25%;
		max-width: 25%;
		text-align: center;
	}

	.routeAreaA .routeBox image {
		width: 40*2upx;
		height: 40*2upx;
		margin-bottom: 6*2upx;
	}

	.routeAreaA .routeBox .title {
		font-size: 28upx;
		color: #0e1a24;
	}

	.routeAreaB {
		display: flex;
		margin-bottom: .32*37*2upx;
	}

	.routeAreaB .routeBox {
		display: flex;
		align-items: center;
		flex: 1;
		border-radius: .3*37*2upx;
		padding: .32*37*2upx 0;
		margin-right: .26*37*2upx;
		background-color: #dfecff;
		justify-content: center;
	}

	.routeAreaB .routeBox:last-child {
		background-color: #e3f9ff;
	}

	.routeAreaB .routeBox:last-child {
		margin: 0;
	}

	.routeAreaB .routeBox image {
		margin-right: .32*37*2upx;
		width: .64*37*2upx;
		height: .64*37*2upx;
	}

	.routeAreaB .routeBox .msg {
		font-size: .38*37*2upx;
		color: #006bd5;
	}

	.routeAreaB .routeBox:last-child .msg {
		font-size: .38*37*2upx;
		color: #0391b9;
	}

	.routeAreaB .routeBox .msg .num {
		color: #409ffd;
		font-size: .48*37*2upx;
		font-weight: bold;
		margin-left: .22*37*2upx;
	}

	.areaCBox {
		background-color: #fff;
		margin-bottom: .32*37*2upx;
		border-radius: .3*37*2upx;

		swiper {
			height: 350upx;
		}
	}

	.routeAreaC {
		display: flex;
		flex-wrap: wrap;
		padding-top: 36upx;
	}

	.routeAreaC .routeBox {
		flex-grow: 1;
		width: 25%;
		max-width: 25%;
		text-align: center;
		margin-bottom: 48upx;
	}

	.routeAreaC .gray {
		filter: grayscale(100%);
	}

	.routeAreaC .routeBox .title {
		font-size: 28upx;
		color: #0e1a24;
	}

	.routeAreaC .routeBox image {
		width: 30*2upx;
		height: 30*2upx;
		margin-bottom: 6*2upx;
	}

	.noticeMode {
		background-color: #fff;
		padding: 12*2upx;
		padding-top: 14*2upx;
		border-radius: .3*37*2upx;
	}

	.noticeMode .title {
		display: flex;
		font-size: 18*2upx;
		font-weight: bold;
		align-items: center;
		margin-bottom: 12*2upx;
	}

	.noticeMode .title .more {
		margin-left: auto;
		font-weight: normal;
		font-size: 14*2upx;
		color: #97A5B1;
		display: flex;
		align-items: center;
	}

	.noticeMode .msgList {
		border: 1px solid #cbe5fe;
		background-color: #f7fbff;
		border-radius: .3*37*2upx;
		display: flex;
		padding: 12*2upx;
		margin-bottom: 12*2upx;

	}

	.noticeMode .msgList .listMsg {
		flex: 1;
		overflow: hidden;
	}

	.noticeMode .msgList .listMsg .msgContant {
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		margin-bottom: 12*2upx;
		font-size: 28upx;
	}

	.noticeMode .msgList .listMsg .dept {
		display: flex;
		font-size: 12*2upx;
		color: #97A5B1;
	}

	.noticeMode .msgList .listMsg .dept .date {
		margin-left: auto;
	}

	.noticeMode .msgList .msgImg {
		width: 1.55*37*2upx;
		max-width: 1.55*37*2upx;
		border-radius: .3*37*2upx;
		overflow: hidden;
		margin-left: .54*37*2upx;
		height: 1.2703*37*2upx;
	}

	.noticeMode .msgList .msgImg img {
		width: 100%;
		height: 100%;
	}

	.maskBox {
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, 0.5);
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		z-index: 99;
	}

	.maskBox .contentTc {
		width: 7.5135*37*2upx;
		height: 9.1351*37*2upx;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: end;
		background-image: url(../../static/index/tcbg.png);
		background-repeat: no-repeat;
		background-size: cover;
		padding: 0 .8108*37*2upx;
	}

	/* .maskBox .contentTc .tcbg {
    width: 7.5135*37*2upx;
    height: 9.1351*37*2upx;
  } */
	.maskBox .contentTc .title {
		font-size: .4324*37*2upx;
		font-weight: 600;
		color: #0e1a24;
	}

	.maskBox .contentTc .text {
		font-size: .3784*37*2upx;
		color: #0e1a24;
		margin-bottom: .5405*37*2upx;
		text-align: center;
	}

	.maskBox .contentTc .ppBtn {
		width: 3.7838*37*2upx;
		height: 1.027*37*2upx;
		line-height: 1.027*37*2upx;
		text-align: center;
		color: #fff;
		font-size: .3784*37*2upx;
		background-image: url(../../static/index/tcbtnbg.png);
		background-repeat: no-repeat;
		background-size: cover;
	}

	.maskBox .contentTc .flex-box {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-bottom: .3784*37*2upx;
	}

	.maskBox .contentTc .flex-box .text-notice {
		font-size: .3784*37*2upx;
		color: #97A5B1;
		margin-left: .1622*37*2upx;
	}

	.maskBox .btn-box {
		margin-top: .3243*37*2upx;
	}

	.maskBox .btn-box .ppBtn {
		width: 3.7838*37*2upx;
		height: 1.027*37*2upx;
		line-height: 1.027*37*2upx;
		text-align: center;
		color: #fff;
		font-size: .3784*37*2upx;
		background-image: url(../../static/index/tcbtnbg.png);
		background-repeat: no-repeat;
		background-size: cover;
	}

	.maskBox .btn-box .flex-box {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}

	.maskBox .btn-box .flex-box .text-notice {
		font-size: .3784*37*2upx;
		color: #F9F9F9;
		margin-left: .1622*37*2upx;
	}

	.maskBox .close {
		width: .7027*37*2upx;
		height: .7027*37*2upx;
		margin-top: .7027*37*2upx;
	}

	.maskBox .contentTc .flex-box .radio {
		width: .5405*37*2upx;
		height: .5405*37*2upx;
		border: 2px solid #bdc4d2;
		background-color: #fff;
		border-radius: 50%;
	}

	.maskBox .btn-box .flex-box .radio {
		width: .5405*37*2upx;
		height: .5405*37*2upx;
		border: 2px solid #F9F9F9;
		border-radius: 50%;
	}

	.radio-active {
		width: .5405*37*2upx;
		height: .5405*37*2upx;
	}

	.margin-bottom-12 {
		margin-bottom: .3243*37*2upx;
	}

	/* 测试样式 */
	.xxx {
		display: flex;
		flex-wrap: wrap;
	}

	.xoo {
		border: 2px solid #16C478;
		border-radius: 8px;
		padding: 14px;
	}

	.tips {
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		background-color: rgba(0, 0, 0, 0.5);
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		z-index: 100;

		.t-content {
			width: 80%;
			height: 500upx;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: start;
			background-color: #fff;
			border-radius: 20upx;
			position: relative;

			.t-title {
				font-size: 30upx;
				line-height: 120upx;
			}

			.t-flex-con {
				width: 80%;

				.t-iput {
					width: 100%;
					border: 1px solid #ccc;
					border-radius: 5upx;
				}

				.t-iput:last-of-type {
					margin-top: 20upx;
				}
			}

			.tips-con {
				font-size: 28upx;
				line-height: 100upx;
			}

			.t-flex-btn {
				width: 100%;
				border-top: 1px solid #f1f1f1;
				position: absolute;
				bottom: 0;
				left: 0;
				display: flex;
				flex-direction: row;

				.confire {
					width: 50%;
					line-height: 100upx;
					color: #ccc;
					font-size: 30upx;
					text-align: center;
				}

				.confire:last-of-type {
					color: #1978DE;
					border-left: 1px solid #f1f1f1;
				}
			}
		}
	}


	.areaDBox {
		background-color: #fff;
		margin-bottom: 0.32*74upx;
		border-radius: 0.3*74upx;
		background-image: url(@/static/background/bg1.png);
		background-size: 100% 100%;
		background-repeat: no-repeat;
		height: 110*2upx;
		padding: 8*2upx 6*2upx;
	}

	.fade-enter-active,
	.fade-leave-active {
		transition: opacity 1s, transform 1s;
	}

	.fade-enter,
	.fade-leave-to {
		opacity: 0;
		transform: scale(0.5);
	}

	.areaDBox_title {
		width: 100%;
		height: 30%;
		margin-left: 3*2upx;
	}

	.areaDBox_title view {
		width: 100%;
		color: #0370CE;
		font-weight: 600;
		padding-top: 3*2upx;
	}

	.areaDBox_content {
		width: 100%;
		height: 70%;
		font-size: 14*2upx;
		color: #4B5B68;
	}

	.areaDBox_canteen {
		display: flex;
		justify-content: center;
		height: 50%;
		margin-top: 6*2upx;
	}

	.areaDBox_count {
		display: flex;
		justify-content: center;
		height: 50%;
	}

	.areaDBox_name {
		margin-right: 70*2upx;
		padding-right: 10*2upx;
	}

	.areaDBox_num {
		font-weight: 600;
		padding-left: 10*2upx;
	}

	.label_mr {
		margin-right: 27*2upx;
	}

	.label_ml {
		margin-left: 27*2upx;
	}

	.activeLabel {
		color: #0370CE;
		font-weight: 600;
	}

	.areaDBox_label img {
		position: absolute;
		bottom: 10*2upx;
		width: 116%;
		left: -8%;
	}

	.areaDBox_label {
		position: relative;
	}

	/* 身份授权 */
	.popup_h3 {
		font-size: 36upx;
		font-weight: 700;
		text-align: center;
		margin: 0px auto;
		margin-top: 20upx;
		padding: 20upx;
	}

	.van-field__body>input {
		border: none;
		padding-left: 30upx;
		border-radius: 20upx;
	}

	.popup_span {
		display: block;
		padding: 10upx;
		font-size: 28upx;
		text-align: center;
	}

	.popup_value {
		display: block;
		width: 100%;
		text-align: center;
		padding: 20upx;
		font-style: normal;
		color: red;
		font-size: 20upx;
	}

	.popup_button {
		width: 100%;
		text-align: center;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.submit-button {
		width: 40%;
		height: 60upx;
		color: #fff;
		background-color: #1989fa;
		border: none;
		border-radius: 30upx;
		line-height: 60upx;
	}

	.popup_true {
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 60upx;
		flex-direction: column;
	}

	.popup_true>span {
		display: block;
		font-size: 36upx;
		font-weight: 700;
		margin-top: 40upx;
	}
</style>