<template>
<div>
    <header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">选择班次</h1>
			<a class=" mui-icon mui-icon-left-nav mui-pull-left" @click="back"></a>
			<a class="mui-btn mui-pull-right mui-btn-blue" @click="ok">确认</a>
		</header>
		<div class="mui-content">
			<form class="mui-input-group mt-10">
				
				<div class="mui-input-row mui-checkbox" v-for="item,i in recordList" :key="i" >
					<label>{{item.name}}</label>
					<input name="checkbox1" v-model="ids" :value="item.id" type="checkbox">
				</div>
			 
			</form>
		</div>	<loading :visible="isLoading"></loading>
</div>
</template>


<script>
 
	import * as API from '@/apis-xsy/applyclass'
 
	import Loading from '$project/components/Loading.vue'
	 

	export default {
		name: '',
		components: {
 
			Loading,
	 
		},
		data() {
			return {
				ids:[],
				names:[],
				isLoading: false,
				old:[],
				listForm: {
					pageIndex: 1,
					pageSize: 20,
					totalPage: 1,
				},
				recordList: [],
			}
		},
		created() {
			

		},
		methods: {
			back(){
					this.ids=this.old;
				this.$emit("confirm",{status:0})
			},
			ok(){
				this.old=this.ids;
				this.names=[];
				for (var i in  this.recordList){
					var obj=this.recordList[i]
					for(var j in this.ids){
						if(this.ids[j]==obj.id){
							this.names.push(obj.name);
						}
					}
				}
				
				this.$emit("confirm",{status:1,id:this.ids.join(","),name:this.names.join("<br/>")})
			},
		 
			getOwnerCompanyShift(){
					this.isLoading = true;
				
				API.ownerCompanyShift(this.listForm).then(response => {
					if (response) {
						if (this.listForm.pageIndex == 1) {
							this.recordList = response.data;
							this.listForm.pageIndex = response.pageNumber;
							this.listForm.totalPage = response.totalPage;
						} else {
							this.recordList = [
								...this.recordList,
								...response.data
							];
						}
					}
					this.listForm.pageIndex++;
					this.isLoading = false;
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},	//下拉事件
			handleScrool() {
				if (isReachBottom()) {
					console.log('到达底部')
					if (this.listForm.pageIndex <= this.listForm.totalPage && this.isLoading == false) {
						this.getList();
					} else {
						return;
					}
				}
			},
			asynCallBack() {

			},
		
		},
		mounted() {
			this.getOwnerCompanyShift();
			//console.log("mounted")
			var _this = this;
				window.addEventListener('scroll', _this.handleScrool);
			
		},
		destroyed() {
			//销毁监听事件
				var _this = this;
				window.removeEventListener('scroll', _this.handleScrool);
			
		},
	
	}
</script>

<style src="$project/assets/css/iconfont.css"></style>
<style scoped src="$project/assets/css/xpwyfyy.css"></style>
<style src="$project/assets/css/xsy.css"></style>
<style>
</style>
