<!-- 路段泊位统计 -->
<template>
	<view class="container">
		<view class="table">
			<!-- <view class="table-date" v-if="currentDate">{{ currentDate.join(' 至 ') }}</view> -->
			<view class="table-box">
				<TableRanking :loading="loading" :tableTh="tableTh" :tableData="tableData"
					@pageChange="pageChange" />
			</view>
		</view>
		<view class="total">
			<view>
				停车数量<text>{{ totalData.vehicleCount || 0 }}</text>辆，实收金额<text>{{ totalData.realAmount || 0 }}</text>元
			</view>
		</view>
	</view>
</template>

<script>
	import TableRanking from '@/components/tableRanking.vue'
	export default {
		components: {
			TableRanking
		},
		props: {
			tableTh: {
				type: Array,
				default: () => {
					return [{
							field: '路段名称',
							key: 'roadName'
						},
						{
							field: '所属泊位',
							key: 'spaceName'
						},
						{
							field: '停车数量(次)',
							width: 80,
							key: 'vehicleCount'
						},
						{
							field: '实收金额(元)',
							width: 80,
							key: 'realAmount'
						}
					]
				}
			}
		},
		data() {
			return {
				beginTime: '',
				endTime: '',
				totalData: {},
				tableData: {
					current: 1,
					total: 0,
					list: []
				},
				currentDate: [],
				loading: false
			}
		},
		methods: {
			getData(data) {
				if (data.length) {
					this.beginTime = data[0]
					this.endTime = data[1]
				} else {
					this.beginTime = undefined
					this.endTime = undefined
				}
				this.currentDate = data
				this.tableData.current = 1
				this.getRoadSpaceTotal()
				this.getRoadSpaceList()
			},
			getRoadSpaceTotal() {
				uni.$u.api.statisticalReportApi.getRoadSpaceTotalApi({
					beginTime: this.beginTime,
					endTime: this.endTime
				}).then(res => {
					if (res.code === 200) {
						this.totalData = res.data
					}
				})
			},
			getRoadSpaceList() {
				this.loading = true
				uni.$u.api.statisticalReportApi.getRoadSpaceListApi({
					beginTime: this.beginTime,
					endTime: this.endTime,
					pageNum: this.tableData.current,
					pageSize: 10
				}).then(res => {
					if (res.code === 200) {
						this.tableData.list = res.rows;
						this.tableData.total = res.total
					}
					this.loading = false
				})
			},
			/**
			 * 分页切换
			 * @param { Number } cur
			 */
			pageChange(cur) {
				this.tableData.current = cur
				this.getRoadSpaceList()
			}
		}
	}
</script>

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