<template>
	<div>

		<common @asynCallBack="asynCallBack"></common>
		<top-header :pageTitle="pageTitle" :routeName="'Master'"></top-header>

		<div class="mui-content">
			<div class="mui-content-padded vongi-work">
				<ul class="mui-table-view vongi-qingjia">
					<li class="mui-table-view-cell" v-for="mod in recordList" @click="detail(mod.id,mod.enableCancel,mod.status)">
						<h4>
							{{mod.title}}
							<span v-text="mod.createTime">12:00</span>
						</h4>
						 
						<button class="mui-btn   mui-btn-outlined" :class="{'mui-btn-primary':mod.status==0,
						'mui-btn-danger':mod.status==2||mod.status==3,
						'mui-btn-success':mod.status==1||mod.status==4}"  v-text="mod.enableCancel||mod.cancelStatus!=5?mod.mergeStatusN:mod.statusN"  ></button>
							
					</li>

				</ul>
			</div>
			<div class="fyy-footer">
				<div class="bindfyy-btn"><button type="submit" class="mui-btn mui-btn-primary " @click="save()">写请假条</button></div>
			</div>
		</div>
		<NullList :remark="'暂无请假记录'" v-if="!recordList.length"></NullList>


		<loading :visible="isLoading"></loading>

	</div>
</template>


<script>
	import * as API_Leave from '@/apis/Master/leave'
	import Common from '$project/components/Common.vue'
	import Loading from '$project/components/Loading.vue'
	import TopHeader from '$project/components/TopHeader.vue'
	import isReachBottom from '$project/utils/isReachBottom'
	import NullList from '$project/components/NullList.vue'

	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	export default {
		name: 'MasterAttendanceLeaveList',
		components: {
			Common,
			Loading,
			TopHeader,
			NullList
		},
		data() {
			return {
				pageTitle: '请假记录',

				isLoading: false,

				listForm: {
					pageIndex: 1,
					pageSize: 20,
					//	token: '',
					totalPage: 1,
					result: 0,
				},
				recordList: [],
				status: ['待审核', '已批准','已退回', '已拒绝','无需审批'],
			}
		},
		created() {
			//this.listForm.openId = this.openId;
			//this.listForm.result = this.$route.query.result != null ? this.$route.query.result : 0;
		},
		methods: {
			//info
			detail(id,bl,stauts) {
				if(stauts==-99){
					this.$router.push({
						name: 'MasterAttendanceLeaveForm',
						query: {
							id:id
						}
					})
				}else{
					var routeName="XsyApprovalInfo";
					
					this.$router.push({
						name: routeName,
						query: {
							id: id,
							formId:'leaveWork',
							opAction:bl
						}
					})
				}
				
			},
			save() {
				this.$router.push({
					name: 'MasterAttendanceLeaveForm',
					query: {

					}
				})
			},
			//获取列表
			getList() {
				this.isLoading = true;
				API_Leave.pageList(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.getList();
			//监控下拉加载事件
			var _this = this;
			window.addEventListener('scroll', _this.handleScrool);
		},
		destroyed() {
			//销毁监听事件
			var _this = this;
			window.removeEventListener('scroll', _this.handleScrool);
		},
		computed: {
			...mapGetters({
				openId: 'wx_openid',
				token: 'token',
			})
		},
		//keepalive监控判断
		beforeRouteLeave(to, from, next) {
			console.log(to.name);
			if (['MasterAttendanceLeaveInfo'].indexOf(to.name) > -1) {
				this.$store.commit('SET_KEEP_ALIVE_COMPONENTS', ['MasterAttendanceLeaveList'])
			} else {
				this.$store.commit('SET_KEEP_ALIVE_COMPONENTS', [])
			}
			next()
		},
	}
</script>

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