<template>
	<div>
		<common @asynCallBack="asynCallBack"></common>
		<top-header :pageTitle="pageTitle"></top-header>


		<div class="mui-content vongi-hdsq">
			<div class="mui-slider-group">
				<ul class="mui-table-view">
					<li v-for="(item,index) in recordList" class="mui-table-view-cell">
						<router-link :to="{name:item.status=='-99'?'MasterBusinessTravelForm':'XsyApprovalInfo',query:{id:item.id,formId:'travelWork'}}">
							<div class="mui-media-body flew-sp">
								出差地点:{{item.destination}}
								<span class='mui-ellipsis mui-h6' v-text="item.startTime.substr(5)"></span>
							</div>
							<p class='mui-ellipsis'>出差事由:{{item.content}}</p>
							<p class='flew-sp flew-items'>
								出差天数:{{item.estimatedTime}}天
								<button class="mui-btn   mui-btn-outlined" :class="{'mui-btn-primary':item.status==0,
								'mui-btn-danger':item.status==2||item.status==3,
								'mui-btn-success':item.status==1||item.status==4}"   >{{item.statusN}}</button>
								
							</p>
						</router-link>
					</li>
				</ul>
			</div>
		</div>
		
		<NullList :remark="'暂无申请记录'" v-if="!recordList.length"></NullList>
		
		<div class="fyy-footer">
			<div class="bindfyy-btn" @click="goToForm"><button type="submit" class="mui-btn mui-btn-primary ">填写出差申请单</button></div>
		</div>

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

<script>
	import * as API_BusinessTravel from '@/apis/Master/business_travel'
	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: 'MasterBusinessTravelList',
		components: {
			Common,
			Loading,
			TopHeader,
			NullList
		},
		data() {
			return {
				pageTitle: '出差申请记录',

				isLoading: false,

				listForm: {
					type: '3',
					pageIndex: 1,
					pageSize: 20,
					totalPage: 1,
				},
				recordList: [],
			}
		},
		created() {},
		methods: {
			//获取列表
			getList() {
				this.isLoading = true;
				API_BusinessTravel.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;
					}
				}
			},
			//填写表单
			goToForm() {
				this.$router.push({
					name: 'MasterBusinessTravelForm'
				})
			},
			//获取状态颜色
			getColor(status) {
				var color = '';
				if (status == '0') {
					color = '#4fc5f7';
				} else if (status == '1') {
					color = '#55f868';
				} else if (status == '2') {
					color = '#fe616c';
				}
				return 'color:' + color + ';border-color:' + color + ';';
			},
			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',
			})
		},
	}
</script>

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