<!-- 收费员业绩统计 -->
<template>
	<view class="container">
		<view class="table">
			<view class="table-date" v-if="currentDate">{{ currentDate.join(' 至 ') }}</view>
			<view class="table-box">
				<TableRanking :loading="loading" :padding="'0'" :tableTh="tableTh" :tableData="tableData" @pageChange="pageChange"/>
			</view>
		</view>
		<view class="total">
			<view>
				应收金额<text>{{ totalData.payAmount || 0 }}</text>元，实收金额<text>{{ totalData.realAmount || 0 }}</text>元
			</view>
			<view>
				现金收入<text>{{ totalData.cashAmt || 0 }}</text>元，非现金收入<text>{{ totalData.otherAmt || 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: 'payeeNo'
						},
						{
							field: '姓名',
							key: 'payeeName'
						},
						{
							field: '所属路段',
							key: 'roadName'
						},
						{
							field: '应收金额(元)',
							key: 'payAmount',
							width: 80
						},
						{
							field: '实收金额(元)',
							key: 'realAmount',
							width: 80
						}
					]
				}
			}
		},
		data() {
			return {
				tableData: {
					current: 1,
					total: 0,
					list: []
				},
				totalData: {},
				beginTime: undefined,
				endTime: undefined,
				loading: false,
				currentDate: []
			}
		},
		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.getTollCollectorAchieveTotal()
				this.getTollCollectorAchieveList()
			},
			getTollCollectorAchieveTotal() {
				uni.$u.api.statisticalReportApi.getTollCollectorAchieveTotalApi({
					beginTime: this.beginTime,
					endTime: this.endTime
				}).then(res => {
					if (res.code === 200) {
						this.totalData = res.data
					}
				})
			},
			getTollCollectorAchieveList() {
				this.loading = true
				uni.$u.api.statisticalReportApi.getTollCollectorAchieveListApi({
					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
				})
			},
			pageChange(cur) {
				this.tableData.current = cur
				this.getTollCollectorAchieveList()
			}
		}
	}
</script>

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