<template>
	<view  class="container">
		<view>
			<view class="u-demo-block__content m-t-10">
				<view class="u-page__tag-item">
					<u-search @click="popupIsShow()"
						:show-action="false"
						shape="square"
						borderColor="rgb(230, 230, 230)"
						bgColor="#fff"
						placeholder="请选择"
						disabled
						v-model="searchmodel"
					></u-search>
				</view>
			</view>
			
		</view>
		
		<view >
			<u-subsection :current="tabIndex" :list="subsectionTitle" @change="thumbChange"></u-subsection>
		</view>
		
		<view id="scroll-post-list">
			<swiper :current="tabIndex" class="swiper-box" style="flex: 1;" :duration="300" @change="ontabchange" :style="'height: '+svHeight+'px;'">
				<swiper-item class="swiper-item" v-for="(tab,index1) in newsList" :key="index1">
					<scroll-view scroll-y="true" :style="'overflow: hidden; height: '+svHeight+'px;'"  @scrolltolower="loadMore(index1)">
						
						<uni-table ref="table" :loading="tab.isLoading" border stripe emptyText="暂无更多数据" v-if="index1 == 0" >
							<uni-tr>
									<uni-td width="65%" align="center">指标</uni-td>
									<uni-td width="10%" align="center">加分</uni-td>
									<uni-td width="10%" align="center">减分</uni-td>
									<uni-td width="10%" align="center">扣款(元)</uni-td>
									<uni-td width="10%" align="center">奖励(元)</uni-td>
							</uni-tr>
							
							<uni-tr v-for="item in newsList[index1].data" @row-click="evaluation(item)">
								
									<uni-td rowspan="1" align="center">{{item.title}}</uni-td>
									<uni-td rowspan="1" align="center">{{item.extrapoints}}</uni-td>
									<uni-td rowspan="1" align="center">{{item.scorereduction}}</uni-td>
									<uni-td rowspan="1" align="center">{{item.deduction}}</uni-td>
									<uni-td rowspan="1" align="center">{{item.reward}}</uni-td>
							</uni-tr>
							
						</uni-table>
						<uni-table ref="table" :loading="tab.isLoading" border stripe emptyText="暂无更多数据" v-if="index1 == 1" >
							<uni-tr>
									
									<uni-td align="center">指标</uni-td>
									<uni-td align="center">操作</uni-td>
							</uni-tr>
							<uni-tr v-for="item in newsList[index1].data" @row-click="evaluations(item)">
								
									
									<uni-td rowspan="1" align="center">{{item.title}}</uni-td>
									<uni-td rowspan="1" align="center" style="color: #3C9CFF;">提报</uni-td>
								
							</uni-tr>
						</uni-table>	
						<!-- <view class="loading-more"  v-if="tab.isLoading || tab.data.length > 4">
							<text class="loading-more-text">{{tab.loadingText}}</text>
						</view> -->
					</scroll-view>
					
				</swiper-item>
				
			</swiper>
		</view>
		
		
		
		<u-toast ref="uToast"></u-toast>
		
		<u-modal
			title="选择职员"
			:show="modalshow"
			showCancelButton
			buttonReverse
			@confirm="modalIsTrue"
			@cancel="() => modalshow = false"
		>
			<uni-table ref="table" :loading="loading" border stripe emptyText="暂无更多数据">
			
				<uni-tr>
					<uni-th  align="center">行政组织</uni-th>
					<uni-th align="center">岗位</uni-th>
					<uni-th  align="center">职员</uni-th>
				</uni-tr>
				<uni-tr>
					<uni-td style="padding: 0; vertical-align: top;">
						<uni-list-item :class="index==orgActive?'active':''" clickable  v-for="(orgItem,index) in orglist" :title="orgItem.title" @click="orgclick(orgItem,index)" />
					</uni-td>
					<uni-td style="padding: 0; vertical-align: top;">
						<uni-list-item :class="index==postActive?'active':''" clickable  v-for="(postItem,index) in postlist" :title="postItem.title" @click="postclick(postItem,index)" />
					</uni-td>
					<uni-td style="padding: 0; vertical-align: top;">
						<uni-list-item :class="index==userActive?'active':''" clickable v-for="(userItem,index) in userlist" :title="userItem.title" @click="userclick(userItem,index)" />
					</uni-td>
				</uni-tr>
				
			</uni-table>
			
			
				
			
		</u-modal>
	</view>
