<template>
	<view class="pad-x120">
		<!-- 头部 -->
		<status-nav :ifReturn="false" navBarTitle="个人中心" :titleColor="titleColor" :backgroudColor="backgroudColor"></status-nav>
		<view class="content" v-if="isLoding">
			<!-- 个人简介 -->
			<view  class="sign-top my-top font24 color-white" :style="{'padding-top':statusHeight+50+'px'}">
				<image src="/static/my-bg.jpg" mode="aspectFill"></image>
				<view class="my-info">
					<view class="my-cover">
						<image :src="userInfo.headimgurl" mode="aspectFill"></image>
					</view>
					<view class="my-txt" v-if="userInfo.role!==2">
						<view class="font28">{{userInfo.nickname}}</view>
						<view class="font24" v-if="userInfo.real_name==''">{{userInfo.checking==1?'入职审核中':'普通用户'}}</view>
						<view class="font24" v-else>{{userInfo.real_name}}</view>
					</view>
					<view class="my-txt" v-else>
						<view class="font28">{{userInfo.nickname}}</view>
						<view class="font24">负责人</view>
					</view>
				</view>
			</view>
			<!-- 其他信息 -->
			<view class="sign-record my-more">
				<view class="item bg-white" v-if="showList.indexOf(index)!==-1" @tap="toMore(item.url)" v-for="(item,index) in myMoreList" :key="index">
					<view class="img">
						<image :src="item.icon" :style="{'width':item.iconWidth+'rpx','height':item.iconHeight+'rpx'}" mode="aspectFit"></image>
					</view>
					<view class="txt font28">{{item.title}}</view>
					<image src="/static/icon/icon-arrow-03.png" mode="aspectFit"></image>
				</view>
			</view>
			<!-- 离职申请弹窗 -->
			<view class="pop-up-bg" v-if="showApply">
				<view class="sign-cate apply-pop bg-white">
					<view class="title apply-title font34" style="border-bottom: 0; padding-bottom: 0;">
						<image src="/static/icon/icon-apply.png" style="width: 94rpx; height: 90rpx;" mode="aspectFill"></image>
					</view>
					<view class="txt apply-txt font30" style="justify-content: center; text-align: center;">
						<text>
							请确认
							您是否真的要申请离职？
						</text>
					</view>
					<!-- 审核按钮 -->
					<view class="sign-cate-btns color-white font30">
						<view class="btn" @tap="showApply=false">取消</view>
						<view class="btn" @tap="submitEv">确认</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 尾部 -->
		<tabbar :userType="userType" current="2"></tabbar>
	</view>
