<template>
	<u-cell-group>
		<u-cell title="开始时间" arrow-direction="down">
			<uni-datetime-picker :end="endTime" type="datetime" slot="value" v-model="reportForm.startTime"
				@change="starTimeChange">
			</uni-datetime-picker>
		</u-cell>
		<u-cell title="结束时间" arrow-direction="down">
			<uni-datetime-picker :start="starTime" type="datetime" slot="value" v-model="reportForm.endTime"
				@change="endTimeChange">
			</uni-datetime-picker>
		</u-cell>
		<u-cell title="时间售后时长(天)" arrow-direction="down">
			<view slot="value" style="display: flex;align-items: center;width: 100%;">
				<u--input readonly style="flex:1" border="surround" v-model="days">
				</u--input>
			</view>
		</u-cell>
		<u-cell title="时间售后时长(小时)" arrow-direction="down">
			<view slot="value" style="display: flex;align-items: center;width: 100%;">
				<u--input readonly style="flex:1" border="surround" v-model="hours">
				</u--input>
			</view>
		</u-cell>
		<u-cell title="时间售后时长(分钟)" arrow-direction="down">
			<view slot="value" style="display: flex;align-items: center;width: 100%;">
				<u--input readonly style="flex:1" border="surround" v-model="minutes">
				</u--input>
			</view>
		</u-cell>
	</u-cell-group>
</template>

<script>
	export default {
		data() {
			return {
				reportForm: {
					startTime: '',
					endTime: '',
					inFactDuration: ''
				},
				endTime: '',
				starTime: '',
				minutes: '',
				hours: '',
				days: ''
			}
		},
		methods: {
			getReportForm() {
				let data = {

				};
				return data;
			},
			// 开始时间
			starTimeChange(e) {
				this.starTime = e;
				this.reportForm.startTime = e;
				this.calculateTimeDifference()
			},
			// 结束时间
			endTimeChange(e) {
				this.endTime = e;
				this.reportForm.endTime = e;
				this.calculateTimeDifference();
			},
			calculateTimeDifference() {
				if (!this.reportForm.startTime || !this.reportForm.endTime) {
					this.days = '';
					this.hours = '';
					this.minutes = '';
					this.reportForm.inFactDuration = '';
					return
				}
				// 计算时间差
				const startTime = new Date(this.reportForm.startTime);
				const endTime = new Date(this.reportForm.endTime);
				const timeDiff = endTime - startTime; // 毫秒数
				// 转换为天、小时、分钟
				const minutes = timeDiff / (1000 * 60);
				const hours = minutes / 60;
				const days = hours / 24;
				this.reportForm.inFactDuration = minutes;
				this.minutes = minutes.toFixed(0) + ' 分钟';
				this.hours = hours.toFixed(1) + ' 小时';
				this.days = days.toFixed(1) + ' 天';
			},
		}
	}
</script>

<style>
</style>