<!-- 统计报表 -->
<template>
	<view class="report">
		<view class="report-header">
			<view class="report-header-left" @click="typePicker = true">
				<u-icon name="arrow-down" color="#000" size="15"></u-icon>
				<text>{{ currentType.text }}</text>
			</view>
			<view class="report-header-right" v-if="currentType.value === 6">
				<view class="tab">
					<view class="tab-item" v-for="(item, index) in tabList" :key="index"
						:class="{'active': tabCur === item.value}" @click="tabClick(item)">{{ item.label }}</view>
				</view>
			</view>
			<view class="report-header-right" v-else>
				<uni-datetime-picker v-model="curDate" type="daterange" @change="dateChange">
					<u--text text="日期查询" color="#1767F2"></u--text>
				</uni-datetime-picker>
			</view>
		</view>
		<view class="report-content">
			<template v-if="currentType.value === 1">
				<TollCollectorPerformance :currentDate="curDate"/>
			</template>
			<template v-else-if="currentType.value === 2">
				<SectionBerth :currentDate="curDate"/>
			</template>
			<template v-else-if="currentType.value === 3">
				<ParkingReallyIncome :currentDate="curDate"/>
			</template>
			<template v-else-if="currentType.value === 4">
				<ArrearsReport :currentDate="curDate"/>
			</template>
			<template v-else-if="currentType.value === 5">
				<RevenueReport :currentDate="curDate"/>
			</template>
			<template v-else-if="currentType.value === 6">
				<ReallyReceivable :currentDate="curDate"/>
			</template>
			<template v-else-if="currentType.value === 7">
				<CheckWorkAttendance :currentDate="curDate"/>
			</template>
		</view>
		<!-- 报表类型 -->
		<u-picker :show="typePicker" :columns="typeList" @confirm="typeConfirm" @cancel="typePicker = false"></u-picker>
		<!-- 年 -->
		<u-picker :show="yearPicker" :columns="yearList" :defaultIndex="defaultYear" @confirm="yearConfirm"
			@cancel="yearPicker = false"></u-picker>
		<!-- 月 -->
		<u-picker :show="monthPicker" :columns="monthList" :defaultIndex="defaultMonth" @confirm="monthConfirm"
			@cancel="monthPicker = false"></u-picker>
		<!-- 日 -->
		<u-picker :show="dayPicker" :columns="dayList" :defaultIndex="defaultDay" @confirm="dayConfirm"
			@cancel="dayPicker = false"></u-picker>
	</view>
</template>

<script>
	import TollCollectorPerformance from './components/tollCollectorPerformance.vue'
	import SectionBerth from './components/sectionBerth.vue'
	import ParkingReallyIncome from './components/parkingReallyIncome.vue'
	import ArrearsReport from './components/arrearsReport.vue'
	import RevenueReport from './components/revenueReport.vue'
	import ReallyReceivable from './components/reallyReceivable.vue'
	import CheckWorkAttendance from './components/checkWorkAttendance.vue'
	export default {
		components: {
			TollCollectorPerformance,
			SectionBerth,
			ParkingReallyIncome,
			ArrearsReport,
			RevenueReport,
			ReallyReceivable,
			CheckWorkAttendance
		},
		data() {
			return {
				tabList: [{
						label: '年',
						value: 1
					},
					{
						label: '月',
						value: 2
					},
					{
						label: '日',
						value: 3
					}
				],
				currentType: {},
				tabCur: 1,
				typePicker: false,
				typeList: [[
					{
						text: '收费员业绩统计',
						value: 1
					},
					{
						text: '路段泊位统计',
						value: 2
					},
					{
						text: '停车场实收统计',
						value: 3
					},
					{
						text: '欠费统计',
						value: 4
					},
					{
						text: '营收统计',
						value: 5
					},
					{
						text: '应收实收分析',
						value: 6
					},
					{
						text: '考勤统计',
						value: 7
					}
				]],
				// 日期
				curDate: [],
				// 年
				yearPicker: false,
				yearList: this.getYearList(),
				defaultYear: [4],
				title: '2022年',
				// 月
				monthPicker: false,
				monthList: this.getMonthList(),
				defaultMonth: [],
				// 日
				dayPicker: false,
				dayList: this.getDayList(),
				defaultDay: []
			}
		},
		onShow() {
			this.currentType = this.typeList[0][0]
		},
		methods: {
			getYearList() {
				const date = new Date()
				const year = date.getFullYear();
				const list = [
					[]
				]
				for (let i = year - 4; i < year + 1; i++) {
					const obj = {
						text: i + '年',
						value: i
					}
					list[0].push(obj)
				}
				return list
			},
			getMonthList() {
				const date = new Date()
				const month = date.getMonth()
				const list = [
					[]
				]
				for (let i = 1; i < 13; i++) {
					const obj = {
						text: i + '月',
						value: i
					}
					list[0].push(obj)
				}
				setTimeout(() => {
					this.defaultMonth = [month]
				}, 1000)
				return list
			},
			getDayList() {
				const date = new Date()
				const year = date.getFullYear()
				const month = date.getMonth()
				const day = date.getDate()
				const dayLen = (new Date(year, month, 0)).getDate()
				const list = [
					[]
				]
				for (let i = 1; i < dayLen + 1; i++) {
					const obj = {
						text: i + '日',
						value: i
					}
					list[0].push(obj)
				}
				setTimeout(() => {
					this.defaultDay = [day - 1]
				}, 1000)
				return list
			},
			tabClick(item) {
				this.tabCur = item.value
				switch (item.value) {
					case 1:
						this.yearPicker = true
						break
					case 2:
						this.monthPicker = true
						break
					case 3:
						this.dayPicker = true
						break
				}
			},
			typeConfirm(e) {
				console.log(e)
				this.currentType = e.value[0]
				this.typePicker = false
			},
			dateChange(e) {
				console.log(e)
			},
			yearConfirm(e) {
				this.defaultYear = [e.indexs[0]]
				this.yearPicker = false
			},
			monthConfirm(e) {
				this.defaultMonth = [e.indexs[0]]
				this.monthPicker = false
			},
			dayConfirm(e) {
				this.defaultDay = [e.indexs[0]]
				this.dayPicker = false
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #1767F2;
		min-height: calc(100vh - 44px);
	}
</style>

<style lang="scss" scoped>
	@import './statisticalReport.scss';
</style>
