<template>
	<view>
		<view>
			<view class="home_top" :style="'background-color:'+backgroundColor+';padding-top:'+tops+'px;'">
				<!-- <view class="home_adr">
					<image :src="adrimg"></image>
					<view class="overtwo">{{address}}</view>
				</view> -->
				<!-- #ifdef MP-WEIXIN -->
				<view class="home_check flexcj" style="padding-right: 160rpx;">
				<!-- #endif -->
				<!-- #ifndef MP-WEIXIN -->
				<view class="home_check flexcj">
				<!-- #endif -->
				
					<!-- 欢迎您登录智能校管家 -->
					<!-- 判断有几种角色 -->
					<block v-for="(ite,idx) in userrolesarr" :key="idx">
						<view class="check_btn" v-if="ite=='school'&&rolesidx==idx" @click="getRoleFn('school',idx)"><image :src="checimg"></image>切换学校</view>
						<view class="check_btn" v-if="ite=='teacher'&&rolesidx==idx" @click="getRoleFn('teacher',idx)"><image :src="checimg"></image>切换老师</view>
						<view class="check_btn" v-if="ite=='parents'&&rolesidx==idx" @click="getRoleFn('parents',idx)"><image :src="checimg"></image>切换家长</view>
					</block>
					<!-- 选择学校 -->
					<!--  -->
					<view style="flex: 0 1 auto;overflow: hidden;">
						<picker range-key='dictLabel' v-if="roles&&roles=='parents'" :value="voindex" :range="voList"	@change='bindDateChangea'>
							<view class="pay_btn flexcc" >
								<view class="f15 cofe f500 over" :class="companyName?'co16':''">
									{{companyName||"请选择学校"}}</view>
								<image :src="upimg" class="rimgs"></image>
							</view>
						</picker>
					</view>
					
				</view>
			</view>
			<image :src="abg" class="abg"></image>

			<view style="margin-top: -460rpx;position: relative;padding-bottom: 20rpx;">
				<!-- <block v-if="dataflag"> -->
				<!-- 老师 -->
				<view class="hatop" v-if="roles=='teacher'">
					<image :src="bbg" class="bbg"></image>
					<view class="hatopa">
						<view class="hatime mb20">{{kaTime}}</view>
						<view class="flex1">
							<block v-for="(ite,idx) in teacherClass" :key="idx">
								<block v-if="idx==checkclassidx">
									<view class="hatit w200 mb12"><text>学校名称：</text>{{ite.schoolName}}</view>
									<view class="flexcj w200 mb12">
										<view class="hatit"><text>上课班级：</text>{{ite.className}}</view>
										<view class="checkimg" @click="getcheckClass(idx)" v-if="teacherClass.length>1">
											<image :src="hcheck"></image>
										</view>
									</view>
								</block>
							</block>
							<view class="flex mb12">
								<view class="hatit w50"><text>当前授课老师：</text>{{tablenow.teacher}}</view>
								<view class="hatit w50"><text>课程名称：</text>{{tablenow.subject}}</view>
							</view>
						</view>
						<view class="flex0 mb8" v-if="tablenow.time">
							<view class="hatit"><text>下课时间：</text>{{tablenow.time}}</view>
						</view>
						<view class="flex0 flexcj">
							<view class="haftime">
								<image :src="htime"></image>
								<!-- @click="handleTime" -->
								<view>还有<text>{{timetit}}</text>分钟
									<block v-if="checkidx==1">延迟放学</block>
									<block v-if="checkidx==2">准备放学</block>
								</view>
							</view>
							<!-- 未放学 -->
							<view class="hafbtn">
								<view :class="checkidx==1?'act':''" @click="getcheck(1)">
									<image :src="hbaga"></image>延迟放学
								</view>
								<view :class="checkidx==2?'act':''" @click="getcheck(2)">
									<image :src="hbag"></image>准备放学
								</view>
							</view>
							<!-- 已放学 -->
							<!-- <view class="hafbtn ">
					   		<view class="acts"><image :src="hbaga"></image>已延迟</view>
					   		<view class="acts">
					   			<image :src="hbag"></image>已放学
					   		</view>
					   </view> -->
						</view>
					</view>
				</view>
				<!-- 家长 列表全展示-->
				<block v-if="roles=='parents'">
					<view class="hatop" style="min-height: 489rpx;" v-for="(ite,idx) in parentsStudent" :key="idx">
						<image :src="cbg" class="bbg"></image>
						<view class="hatopa" style="padding-top: 120rpx;">
							<view class="hatime mb20">{{kaTime}}</view>
							<view class="flex1">
								<view class="hatit w200 mb12"><text>学校名称：</text>{{ite.schoolName}}</view>
								<view class="flexcj w200 mb12">
									<view class="hatit"><text>上课班级：</text>{{ite.className}}</view>
								</view>
								<view class="flex mb12">
									<view class="hatit w50"><text>当前授课老师：</text>{{ite.teacher}}</view>
									<view class="hatit w50"><text>课程名称：</text>{{ite.subject}}</view>
								</view>
							</view>

							<view class="flex0 flexcj">
								<view class="haftime">
									<image :src="htime"></image>

									<view v-if="ite.time&&ite.time!='time'">
										将于<text>{{ite.time}}</text>放学，请您于校门口等待孩子。</view>
									<view v-else>暂无放学信息，请耐心等待</view>
								</view>
							</view>
						</view>
					</view>
				</block>
				
				<!-- tab -->
				<view class="itab">
					<view class="tlist" @click="getStuFn" v-if="checkPermi(['student:info:list'])">
						<view class="image"><image :src="itaba" class="ico1"></image></view>
						<view>学生档案</view>
					</view>
					<!-- <view class="tlist" @click="getStuFn"><image :src="itaba"></image><view>成长档案</view></view> -->
					<view class="tlist" @click="getTeaFn" v-if="checkPermi(['teacher:info:list'])">
						<view class="image"><image :src="itabb" class="ico1"></image></view>
						<view>职工档案</view>
					</view>
					<!-- 家长 -->
					<view class="tlist" @click="getScoreFn" v-if="checkPermi(['score:data:list'])">
						<view class="image"><image :src="itabc" class="ico2"></image></view>
						<view>学生成绩</view>
					</view>
					<view class="tlist" @click="getSecoreFn(1)" v-if="checkPermi(['xiaoYuanInfo:xiaoYuanInfo:list'])">
						<view class="image"><image :src="itabd" class="ico2"></image></view>
						<view>校园广播</view>
					</view>
					<view class="tlist" @click="getSecoreFn(2)" v-if="checkPermi(['xiaoYuanInfo:xiaoYuanInfo:list'])">
						<view class="image"><image :src="itabe" class="ico3"></image></view>
						<view>校园安全</view>
					</view>
					<view class="tlist" @click="getLeaveFn" v-if="checkPermi(['system:leave:list'])">
						<view class="image"><image :src="itabl" class="ico4"></image></view>
						<view>在线请假</view>
					</view>
					<view class="tlist" @click="getMindFn" v-if="checkPermi(['mind:old:list'])&&roles=='parents'">
						<view class="image"><image :src="itabf" class="ico5"></image></view>
						<view>心理健康</view>
					</view>
					<!-- 家长 -->
					<view class="tlist" @click="getHeighFn" v-if="checkPermi(['live:old:list'])&&roles=='parents'">
						<view class="image"><image :src="itabk" class="ico1"></image></view>
						<view>身高体重</view>
					</view>

					<view class="tlist" @click="getTiaoFn" v-if="checkPermi(['course:change:reply'])">
						<view class="image"><image :src="itabg" class="ico5"></image></view>
						<view>调课审核</view>
					</view>
					<view class="tlist" @click="getFanFn">
						<view class="image"><image :src="itabi" class="ico5"></image></view>
						<view>防溺水</view>
					</view>
					<view class="tlist" @click="getPay" v-if="checkPermi(['xiaoYuan:pay:list'])">
						<view class="image"><image :src="itabo" class="ico6"></image></view>
						<view>工资条</view>
					</view>
					<view class="tlist" @click="getYuyueFn" v-if="checkPermi(['system:reservat:list'])">
						<view class="cirbox image">
							<image :src="itabm" class="ico2"></image>
							<view class="cir"></view>
						</view>
						<view>预约拜访</view>
					</view>
					<view class="tlist" @click="getMenuFn" v-if="checkPermi(['system:recipe:list'])">
						<view class="cirbox image">
							<image :src="itabq" class="ico1"></image>
						</view>
						<view>每日食谱</view>
					</view>
					<view class="tlist" @click="getopinion" v-if="checkPermi(['system:opinion:add'])">
						<view class="image"><image :src="itabp" class="ico8"></image></view>
						<view>意见反馈</view>
					</view>
					<view class="tlist" @click="getWebview">
						<view class="image"><image :src="itabn" class="ico2"></image></view>
						<view>问一问</view>
					</view>
					<!-- <view class="tlist" @click="getTiaoFn" ><image :src="itabj"></image><view>使用指南</view></view> -->
					<!-- v-if="roles=='parents'" -->
					<!-- <view class="tlist" @click="gettoStuFn" >
						<view class="image"><image :src="itabh" class="ico7"></image></view>
						<view>敬请期待</view>
					</view> -->
				</view>
				<!-- 路况 公共的-->
				<lu-swiper ></lu-swiper>
				<!-- 视频 -->
				<view class="mt15" v-if="videoflag=='true'">
					<luVideo></luVideo>
				</view>
				<!-- 放学状态 -->
				<view class="hsta" v-if="roles&&roles!='parents'">
					<view class="hsta_t flexcj">
						<view class="hsta_tl f17 ">
							放学状态
							<image :src="hline" class="hline"></image>
						</view>
						<view class="f15 co6 fw5">共计 {{allinfo.all||0}}个班级</view>
					</view>
					<view class="bgf hsta_tm">
						<view class="flexcj pb15">
							<view class="hsta_tmt bg1">
								<view class="hsta_tmta">
									<view class="tit co33">已放学</view>
									<view><text class="co33 f18">{{allinfo.y||0}}</text>个班级</view>
								</view>
								<image :src="habag"></image>
							</view>
							<view class="hsta_tmt bg2">
								<view class="hsta_tmta">
									<view class="tit coed">未放学</view>
									<view><text class="coed f18">{{allinfo.n||0}}</text>个班级</view>
								</view>
								<image :src="haclass"></image>
							</view>
						</view>
						<block v-if="list.length>0">
							<view class="htlist" v-for="(ite,idx) in list" :key="idx">
								<view class="htlistl f15 fw5"><text class="co16">{{ite.className}}</text><text
										class="line">|</text>
									<block v-if="ite.time=='time'">等待放学中</block>
									<block v-else>放学时间 {{ite.time}}</block>
								</view>

								<view class="f15 fw5 coed flex0" v-if="ite.time=='time'">未放学</view>
								<view class="f15 fw5 co33 flex0" v-else>已放学</view>
							</view>
						</block>
						<view class="hmore" @click="getMore" v-if="reachflag">
							查看更多
							<image :src="moreimg"></image>
						</view>
					</view>

				</view>
				<!-- </block> -->
				<!-- 暂无信息 -->
				<!-- <block v-else><no-data ></no-data></block> -->
			</view>
		</view>

		<!-- 发布按钮 -->
		<image :src="scoreimg" class="scoreimg" @click="getRelease" v-if="checkPermi(['score:data:add'])"></image>
		<!-- 弹窗 -->
		<pop-up :type='type' :timetit="timetit" :timelist="timelist" :confdat="confdat" @getConfirm="getConfirm"
			@getClose="getClose" @getyanKeyFn="getyanKeyFn" ></pop-up>
		<footers v-if="isfootflag" :footlist="footlist" :footerindex="footerindex" :color_checked="color_checked" :color_nochecked="color_nochecked" :isHomeIndex="true"></footers>
		
	</view>