</template>

<script>
	
	export default {
		
		data() {
			return {
				svHeight:0, //元素的所需高度
				loading:false,
				headerVerify:{					//操作人基础信息
					userkey:"",
					token:"",
					userCont:"",
					userInfo:""
				},
				tabIndex:0,	//分段器
				subsectionTitle: ['定性考核', '定量考核'],		//分段器标题
				newsList: [],	//数据缓存
				search:{										//查询条件
					orgtitle:"",
					orgtid:"",
					posttitle:"",
					postid:"",
					usertitle:"",
					userid:""
				},
				searchmodel:"",
				modalshow:false,			//弹出层
				orglist:[]	,//行政组织
				postlist:[], //岗位
				userlist:[] ,//职员
				orgActive:0,
				postActive:0,
				userActive:0
			};
		},
		onLoad() {
			let _this = this
			//判断Token是否有效
			let systemCache = _this.$commonMethod.getSystemCacheDate('myCache')
			if(!systemCache){
				_this.$commonMethod.JumpUrl('/pages/login/login')
			}else{
				let currentTime = new Date().getTime() - systemCache.tokenTime
				if (currentTime >= 10800000){
					_this.$commonMethod.verifyPowerIsTrue('myCache')
				}
			}
			_this.headerVerify.userkey = systemCache.userKey
			_this.headerVerify.token = systemCache.token
			_this.headerVerify.userInfo = systemCache.userInfo
			_this.headerVerify.userCont = systemCache.userCont
			console.log(_this.headerVerify)
			this.getOrgList()
			//初始化数据
			_this.subsectionTitle.forEach(() => {
			    _this.newsList.push({
			        data: [],
					page:0,
			        isLoading: false,
			        refreshText: "",
			        loadingText: '加载更多...',
					loadingEnd:false
			    });
			});
		},
		onReady() {
			let _this=this;
			uni.getSystemInfo({
			    success: function(res) {
			        uni.createSelectorQuery().select("#scroll-post-list").boundingClientRect(function(data) {
			            _this.svHeight= (res.windowHeight - data.top);
			        }).exec();
			    }
			});
			 _this.loadData()
		},
		methods:{
			//分段器
			thumbChange(index){
				let _this = this
				this.tabIndex = index;
				// let date = this.newsList[index]
			},
			//弹出成
			popupIsShow(){
				this.modalshow = true
				this.getOrgList()
			},
			modalIsTrue(){
				let _this = this
				if(this.search.orgtitle != "" || this.search.posttitle != "" || this.search.usertitle != ""){
					this.searchmodel = this.search.orgtitle+"-"+this.search.posttitle+"-"+this.search.usertitle
				}
				_this.subsectionTitle.forEach(() => {
				    _this.newsList[_this.tabIndex].data=new Array
				});
				
				this.modalshow = false
				this.loadData()
				console.log("弹出成-----------》",_this.newsList)
			},
			//获取行政组织
			getOrgList(){
				let _this = this
				_this.orglist=[]	,//行政组织
				_this.postlist=[], //岗位
				_this.userlist=[] //职员
				uni.request({
					url:_this.$commonMethod.localhostUrl+'/hrapi/org/getorgallsun',
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
						// 'User-Agent':250,
						'user-key': _this.headerVerify.userkey,
						'user-token': _this.headerVerify.token
					},
					method:'POST',//请求方式，必须为大写
					data:{
						// group:_this.headerVerify.userCont.company,	//公司
						id:_this.headerVerify.userInfo.maindeparment,	//部门
						// tittle:"" //指标
					},
					success: (res) => {
						console.log(res)
						let callBackDate = res.data
						if(callBackDate.code == 0){
							let chartDate = callBackDate.data
							let orgID = 0
							if(chartDate != null && chartDate.length > 0){
								chartDate.forEach(item=>{
									if(orgID == 0){
										orgID = item.id
										_this.search.orgtid=item.id
										_this.search.orgtitle=item.name
									}
									let orgCont ={
										id:item.id,
										title:item.name,
									}
									_this.orglist.push(orgCont)
								})
							}
							if(orgID != 0){
								_this.getPostList()
							}
						}else{
							_this.$refs.uToast.show({
								message: callBackDate.msg,
								duration: 1000 * 1,
								position:'bottom',
							})
						}
					},
					fail:function(e){
						console.log('接口返回--login--2--',e);
						_this.$refs.uToast.show({
							message: e,
							duration: 1000 * 1,
							position:'bottom',
						})
					},
				})
			},
			//获取岗位
			getPostList(){
				let _this = this
				_this.postlist=[], //岗位
				_this.userlist=[] //职员
				uni.request({
					url:_this.$commonMethod.localhostUrl+'/hrapi/org/positionlist',
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
						// 'User-Agent':250,
						'user-key': _this.headerVerify.userkey,
						'user-token': _this.headerVerify.token
					},
					method:'POST',//请求方式，必须为大写
					data:{
						// group:_this.headerVerify.userCont.company,	//公司
						organization:_this.search.orgtid.toString(),	//部门
						page:1,
						pagesize:20000
					},
					success: (res) => {
						console.log(res)
						let callBackDate = res.data
						if(callBackDate.code == 0){
							let chartDate = callBackDate.data
							// console.log('接口返回--login--2--',chartDate);
							let postId = 0
							if(chartDate.list != null && chartDate.list.length > 0){
								chartDate.list.forEach(item=>{
									if(postId == 0){
										postId = item.id
										_this.search.postid=item.id
										_this.search.posttitle=item.name
									}
									let postCont ={
										id:item.id,
										title:item.name,
									}
									_this.postlist.push(postCont)
								})
							}
							if(postId != 0){
								_this.getUserList()
							}
						}else{
							_this.$refs.uToast.show({
								message: callBackDate.msg,
								duration: 1000 * 1,
								position:'bottom',
							})
						}
					},
					fail:function(e){
						console.log('接口返回--login--2--',e);
						_this.$refs.uToast.show({
							message: e,
							duration: 1000 * 1,
							position:'bottom',
						})
					},
				})
			},
			//获取员工
			getUserList(){
				let _this = this
				_this.userlist=[] //职员
				uni.request({
					url:_this.$commonMethod.localhostUrl+'/hrapi/staff/archiveslist',
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
						// 'User-Agent':250,
						'user-key': _this.headerVerify.userkey,
						'user-token': _this.headerVerify.token
					},
					method:'POST',//请求方式，必须为大写
					data:{
						page:1,
						pagesize:20000,
						adminorg:_this.search.orgtid,	//部门
						position:_this.search.postid
					},
					success: (res) => {
						console.log(res)
						let callBackDate = res.data
						if(callBackDate.code == 0){
							let chartDate = callBackDate.data
							// console.log('接口返回--login--2--',chartDate);
							let userId = 0
							if(chartDate.list != null && chartDate.list.length > 0){
								chartDate.list.forEach(item=>{
									if(userId == 0){
										userId = item.id
										_this.search.userid=item.keystr
										_this.search.usertitle=item.name
									}
									let userCont ={
										id:item.keystr,
										title:item.name,
									}
									_this.userlist.push(userCont)
								})
							}
							
							
						}else{
							_this.$refs.uToast.show({
								message: callBackDate.msg,
								duration: 1000 * 1,
								position:'bottom',
							})
						}
					},
					fail:function(e){
						console.log('接口返回--login--2--',e);
						_this.$refs.uToast.show({
							message: e,
							duration: 1000 * 1,
							position:'bottom',
						})
					},
				})
			},
			//单击行政组织获取职员
			orgclick(data,ind){
				this.search.orgtid=data.id
				this.search.orgtitle=data.title
				this.orgActive=ind
				this.userActive=0
				this.postActive=0
				this.getPostList()
			},
			//单击选择岗位
			postclick(data,ind){
				this.search.postid=data.id
				this.search.posttitle=data.title
				this.postActive=ind
				this.getUserList()
				this.userActive=0
			},
			//选择人员
			userclick(data,ind){
				this.search.userid=data.id
				this.search.usertitle=data.title
				this.userActive=ind
			},
			//页面切换
			ontabchange(e) {
				let _this = this
			    let index = e.target.current || e.detail.current;
			    // this.switchTab(index);
				console.log(index)
				this.tabIndex = index
				if(!this.newsList[index].loadingEnd){
					this.loadData()
				}
			},
			//触底执行
			loadMore(e) {
				let _this = this
				_this.newsList[e].isLoading = true
			   console.log(e,"上拉加载")
			   if(!_this.newsList[e].loadingEnd){
				   _this.loadData()
			   }
			},
			//加载数据
			loadData(){
				let _this = this
				if(_this.search.userid == ""){
					return
				}
				let getUrl = _this.$commonMethod.localhostUrl+'/kpiapi/postweb/getpostnature'
				if(_this.tabIndex > 0){
					getUrl = _this.$commonMethod.localhostUrl+'/kpiapi/postweb/getpostration'
				}
				uni.request({
					url:getUrl,
					header: {
						'Content-Type': 'application/json', //自定义请求头信息
						// 'User-Agent':250,
						'user-key': _this.headerVerify.userkey,
						'user-token': _this.headerVerify.token
					},
					method:'POST',//请求方式，必须为大写
					data:{
						id:_this.search.userid
					},
					success: (res) => {
						console.log(res)
						let callBackDate = res.data
						if(callBackDate.code == 0){
							let chartDate = callBackDate.data
							
							let activeTab = _this.newsList[_this.tabIndex]
							activeTab.loadingEnd = true
							activeTab.isLoading = false
							activeTab.page++
							activeTab.data = activeTab.data.concat(chartDate);
							console.log(activeTab,chartDate)
						}else{
							_this.$refs.uToast.show({
								message: callBackDate.msg,
								duration: 1000 * 1,
								position:'bottom',
							})
						}
					},
					fail:function(e){
						console.log('接口返回--login--2--',e);
						_this.$refs.uToast.show({
							message: e,
							duration: 1000 * 1,
							position:'bottom',
						})
					},
				})
			},
			//考评
			evaluation(data){
				let _this = this
				console.log("定性考核---------->",data)
				_this.$commonMethod.JumpUrl('/pages/jobposition/postnature?search='+JSON.stringify(_this.search)+'&data='+JSON.stringify(data))
				
			},
			evaluations(data){
				let _this = this
				console.log("定量考核---------->",data)
				_this.$commonMethod.JumpUrl('/pages/jobposition/rationment?search='+JSON.stringify(_this.search)+'&data='+JSON.stringify(data))
			}
			
			
			
			
		}
	}
