<template>
	<view class="content">
		<view class="container">
			<headers :titles="titles"><u-icon name="arrow-left" color="#fff" size="22"></u-icon></headers>
			<view class="time-bs">
				<view class="time-box" @click="showStartTime = true">{{form.startTime?form.startTime:'开始日期'}}</view>
				<view class="">-</view>
				<view class="time-box" @click="showEndTime = true">{{form.endTime?form.endTime:'结束日期'}}</view>
			</view>
			<view class="box_" v-for="item,index in listData">
				<view class="top-title">
					<view class="name_">{{item.staffName}}</view>
					<view class="price_">￥{{item.totalPayMoney}}</view>
				</view>
				<view class="time">{{item.startTime}}-{{item.endTime}}</view>
			</view>
			<u-datetime-picker :show="showStartTime" v-model="startTimeValue" mode="datetime" @confirm="clickStart"
				@close="showStartTime = false" @cancel="showStartTime = false"></u-datetime-picker>

			<u-datetime-picker :show="showEndTime" v-model="endTimeValue" mode="datetime" @confirm="clickEnd"
				@close="showEndTime = false" @cancel="showEndTime = false"></u-datetime-picker>

		</view>
	</view>
</template>

<script>
	import request from "../../utils/request";

	import headers from '../../components/header/headers.vue'

	export default {
		data() {
			return {
				titles: "交班记录",
				show: false,
				value1: Number(new Date()),
				listData: [],
				dateRange: [],
				startTime: "",
				endTime: "",
				startTimeValue: "",
				endTimeValue: "",
				showStartTime: false,
				showEndTime: false,
				form: {
					page: 1,
					pageSize: 10000,

					startTime: '',
					endTime: ''
				}
			}
		},
		onShow() {
			// this.actList = ["1", "1", "1", "1", "1", ]
			// this.status = "nomore" 底部刷新结束
			this.getIndexData()
		},
		onPullDownRefresh() {
			console.log("刷新");
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			// this.show = true
			setTimeout(() => {
				console.log("加载执行");
			}, 2000)
		},
		components: {
			headers
		},
		methods: {
			goback() {
				uni.navigateBack()
			},
			clickStartTime(e) {
				this.showStartTime = true
				console.log(123, e)
				// const date = new Date(timestamp);

			},
			clickEndTime(e) {
				this.showEndTime = true

			},
			clickStart(e) {
				console.log('123123', e)
				this.showStartTime = false
				this.form.startTime = this.formatDateToYYMMDDHHMM(new Date(e.value));

				this.getIndexData();

			},
			clickEnd(e) {
				this.showEndTime = false
				this.form.endTime = this.formatDateToYYMMDDHHMM(new Date(e.value));

				this.getIndexData();
			},


			// 获取销售数据
			getIndexData() {
				if (this.form.startTime && this.form.endTime) {
					this.form.params = {
						beginTime: this.form.startTime,
						endTime: this.form.endTime
					}
				}


				request({
					url: 'business/handoverRecord/queryByPage',
					method: 'get',
					params: this.form
				}).then((res) => {
					if (res.code == 200) {
						this.listData = res.data.records
					} else {
						uni.showToast({
							title: res.data,
							icon: "none"
						})
					}
				})
			},
			formatDateToYYMMDDHHMM(date) {
				const year = String(date.getFullYear()); // 获取两位数的年份
				const month = String(date.getMonth() + 1).padStart(2, '0'); // 获取月份，并确保是两位数
				const day = String(date.getDate()).padStart(2, '0'); // 获取日期，并确保是两位数
				const hours = String(date.getHours()).padStart(2, '0'); // 获取小时，并确保是两位数
				const minutes = String(date.getMinutes()).padStart(2, '0'); // 获取分钟，并确保是两位数

				// return `${year}/${month}/${day} ${hours}:${minutes}`;
				return `${year}/${month}/${day}`;
			}
		}
	}
</script>

<style scoped lang="scss">
	.content {
		background: #f8f8f8;
		// background: linear-gradient(180deg, #B2D2FC 0%, #B2D2FC 14%, rgba(255, 255, 255, 0.84) 24%, rgba(255, 255, 255, 0.84) 100%);
		height: 100vh;
	}

	.container {
		width: 100%;
		background: #f8f8f8;
		box-sizing: border-box;
		padding-top: 88px;
	}


	.box_ {
		width: 95%;
		background: #FFFFFF;
		border-radius: 8px;
		box-sizing: border-box;
		margin: 10px auto;
		box-sizing: border-box;
		padding: 15px;
	}

	.top-title {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.name_ {
		font-weight: bold;
		font-size: 16px;
		color: #333333;
	}

	.price_ {
		font-weight: bold;
		font-size: 16px;
		color: #0864E9;
	}

	.time {
		font-weight: 500;
		font-size: 14px;
		color: #333333;
		margin: 0px auto;
		margin-top: 15px;
	}

	.time-bs {
		width: 100%;
		box-sizing: border-box;
		background: #FFFFFF;
		padding: 15px;
		display: flex;
		align-items: center;
		justify-content: space-around;
	}

	.time-box {
		border: 1px solid #0864E9;
		box-sizing: border-box;
		padding: 5px 15px;
		border-radius: 8px;
		font-size: 14px;
		color: #333;
		display: flex;
		align-items: center;
		justify-content: center;
	}
</style>