</template>
<script>
	import tabbar from '@/components/tabbar/tabbar';
	export default {
		components:{
			tabbar
		},
		data() {
			return {
				statusHeight:uni.getSystemInfoSync().statusBarHeight, //状态栏高度
				userType:'', //账户类型 工人：worker 负责人：director
				frontColor:'#ffffff', //状态栏文字颜色
				backgroudColor:'none', //导航栏背景
				titleColor:'#ffffff', //导航栏颜色
				userInfo:{}, //用户信息
				myMoreList:[], //更多列表
				isLoding:false, //是否加载完成
				showApply:false ,//是否显示离职申请
				showList:[], //展示数组
			}
		},
		onPageScroll(object){
			if(object.scrollTop >= 5){
				this.frontColor = '#000000';
				this.backgroudColor = '#ffffff';
				this.titleColor = '#3333333';
				// 改变状态栏
				this.changeStatusNav();
			}
			if(object.scrollTop <= 0){
				this.frontColor = '#ffffff';
				this.backgroudColor = 'none';
				this.titleColor = '#ffffff';
				// 改变状态栏
				this.changeStatusNav();
			}
		},
		onLoad(op) {
			if(op.userType!==''){
				this.userType = op.userType;
				if(op.userType=='worker'){
					this.myMoreList = [
						{title:'个人资料',url:'/pagesA/information/information',icon:'/static/icon/icon-my-01.png',iconWidth:32,iconHeight:32},
						{title:'打卡记录',url:'/pagesA/signRecord/signRecord?userType=worker',icon:'/static/icon/icon-my-02.png',iconWidth:30,iconHeight:30},
						{title:'工资记录',url:'/pagesA/wagesRecord/wagesRecord',icon:'/static/icon/icon-my-03.png',iconWidth:30,iconHeight:30},
						{title:'加班记录',url:'/pagesA/overtimeRecord/overtimeRecord',icon:'/static/icon/icon-my-04.png',iconWidth:32,iconHeight:32},
						{title:'员工手册',url:'/pagesA/singlePage/singlePage?type=manual',icon:'/static/icon/icon-my-05.png',iconWidth:31,iconHeight:29},
						{title:'安全告知',url:'/pagesA/singlePage/singlePage?type=security',icon:'/static/icon/icon-my-06.png',iconWidth:28,iconHeight:36},
						{title:'入职申请',url:'workerApply',icon:'/static/icon/icon-my-11.png',iconWidth:33,iconHeight:33},
						{title:'离职申请',url:'auitApply',icon:'/static/icon/icon-my-07.png',iconWidth:31,iconHeight:31},
						{title:'公告',url:'/pagesA/singlePage/singlePage?type=notice',icon:'/static/icon/icon-my-08.png',iconWidth:28,iconHeight:30}
					]
				}
				if(op.userType=='director'){
					this.myMoreList = [
						{title:'个人资料',url:'/pagesA/information/information',icon:'/static/icon/icon-my-01.png',iconWidth:32,iconHeight:32},
						{title:'打卡记录',url:'/pagesA/signRecord/signRecord?userType=director',icon:'/static/icon/icon-my-02.png',iconWidth:30,iconHeight:30},
						{title:'工人列表',url:'/pagesB/worker/worker',icon:'/static/icon/icon-my-10.png',iconWidth:31,iconHeight:33},
						{title:'工人补卡确认',url:'/pagesB/repair/repair',icon:'/static/icon/icon-my-04.png',iconWidth:28,iconHeight:36},
						{title:'工人离职申请',url:'/pagesB/quitApply/quitApply',icon:'/static/icon/icon-my-09.png',iconWidth:33,iconHeight:33},
						{title:'公告管理',url:'/pagesB/notick/notick',icon:'/static/icon/icon-my-08.png',iconWidth:28,iconHeight:30}
					]
				}
			}
			// 改变状态栏
			this.changeStatusNav();
		},
		onShow() {
			// 获取用户信息
			this.getUserInfo();
		},
		methods: {
			// 改变状态栏
			changeStatusNav(){
				wx.setNavigationBarColor({
				  frontColor: this.frontColor,
				  backgroundColor: 'none',
				})
			},
			// 获取用户信息
			getUserInfo(){
				this.$requst.post('/api/v1/user/info').then(res=>{
					if(res.code==0){
						console.log(res,'用户信息');
						if(res.data.role!==uni.getStorageSync('worker_role')){
							this.$toolAll.tools.showToast('身份已变更，正在切换');
							setTimeout(()=>{
								uni.reLaunch({
									url:'/pages/pagehome/pagehome'
								})
							},2000)
						}
						uni.setStorageSync('baseWorksiteId',res.data.worksite_id)
						if(res.data.role==0){
							this.showList = [0,1,5,6,8];
						}
						if(res.data.role==1){
							this.showList = [0,1,2,3,4,5,7,8];
						}
						if(res.data.role==2){
							this.showList = [0,1,2,3,4,5];
						}
						this.userInfo = res.data;
						this.userInfo.headimgurl = res.data.headimgurl;
						this.isLoding = true;
					}
				})
			},
			//跳转页面
			toMore(url){
				if(url=='auitApply'){
					this.showApply = true;
				}else if(url=='workerApply'){
					if(uni.getStorageSync('worksite_id')){
						uni.navigateTo({
							url:'/pages/worker/sign/sign?userType=worker&apply=join'
						})
					}else{
						this.$toolAll.tools.showToast('不在可申请范围内');
					}
					
				}else{
					uni.navigateTo({
						url:url
					})
				}
			},
			
			// 确认离职
			submitEv(){
				this.$requst.post('/api/v1/worker/dimission').then(res=>{
					if(res.code==0){
						console.log(res,'用户信息');
						this.$toolAll.tools.showToast('离职申请提交成功');
						this.showApply = false;
					}else{
						this.$toolAll.tools.showToast(res.msg);
					}
				})
			}
		}
	}
</script>
<style scoped>
	
</style>