</template>

<script>
	import myAmapFun from '@/utils/initmap.js';
	import self from '@/utils/location.js';
	import noData from "@/components/nodata/nodata.vue"
	import luSwiper from "@/components/home/luswiper.vue"
	import luVideo from "@/components/home/luvideo.vue"
	import popUp from "@/components/popup/popup.vue"
	import footers from '@/components/footer/footer.vue'
	import {getApplet,getAppxiaKe,getApplist,getTablenow,getxiaKeTime,getAdrinfo,gettenantCheck,getptenantList} from "@/api/index/index.js"
	import {getDictionaryFn,getconfigKeyFn} from '@/api/mine/register.js'
	import {getConfigKey,getupdConfigKey} from "@/api/mine/mine.js"
	import {checkPermi,checkRole} from "@/utils/permission"; // 权限判断函数
	import {getInfo} from '@/api/login'
import { resolveTransitionHooks } from "vue";
	export default {

		data() {
			return {
				footlist:[
					{module:'home',title:'首页',icon_checked:require('@/static/images/tabbar/home_.png'),icon_nochecked:require('@/static/images/tabbar/home.png'),},
					{module:'work',title:'课表',icon_checked:require('@/static/images/tabbar/work_.png'),icon_nochecked:require('@/static/images/tabbar/work.png'),limit:'course:table:list'},
					{module:'trends',title:'动态',icon_checked:require('@/static/images/tabbar/trends_.png'),icon_nochecked:require('@/static/images/tabbar/trends.png'),limit:'xiaoYuan:notice:list'},
					{module:'mine',title:'我的',icon_checked:require('@/static/images/tabbar/mine_.png'),icon_nochecked:require('@/static/images/tabbar/mine.png')},
					],
				footerindex:'home',
				isfootflag:true,
				color_checked :'161616',
				color_nochecked :'666666',
				navborder: false,
				abg: require('@/static/images/index/habg.png'),
				bbg: require('@/static/images/index/hbbg.png'),
				cbg: require('@/static/images/index/hcbg.png'),
				hcheck: require('@/static/images/hcheck.png'),
				habag: require('@/static/images/index/habag.png'),
				haclass: require('@/static/images/index/haclass.png'),
				hbag: require('@/static/images/index/hbag.png'),
				hbaga: require('@/static/images/index/hbaga.png'),
				hline: require('@/static/images/hline.png'),
				htime: require('@/static/images/htime.png'),
				upimg: require('@/work/static/pay/aup.png'),
				moreimg: require('@/static/images/hmore.png'),
				itaba: require('@/static/images/index/itaba.png'),
				itabb: require('@/static/images/index/itabb.png'),
				itabc: require('@/static/images/index/itabc.png'),
				itabd: require('@/static/images/index/itabd.png'),
				itabe: require('@/static/images/index/itabe.png'),
				itabf: require('@/static/images/index/itabf.png'),
				itabg: require('@/static/images/index/itabg.png'),
				itabh: require('@/static/images/index/itabh.png'),
				itabi: require('@/static/images/index/itabi.png'),
				itabj: require('@/static/images/index/itabj.png'),
				itabk: require('@/static/images/index/itabk.png'),
				itabl: require('@/static/images/index/itabl.png'),
				itabm: require('@/static/images/index/itabm.png'),
				itabn: require('@/static/images/index/itabn.png'),
				itabo: require('@/static/images/index/itabo.png'),
				itabp: require('@/static/images/index/itabp.png'),
				itabq: require('@/static/images/index/itabq.png'),
				scoreimg: require('@/static/images/index/release.png'),
				adrimg: require('@/static/images/adr.png'),
				checimg: require("@/static/images/check.png"),
				checkidx: 2,
				checkidxs: 2,
				timetype: 1,
				backgroundColor: "transparent",
				allinfo: {},
				pageSize: 10,
				pageNum: 1,
				reachflag: true,
				wtdt: '',
				list: [],
				confdat: {
					tit: '确认放学',
					txt: "是否确认准备放学？",
					closetxt: '取消',
					suretxt: '确认放学'
				},
				confdata: {
					tit: '确认放学',
					txt: "是否确认准备放学？",
					closetxt: '取消',
					suretxt: '确认放学'
				},
				confdatb: {
					tit: '延迟放学',
					txt: "是否确认延迟放学？",
					closetxt: '取消',
					suretxt: '确认延迟'
				},
				type: 0,
				timefn: '',
				kaTime: '',
				timetit: '',
				ftimetit: '',
				ytimetit: '',
				timelist: [],
				checkclassidx: 0, //切换班级idx
				classId: '', //班级id
				schoolId: '', //学校id
				roles: '',
				teacherClass: [],
				parentsStudent: [],
				dataflag: false,
				choseroles: '',
				tablenow: {
					teacher: '',
					subject: ''
				}, //现在上课
				loadflag: true,
				tops:0,
				location:'',
				address:'',
				userrolesarr:[],
				rolesidx:0,
				scrollTop:0,
				setflag:false,
				voList:[],
				companyName:'',
				tenantId:'',
				voindex:0,
				videoflag:'false'
			}
		},
		components: {
			luSwiper,
			luVideo,
			popUp,
			noData,footers
		},
		onUnload() {
			clearInterval(this.timefn)
			if (this.teacherClass && this.teacherClass.length > 0) {
				var idx = Number(this.checkclassidx) || 0;
				var newArr = this.teacherClass || [];
				var newstr = newArr[idx]
				var newobj = {
					classId: newstr.classId,
					schoolId: newstr.schoolId,
					discipline: newstr.discipline,
					schoolName: newstr.schoolName,
				}
				// 修改储存的schoolId
				this.$store.dispatch('checkClass', newobj).then(() => {
					
				}).catch(() => {
				 
				})
				uni.setStorageSync('checkclass', JSON.parse(JSON.stringify(newobj)))
			}
		},
		onLoad: function() {
			this.loadflag = true;
			this.getptenantList()
			this.getClassFn();
			uni.getSystemInfo({
				success: (e) => {
					this.tops = Number(e.statusBarHeight);
				}
			})
			var that=this;
			this.userrolesarr=this.$store.state.user.roles;
			this.getconfigKeyFn()
		},
		onPullDownRefresh: function() {
			this.reachflag = true;
			this.pageNum = 1;
			this.list = [];
			clearInterval(this.timefn)
			this.getClassFn();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onShow: function() {
			var scrollTop=this.scrollTop;
			if (scrollTop > 0) {
				this.backgroundColor = '#c4defb'
			} else {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 0
				})
				this.backgroundColor = 'transparent'
			}
			
			return
			// 判断角色是否一样
			if (!this.loadflag) {
				var choseroles = this.$store.state.user.choseroles;
				if (this.roles && choseroles && this.roles != choseroles) {
					clearInterval(this.timefn)
					this.getClassFn()
				} else {
					var newArr=this.$store.state.user.refreshflag
					if(newArr&&newArr.length){
						if(newArr[0]){
							clearInterval(this.timefn)
							this.getClassFn()
							newArr[0]=false
							this.$store.dispatch('checkRefresh', newArr).then(() => {
								
							}).catch(() => {
							 
							})
							return
						}
					}
					if (choseroles != 'parents') {
						this.init()
					}
					if (choseroles == 'teacher') {
						this.getConfigKey()
					}

				}
			}
			
			var that=this;
			if(that.setflag){
				that.setflag=false;
				// #ifndef H5
				self.getLocation(function(res){
					if(res==-1){
						that.setflag=true
					}else{
						that.getAdrinfoFn(res)
						// that.location = `${res.lng},${res.lat}`
						// that.address=res.city;
					}			
				})
				// #endif
			}else{
				// this.location = `${self.__CFG.lng},${self.__CFG.lat}`
				// this.address=self.__CFG.city;
			}
		},
		onReachBottom() {
			if (this.reachflag && this.pageNum != 1) {
				this.pageNum++
				this.getDataFn()
			}
		},
		methods: {
			checkPermi,
			checkRole,
			getconfigKeyFn(){
				getconfigKeyFn('sys.video.player').then(res=>{
					if(res.code==200){
						this.videoflag=res.msg
					}
				})
			},
			bindDateChangea(e){
				var val=e.detail.value;
				var id=this.voList[val].dictValue
				this.companyName=this.voList[val].dictLabel;
				if(id!=this.tenantId){
					this.tenantId=id
					gettenantCheck(id).then(res=>{
						this.getClassFn();
						// 刷新其余的页面
						var newArr=[false,true,true,true,true]
						this.$store.dispatch('checkRefresh', newArr).then(() => {
							
						}).catch(() => {
						 
						})
					})
				}
				
			},
			getptenantList(){
				getptenantList().then(res=>{
					if(res.code==200){
						if(res.data.voList&&res.data.voList.length){
							this.voList = res.data.voList.map(v => {
								return {
									dictLabel: v.companyName,
									dictValue: v.tenantId
								}
							})
						}
						
					}else{
						this.$toast(res.msg)
					}
				})
			},
			getScoreFn() {
				this.$tab.navigateTo('/mine/pages/release/scorelist')
			},
			getPay(){
				// 学校看列表
				var roles=this.roles;
				if(roles=='school'){
					this.$tab.navigateTo('/mine/pages/payslip/paylist')
				}else if(roles=='teacher'){
					this.$tab.navigateTo('/mine/pages/payslip/index')
				}
				
				//老师看详情
				
			},
			//意见反馈
			getopinion(){
				this.$tab.navigateTo('/mine/pages/trends/addopinion')	
			},
			getWebview(){
				var url='https://ai.cnzxy.cn/room/67'
				uni.navigateTo({
					url:'/pages/common/webview/index?url='+encodeURIComponent(url)
				})
			},
			getAdrinfoFn(res){
				
				var params={
					address:res.address,
					longitude:res.lng,
					latitude:res.lat,
				}
				getAdrinfo(params).then(res=>{
				})
			},
			getRoleFn(type,idx){
				var that=this;
				that.rolesidx=Number(idx)<that.userrolesarr.length-1?Number(idx)+1:0;
				var userroles=this.$store.state.user.userroles;
				Object.keys(userroles).some((key) => {
					if (userroles[key].roleKey == ('' + type)) {
						that.$store.dispatch('checkRole', userroles[key]).then(() => {
						   that.getClassFn()
						   uni.pageScrollTo({
						   	scrollTop: 0,
						   	duration: 0
						   })
						}).catch(() => {
						 
						})
						return true;
					}
				})
			},
			gettoStuFn() {

			},
			getRelease() {
				this.$tab.navigateTo('/mine/pages/release/index')
			},
			getStuFn() {
				this.$tab.navigateTo('/mine/pages/files/student')
			},
			getTeaFn() {
				this.$tab.navigateTo('/mine/pages/files/teacher')
			},
			getTiaoFn() {
				this.$tab.navigateTo('/work/pages/examine/tkcourse')
			},
			getSecoreFn(id) {
				this.$tab.navigateTo('/work/pages/news/secure?type='+id)
			},
			getMindFn() {
				this.$tab.navigateTo('/mine/pages/files/mindlist')
			},
			getFanFn(){
				this.$tab.navigateTo('/mine/pages/mine/limit')
			},
			getYuyueFn(){
				this.$tab.navigateTo('/work/pages/order/index')
			},
			getMenuFn(){
				this.$tab.navigateTo('/work/pages/menu/list')
			},
			getLeaveFn() {
				this.$tab.navigateTo('/mine/pages/files/leavelist')
			},
			getHeighFn() {
				this.$tab.navigateTo('/mine/pages/files/heightlist')
			},
			getMore() {
				// 判断是否有第二节
				if (this.reachflag) {
					this.pageNum++
					this.getDataFn()
				}
			},
			getcheck(e) {
				if (this.checkidx == e) {

				} else {
					this.checkidx = e;
				}
				this.checkidxs = e;
				if (e == 2) { //准备放学
					this.timetype = 1;
					this.type = 1;
					this.timetit = this.ftimetit
					this.confdat = this.confdata
				} else { //延迟放学
					this.timetype = 2;
					// 延迟放学
					var obj = this.confdatb;
					this.timetit = this.ytimetit
					obj.txt = '是否确认延迟' + this.ytimetit + '分钟放学？'
					this.confdat = obj;
					this.type = 9;
				}

			},
			getConfigKey(e) {
				this.getConfigKeyf();
				this.getConfigKeyy();



				//e  是classid
				//"configType":"1:准备下课 2:延迟下课"
				// var params={
				// 	configType:this.timetype,
				// 	configKey:this.classId
				// }
				// //班级id
				// // configType "1:准备下课 2:延迟下课",
				// getConfigKey(params).then(res=>{
				// 	if(res.code==200){
				// 		this.timetit=res.msg;
				// 	}else{
				// 		this.$toast(res.msg)
				// 	}
				// })

				// 
			},
			getConfigKeyf() {
				var params = {
					configType: 1,
					configKey: this.classId
				}
				//班级id
				// configType "1:准备下课 2:延迟下课",
				getConfigKey(params).then(res => {
					if (res.code == 200) {
						if (this.checkidx == 2) {
							this.timetit = res.msg;
						}
						this.ftimetit = res.msg;
					} else {
						this.$toast(res.msg)
					}
				})
			},
			getConfigKeyy() {
				var params = {
					configType: 2,
					configKey: this.classId
				}
				//班级id
				// configType "1:准备下课 2:延迟下课",
				getConfigKey(params).then(res => {
					if (res.code == 200) {
						this.ytimetit = res.msg;
						if (this.checkidx == 1) {
							this.timetit = res.msg;
						}
					} else {
						this.$toast(res.msg)
					}
				})
			},
			getinit() {
				// 放学时间
				getDictionaryFn('sys_time').then(res => {
					if (res.code == 200) {
						this.timelist = res.data.map(v => {
							return {
								dictLabel: v.dictLabel,
								dictValue: v.dictValue
							}
						})
					}
				})
			},
			getConfirm() {
				var params = {
					schoolId: this.schoolId,
					classId: this.classId
				}

				if (this.checkidx == 2) {
					params.type = 1
				} else {
					params.type = 2
				}
				getAppxiaKe(params).then(res => {
					if (res.code == 200) {
						// this.checkidx=this.checkidxs;
						// this.getConfigKey();
						this.$toast('放学成功')
						this.type = 0;
						this.init()
					}

				})
			},
			handleTime() {
				// this.getConfigKey()
				this.type = 3
			},
			// 延迟
			getyanKeyFn(str){
				var params = {
					schoolId: this.schoolId,
					classId: this.classId,
					xiakeTime:Number(str)
				}
				
				if (this.checkidx == 2) {
					params.type = 1
				} else {
					params.type = 2
				}
				// console.log(params)
				// return
				getAppxiaKe(params).then(res => {
					if (res.code == 200) {
						// this.checkidx=this.checkidxs;
						// this.getConfigKey();
						this.$toast('放学成功')
						this.type = 0;
						this.init()
					}
				
				})
			},
			getKeyFn() {
				var params = {
					'configKey': this.classId,
					'configValue': this.timetit,
					"configType": this.timetype
				}
				getupdConfigKey(params).then(res => {
					if (res.code == 200) {
						this.$toast('修改成功')
						this.type = 0;
					} else {
						this.$toast(res.msg)
					}
				})
			},
			getClose() {
				this.type = 0
			},
			gettimeFn() {
				var that = this;
				clearInterval(this.timefn)
				that.time();
				// var stime = this.shuatime
				that.timefn = setInterval(function() {
					// if (stime <= 1) {
					// 	that.shuiux()
					// 	stime = that.shuatime
					// }
					// stime = stime - 1;
					that.time();
				}, 1000);
			},
			time() {
				var date = new Date();
				var y = date.getFullYear();
				var m = date.getMonth() + 1;
				var d = date.getDate();
				var h = date.getHours();
				var min = date.getMinutes();
				var s = date.getSeconds();
				var week = date.getDay(); //获取当前星期X(0-6,0代表星期天)
				var weeks = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
				var yearStr = y + '-' + (m < 10 ? ('0' + m) : m) + '-' + (d < 10 ? ('0' + d) : d)
				var timeStr = (h < 10 ? ('0' + h) : h) + ':' + (min < 10 ? ('0' + min) : min) + ':' + (s < 10 ? (
					'0' + s) : s);
				this.kaTime = yearStr + ' ' + timeStr;
				// this.kaYear = y;
				// this.kaMonth = m < 10 ? "0" + m : m;
				// this.kaDay = d < 10 ? "0" + d : d;
				// this.kaWeek = week;
				// this.gettime = timeStr
			},
			init() {
				this.getApplet();
				this.getApplist()
				this.getTablenow();
			},
			timeinit() {
				this.gettimeFn();
				this.getTablenow();
				this.getinit();
				this.getConfigKey();
			},
			getcheckClass(idx) {
				var leng = Number(this.teacherClass.length) - 1;
				if (Number(idx) < leng) {
					this.checkclassidx++
				} else {
					this.checkclassidx = 0;
				}
				var newArr = this.teacherClass;
				var nidx = this.checkclassidx;
				var newstr = newArr[nidx]
				this.classId = newstr.classId;
				this.schoolId = newstr.schoolId;
				this.getTablenow()
				this.getConfigKey();
				// 请求新数据
			},
			getClassFn() {
				var that = this;
				this.$store.dispatch('GetInforoles').then(resd => {
					that.loadflag = false;
					if (resd.code == 200) {
						var roles = that.$store.state.user.choseroles;
						that.roles = roles;
						var res=resd.data;
						var idx=that.userrolesarr.indexOf(roles)
						that.rolesidx=idx<that.userrolesarr.length-1?Number(idx)+1:0;
						if (roles == 'teacher') {
							if (res.user && res.user.teacherClass && res.user.teacherClass.length) {
								var teacherClass=res.user.teacherClass;
								var newArrs = [];
								const map = new Map();
								that.teacherClass = teacherClass.filter(v => !map.has(v.classId) && map.set(v.classId, 1));
								if (uni.getStorageSync('checkclass')) {
									var newobja = JSON.parse(JSON.stringify(uni.getStorageSync('checkclass')))
									// 选择展示那个数据
									var newArr = that.teacherClass;
									var val = newobja.classId;

									var a = 0;
									Object.keys(newArr).some((key) => {
										if (newArr[key].classId == ('' + val)) {
											that.checkclassidx = key;
											a = 1;
											return true;
										}
									})
									if (a == 0) {
										var newstr = that.teacherClass[0];
										var newobj = {
											classId: newstr.classId,
											schoolId: newstr.schoolId,
											discipline: newstr.discipline,
											schoolName: newstr.schoolName,
										}
										that.checkclassidx = 0;
										that.classId = newobj.classId;
										that.schoolId = newobj.schoolId;
										that.$store.dispatch('checkClass', newobj).then(() => {
											
										})
										uni.setStorageSync('checkclass', JSON.parse(JSON.stringify(newobj)))
									} else {
										that.classId = newobja.classId;
										that.schoolId = newobja.schoolId;
									}
								} else {
									var newstr = that.teacherClass[0];
									var newobj = {
										classId: newstr.classId,
										schoolId: newstr.schoolId,
										discipline: newstr.discipline,
										schoolName: newstr.schoolName,
									}
									that.checkclassidx = 0;
									that.classId = newobj.classId;
									that.schoolId = newobj.schoolId;
									that.$store.dispatch('checkClass', newobj).then(() => {
										
									})
									uni.setStorageSync('checkclass', JSON.parse(JSON.stringify(newobj)))
								}
								that.dataflag = true;
								this.timeinit()
								that.init()
							} else {
								that.dataflag = false
								that.teacherClass =[];
							}
						} else if (roles == 'parents') {
							if (res.user && res.user.parentsStudent && res.user.parentsStudent.length) {

								var newArr = [];
								const map = new Map();
								newArr = res.user.parentsStudent.filter(v => !map.has(v.classId) && map.set(v.classId, 1));
								var newArrs = [];
								newArr.forEach(ite => {
									var schoolId = ite.schoolId;
									var classId = ite.classId;
									var params = {
										schoolId: schoolId,
										classId: classId
									}
									getTablenow(params).then(res => {
										if (res.code == 200) {
											ite.teacher = res.data.teacher;
											ite.subject = res.data.subject;
											ite.time = res.data.time;
											newArrs[newArrs.length] = JSON.parse(JSON.stringify(
												ite));
											that.parentsStudent = JSON.parse(JSON.stringify(
												newArrs));
											// this.tablenow=res.data
										} else {
											that.$toast(res.msg)


										}
									}).catch(r => {
										if (r == 500) {
											newArrs[newArrs.length] = JSON.parse(JSON.stringify(
												ite));
											that.parentsStudent = JSON.parse(JSON.stringify(
												newArrs));
										}
									})

								})
								that.dataflag = true;

								// var newstr=res.user.parentsStudent[0];
								// that.classId=newstr.classId;
								// that.schoolId=newstr.schoolId;

								// 分班级选择
								// this.timeinit()
							} else {
								that.dataflag = false
								that.parentsStudent=[]
							}
						} else {
							// 学校
							that.classId = '';
							that.schoolId = that.$store.state.user.deptId;
							that.init()
						}
					}

				})
			},
			getTablenow() {
				var params = {
					schoolId: this.schoolId,
					classId: this.classId
				}
				getTablenow(params).then(res => {
					if (res.code == 200) {
						this.tablenow = res.data
					} else {
						this.$toast(res.msg)
					}
				})
			},
			getApplet() {
				var params = {
					schoolId: this.schoolId,
					// classId:this.classId
				}
				getApplet(params).then(res => {
					if (res.code == 200) {
						this.allinfo = res.data
					} else {
						this.$toast(res.msg)
					}
				})
			},
			getApplist() {
				var params = {
					schoolId: this.schoolId,
					pageSize: this.pageSize,
					pageNum: this.pageNum,
				}
				getApplist(params).then(res => {
					if (res.code == 200) {
						if (res.data.length < this.pageSize) {
							this.reachflag = false
							this.wtdt = '到底了~';
						} else {
							var num = parseInt(res.data.length) + parseInt(this.pageSize) * parseInt(this.pageNum -
								1)
							if (num < res.total) {
								this.reachflag = true
								this.wtdt = '上拉加载更多'
							} else {
								this.reachflag = false
								this.wtdt = '到底了~';
							}
						}
						if (this.pageNum == 1) {
							this.list = res.data;
						} else {
							this.list = this.list.concat(res.data)
						}
					} else {
						this.$toast(res.msg)
					}
				})
			},
			getAppxiaKe() {

			},
		},
		onPageScroll(e) {
			var scrollTop = Number(e.scrollTop);
			this.scrollTop=scrollTop;
			if (scrollTop > 0) {
				this.backgroundColor = '#c4defb'
			} else {
				this.backgroundColor = 'transparent'
			}
		},
	}
