<template>
	<view :style="{'padding-top':navHeight+ 'px'}">
		<header-nav>
			<view style="font-size:#333333 ;font-weight: 550;font-size: 14px;" class="term-name"
				@click="selectTermShow=true">
				<u-icon name="arrow-down-fill" style="margin-right: 5px;"></u-icon>{{term_name}}
			</view>
			<u-picker v-model="selectTermShow" mode="selector" :range="term_list" range-key="name"
				@confirm="changeTerm"></u-picker>
		</header-nav>
		<view class="u-flex user-box u-p-l-30 u-p-r-20 u-p-b-30 min-top">
			<view class="u-flex-1">
				<view class="u-font-18 u-p-b-20" style="font-size: 18px;font-weight: bold;">{{username.name}}</view>
				<view class="u-font-14 u-tips-color">
					{{username.department.name == '--' ? '超级管理员' : username.department.name}}
				</view>
			</view>
			<view class="u-m-l-10 u-p-10" @click="history">
				<view class="message">
					<u-icon name="bell-fill" class="notice-icon" size="28">
					</u-icon>历史消息
				</view>
			</view>
		</view>
		<view class="list">
			<view class="list-item" @click="laboratory" v-if="$transformAuth('100701')">
				<image src="../../static/image/mine/icon_1.png" mode="" class="icon"></image>
				<view class="text">
					实验室管理
				</view>
				<view class="right-icon">
					<u-icon name="arrow-right" class="notice-icon" size="28" color="#999999"></u-icon>
				</view>
			</view>
			<view class="list-item" @click="tutorial" v-if="$transformAuth('100205')|| $transformAuth('100207') || $transformAuth('100208')">
				<image src="../../static/image/mine/icon_2.png" mode="" class="icon"></image>
				<view class="text">
					调/停/补课审批记录
				</view>
				<view class="right-icon">
					<u-icon name="arrow-right" class="notice-icon" size="28" color="#999999"></u-icon>
				</view>
			</view>
			<view class="list-item" @click="record" v-if="$transformAuth('100103')|| $transformAuth('100101')||$transformAuth('100102')">
				<image src="../../static/image/mine/icon_3.png" mode="" class="icon"></image>
				<view class="text">
					开放预约记录
				</view>
				<view class="right-icon">
					<u-icon name="arrow-right" class="notice-icon" size="28" color="#999999"></u-icon>
				</view>
			</view>
			<view class="list-item" @click="userApproval"  v-if="$transformAuth('100301')">
				<image src="../../static/image/mine/icon_4.png" mode="" class="icon"></image>
				<view class="text">
					账号审批记录
				</view>
				<view class="right-icon">
					<u-icon name="arrow-right" class="notice-icon" size="28" color="#999999"></u-icon>
				</view>
			</view>
			<view class="list-item" @click="notice">
				<image src="../../static/image/mine/icon_5.png" mode="" class="icon"></image>
				<view class="text">
					通知公告
				</view> 
				<view class="right-icon">
					<u-icon name="arrow-right" class="notice-icon" size="28" color="#999999"></u-icon>
				</view>
			</view>
			<view class="list-item" @click="revisePass">
				<image src="../../static/image/mine/edit1.png" mode="" class="icon"></image>
				<view class="text">
					修改密码 
				</view>
				<view class="right-icon">
					<u-icon name="arrow-right" class="notice-icon" size="28" color="#999999"></u-icon>
				</view>
			</view>
			<view class="list-item" @click="logout">
				<image src="../../static/image/mine/icon_6.png" mode="" class="icon"></image>
				<view class="text">
					退出登录
				</view>
				<view class="right-icon">
					<u-icon name="arrow-right" class="notice-icon" size="28" color="#999999"></u-icon>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var app = getApp()
	export default {
		data() {
			return {
				pic: 'https://uviewui.com/common/logo.png',
				show: true,
				username: this.$store.state.vuex_user,
				is_monitor: false,
				is_polling: false,
				is_admin: false,
				navHeight: app.globalData.navHeight,
				term_name: '',
				selectTermShow: false,
				term_list: []
			}
		},
		onShow() {
			console.log(this.$store.state.vuex_user, 'this.$store.state.vuex_user')
			this.checkRole()
			this.term_name = this.vuex_term_name
		},
		onLoad() {
			this.getTermList()
		},
		methods: {
			//切换学期
			changeTerm(e) {
				let index = e[0]
				console.log(index, '---------')
				let data=this.term_list[index]
				this.$u.vuex('vuex_term_name', data.name);
				this.$u.vuex('vuex_term_id', data.id)
				this.$u.vuex('vuex_term_weeks', data.weeks)
				uni.reLaunch({
					url:'/pages/mine/mine'
				})
			},

			//获取学期
			getTermList() {
				this.$u.get('/school/term-select-options', {
					status: 1
				}).then(res => {
					this.term_list = res.data
				})
			},
			//判断权限
			checkRole() {
				let status = false
				let roles = this.$store.state.vuex_user.roles
				let arr = []
				// roles.map(item => {
				// 	arr.push(item.name)
				// })
				let index = arr.indexOf('polling')
				if (index >= 0) this.is_polling = true
				let index2 = arr.indexOf('monitor')
				if (index2 >= 0) this.is_monitor = true
				let index3 = arr.indexOf('admin')
				if (index3 >= 0) this.is_admin = true
				console.log(index, index2, index3)

			},
			//修改密码
			changePwd() {
				uni.navigateTo({
					url: './changePwd'
				})
			},
			//分配历史
			fenpeiHistory() {
				uni.navigateTo({
					url: './history'
				})
			},
			//历史任务
			myTask() {
				uni.navigateTo({
					url: './myTask'
				})
			},
			//我的反馈
			feedBack() {
				uni.navigateTo({
					url: './fankui'
				})
			},
			//历史记录
			history() {
				uni.navigateTo({
					url: '/pages/laboratory/history'
				})
			},
			//实验室管理
			laboratory() {
				uni.navigateTo({
					url: '/pages/laboratory/manage'
				})
			},
			tutorial() {
				//调停补课记录
				uni.navigateTo({
					url: '/pages/record/tutorialRecord'
				})
			},
			userApproval() {
				//账号审批记录
				uni.navigateTo({
					url: '/pages/record/userApproval'
				})
			},
			//通知公告
			notice() {
				uni.navigateTo({
					url: '/pages/mine/notice'
				})
			},
			//开放预约记录
			record() {
				uni.navigateTo({
					url: '/pages/record/reserve'
				})
			},
			revisePass() {
				//修改密码
				uni.navigateTo({
					url: '/pages/mine/revisePass'
				})
			},
			//退出登录
			logout() {
				this.$u.get('/auth/logout').then(res => {
					this.$u.toast('修改成功请重新登陆')
					this.$u.vuex('vuex_token', '');
					this.$u.vuex('vuex_user', '');
					this.$u.vuex('vuex_id', '');
					uni.reLaunch({
						url: '/pages/login/login'
					})
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.user-box {
		padding-top: 15px;
		background-color: #fff;
		border-bottom: solid 1px #F2F2F2;

	}

	.term-name {
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	// .min-top {
	// 	border-bottom: solid 1px #F2F2F2;
	// }

	.message {
		display: inline-block;
		background-color: #3665FF;
		color: #FFFFFF;
		padding: 5px 10px;
		font-size: 12px;
		border-radius: 14px;
	}

	.list-item {
		display: flex;
		// height: 65px;
		// line-height: 65px;
		align-items: center;
		padding: 15px;
		font-size: 15px;

		font-weight: bold;
		border-bottom: solid 1px #F2F2F2;

		.text {
			flex: 1;
		}

		.icon {
			margin-right: 8px;
			height: 24px;
			width: 24px;
		}
	}
</style>
