<template>
	<view class="clockInContainer">
		<uni-nav-bar @clickLeft="goBack()" height="110rpx" leftWidth="200rpx" leftText="打卡记录" leftIcon="left" border
			backgroundColor="#2cade8" color="#fff" fixed statusBar shadow></uni-nav-bar>
		<view class="tabbar-title">
			<view :class="{'text-title':true, 'active':activeIndex}" @click="changeList(1)">本月</view>
			<view style="display: flex;">
				<view>选择月份：</view>
				<picker mode="date" :value="date" fields="month"  @change="bindDateChange">
					<view class="uni-input">{{date}}</view>
				</picker>
			</view>
			
		</view>
		<view class="content">
			<view class="item-wrap" v-for="(val,index) in lists" :key="val.id">
				<view class="clock_in_-item">
					<view class="center-info">
						<view class="info-details">触发模式：{{val.detail.openTypeStr}}</view>
						<view class="info-details">打卡类型：<text v-if="val.type==10">上班打卡</text><text v-else>下班打卡</text></view>
						<view class="info-details">其他信息：{{val.detail.deviceName}}</view>
						<view class="info-details">打卡时间：{{val.update_time}}</view>
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		name: 'ticket',
		data() {
			return {
				params: {
					employee: '',
					pageSize: 10,
					pageNum: 1,
					month: '',
					year:''
				},
				totalNum: 0,
				activeIndex:true,//本月
				lists: [],
				currentMonth:'',
				currentYear:'',
				date:'选择其他月',
			}
		},
		//上拉加载
		onReachBottom() {
			const totalPage = Math.ceil(this.totalNum / this.params.pageSize);
			if (this.params.pageNum < totalPage) {
				this.params.pageNum += 1;

			} else {
				uni.showToast({
					title: "已全部加载",
					icon: 'none'
				})
			}
		},
		onShow() {
			let that = this;
			let now = new Date()
			var year = now.getFullYear(); // 年
			var month = now.getMonth() + 1; // 月
			if(month < 10) {
				month = '0' + month;
			}		
			that.params.month = that.currentMonth = month;
			that.params.year = that.currentYear = year;
			that.date = year+'-'+month;
			that.$u.api.hrmUserInfo().then(res => {
				if(res.err_msg){}else{
					that.params.employee = res.id;
					that.getLists();
				}
			})
			
		},
		//下拉刷新
		onPullDownRefresh() {
			this.params.pageNum = 1;
			this.lists = [];
			this.getLists();
		},
		methods: {
			bindDateChange(e){
				let that = this;
				that.date = e.target.value;
				that.params.month = that.date.split('-')[1];
				that.params.year = that.date.split('-')[0];
				let current = that.currentYear+'-'+that.currentMonth;
				if(that.date==current){
					that.activeIndex=true;
				}else{
					that.activeIndex=false;
				}
				that.params.pageNum = 1;
				that.lists = [];
				that.getLists();
			},
			getLists() {
				let that = this;
				that.$u.api.hrmClockRecord(that.params).then(res => {
					that.lists = that.lists.concat(res.results);
					that.totalNum = res.count;
				})
			},
			changeList(index){
				let that = this;
				that.activeIndex = index;
				that.params.month = that.currentMonth;
				that.params.year = that.currentYear;
				that.params.pageNum = 1;
				that.lists = [];
				that.getLists();
			},
			goBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			
		}
	}
</script>

<style scoped>
	.empty-view {
		height: 120rpx;
	}

	>>>.uni-navbar__header,
		>>>.uni-status-bar,
		.search-wrap {
			background-image: linear-gradient(270deg,
					#0ca7ee 0%,
					#005aff 100%,
					#2a8cff 100%,
					#54bdff 100%),
				linear-gradient(#e60012,
					#e60012);
		}
		
		.tabbar-title{
			display: flex;
			justify-content: space-between;
		}
	.clockInContainer {
		background-color: #f3fbff;
	}

	.clockInContainer>>>.uni-navbar-btn-text text {
		font-size: 32rpx !important;
	}

	.content {
		padding: 14rpx;
		padding-top: 10upx;
	}

	.item-wrap {
		margin-bottom: 14rpx;
	}

	.clock_in_-item {
		width: 720rpx;
		background-color: #ffffff;
		border-radius: 10rpx;
		margin: 0 auto;
		padding: 24rpx 21rpx;
		box-sizing: border-box;
	}

	.info-details {
		font-size: 28rpx;
		line-height: 40rpx;
		color: #5b5b5b;
	}

</style>