</script>

<style lang="scss" scoped>
.home_top /deep/ .uni-navbar__placeholder{height: 0 !important;}
.hatop {position: relative;min-height: 419rpx;margin: 0 22rpx 0rpx;
	.bbg{width: 100%;height: 100%;position: absolute;right: 0;top: 0;bottom: 0;left: 0;z-index: -1;}
	.hatopa{box-sizing: border-box;padding: 58rpx 38rpx 44rpx 49rpx;display: flex;flex-direction: column;
		.hatime{font-style: italic;color: #215CEB;font-size: 30rpx;font-weight: bold;flex: 0 0 auto;}
		.hatit{font-size: 30rpx;color: #161616;display: flex;word-break: break-all;
			text{flex:0 0 auto;font-weight: bold;}
		}
		.checkimg{flex: 0 0 auto;margin-left: 12rpx;padding: 8rpx 12rpx;
			image{width: 28rpx;height: 24rpx;}
		}
		.haftime{display: flex;font-size: 28rpx;font-weight: bold;color: #161616;align-items: center;
		text{font-size: 32rpx;color: #215CEB;min-width: 36rpx;text-align: center;padding: 0 10rpx;box-sizing: border-box;display: inline-block;}
			image{width: 26rpx;height: 30rpx;margin-right: 18rpx;flex: 0 0 auto;}
		}
		.hafbtn{
			flex: 0 0 auto;display: flex;align-items: center;height: 56rpx;border-radius: 28rpx;width:288rpx;background-color: #E8EAEC;
			view{width:50%;display: flex;align-items: center;justify-content: center;font-size: 28rpx;font-weight: 500;color: #666666;height: 100%;
			image{width: 24rpx;height: 24rpx;margin-right: 6rpx;display: none;}
			&.act{background: linear-gradient(-37deg, rgba(22,80,229,0.96), rgba(68,138,255,0.96));border-radius: 28rpx;color: #ffffff;
				image{display: block;}
			}
			&.acts{background: #eb5663;border-radius: 28rpx;color: #ffffff;
				image{display: block;}
			}	
			}
			
		}
	}
}
.abg{width: 100%;height: 622rpx;z-index: -2;}
.w200{width: 400rpx;}




// 放学状态
.hsta{margin: 50rpx 32rpx 0;
	.hsta_t{margin-bottom: 39rpx;
		.hsta_tl{font-weight: bold;color: #161616;position: relative;
			.hline{position: absolute;bottom: -20rpx;width: 40rpx;height: 11rpx;left: 50%;margin-left: -20rpx;}
		}
	}
	.hsta_tm{padding: 30rpx 20rpx;box-sizing: border-box;
		.hsta_tmt{width: 48%;height: 140rpx;border-radius: 14rpx;display: flex;align-items: center;padding: 24rpx;box-sizing: border-box;
		image{flex: 0 0 auto;margin-left: 20rpx;}
		&.bg1{background: #EAEAF7;
			image{width: 84rpx;height: 98rpx;}
		}
		&.bg2{background:#F9EAE2;
			image{width: 86rpx;height: 94rpx;}
		}
		
		.hsta_tmta{flex: 1;font-size: 26rpx;
			.tit{font-size: 30rpx;font-weight: bold;margin-bottom: 20rpx;}
			text{display: inline-block;padding: 0 10rpx;min-width: 40rpx;box-sizing: border-box;}
		}
		}
		// 列表
		.htlist{display: flex;align-items: center;justify-content: space-between;margin-top: 30rpx;
			.htlistl{flex: 1;color: #9D9D9D;
				.line{display: inline-block;margin: 0 10rpx;}
			}
		}
	
	}
	.hmore{padding-top: 60rpx;font-size: 30rpx;font-weight: 500;text-align: center;
color: #AAAAAA;
		image{width: 24rpx;height: 22rpx;margin: 12rpx auto 0;}
	}
}
.pay_btn{min-width: 240rpx;height: 66rpx;flex: 0 1 auto;margin-left: 20rpx;overflow: hidden;
			font-size: 30rpx;font-weight: 500;color: #333432;
			image{width: 18rpx;height: 10rpx;margin-left: 20rpx;flex:0 0 auto;}
		}
// tab
.itab{background-color: #ffffff;border-radius: 14rpx;display: flex;flex-wrap: wrap;padding: 8rpx 0;margin:26rpx 32rpx;
	.tlist{display: flex;align-items: center;flex-direction: column;width: 25%;padding: 20rpx 0;flex:0 0 auto;position: relative;
		.image{width: 52rpx;height: 52rpx;margin-bottom: 20rpx;display: flex;align-items: center;justify-content: center;
			.ico1{width: 48rpx;height: 48rpx;}
			.ico2{width: 48rpx;height: 50rpx;}
			.ico3{width: 46rpx;height: 50rpx;}
			.ico4{width: 52rpx;height: 48rpx;}
			.ico5{width: 50rpx;height: 48rpx;}
			.ico6{width: 50rpx;height: 52rpx;}
			.ico7{width: 42rpx;height: 50rpx;}
			.ico8{width: 50rpx;height: 50rpx;}
		}
		view{font-size: 28rpx;font-weight: 500;color: #161616;}
		.cirbox{position: relative;}
		.cir{min-width: 20rpx;height: 20rpx;background: #FF2D4F;border-radius: 50%;font-size: 20rpx;font-weight: 500;
color: #FFFFFF;position: absolute;right: -6rpx;top: -6rpx;line-height: 20rpx;text-align: center;}
	}
}
.home_top{position: fixed;left: 0;right: 0;top: 0;padding:20rpx 36rpx 0;z-index: 2;}
.home_adr{display: flex;align-items: flex-start;padding-right: 200rpx;
	view{font-size: 30rpx;font-weight: 500;color: #161616;flex: 1;}
	image{width: 22rpx;height: 26rpx;margin-right:18rpx;box-sizing: border-box;margin-top: 6rpx;}
}
.home_check{display: flex;align-items: center;font-size: 30rpx;color: #333432;font-weight: 500;height: 88rpx;overflow: hidden;
	.check_btn{display: flex;align-items: center;line-height: 48rpx;margin-left: 10rpx;flex:0 0 auto;
		image{width: 26rpx;height: 22rpx;margin-right: 10rpx;}
		font-weight: 500;color: #333432;font-size: 28rpx;padding: 0 16rpx;background-color: #e7f3fe;height: 48rpx;border-radius: 24rpx;
	}
}
.scoreimg{width: 210rpx;height: 148rpx;position: fixed;right: 0;bottom: 120rpx;z-index: 1;}
</style>