</script>

<style lang="scss">
	.u-page__tag-item {
		@include flex(column);
		flex: 1,
	}

	.m-t-10 {
		margin-bottom: 2px;
	}
	.tabs {
	    flex: 1;
	    flex-direction: column;
	    overflow: hidden;
	    background-color: #ffffff;
	    /* #ifndef APP-PLUS */
	    height: 88vh;
	    /* #endif */
		/* height: calc(100% - 60px); */
		/* height: 100%; */
	}
	.swiper-box{
		/* height: 100%; */
		height: calc(100% - 160px);
	}
	.demo-uni-col{
		text-align: center;
		line-height: 35px;
	}
	.example-body{
		width: 100%;
		border-top:1px solid #DDDDDD;
	}
	.demo-uni-row{
		width: 100%;
		border-left: 1px solid #DDDDDD;
		border-right: 1px solid #DDDDDD;
		
	}
	
	.light{
		border-left: 1px solid #DDDDDD;
		border-right: 1px solid #DDDDDD;
		border-bottom:1px solid #DDDDDD;
		// border: 1px solid #DDDDDD;
	}
	.dark{
		border-bottom:1px solid #DDDDDD;
	}
	.darkes{
		border-right: 1px solid #DDDDDD;
		border-left: 1px solid #DDDDDD;
	}
	.darkes .active{
		background-color: #449FF4;
		color: #ffffff;
	}
	.lightes{
		border-left: 1px solid #DDDDDD;
	}
	.chat-custom-text{
		color: #ffffff;
	}
	.uni-list-item.active{
		background-color: #CCFFFF;
	}
</style>
