<template>
	<view class="">
		<StatSingleData :genre="1"></StatSingleData>
		<StatLoanChart ref="workChartObj" :leftText="'任务汇总占比'"></StatLoanChart>
		<StatRanking ref="workListObj" :is_type="3" :leftText="'任务明细'"></StatRanking>
	</view>
</template>

<script>
	import StatLoanChart from "../module/stat_loan_chart.vue"
	import StatRanking from "../module/stat_ranking.vue"
	import StatSingleData from "../module/stat_single_data.vue"
	import md5 from "js-md5";
	import {
		getUserWorkload
	} from "@/api/statistics";

	export default {
		props: {
			'dateTypeObj': {
				default: () => {
					return {
						dateType: 4,
						selectDate: '2023-02-25',
						money_type: 1,
						censusUserType: 0,
						product_id: 5,
					}
				}
			}
		},
		components: {
			StatLoanChart,
			StatRanking,
			StatSingleData
		},
		watch: {
			'dateTypeObj': function() {
				this.initData()
			}
		},
		mounted() {
			this.initData()
		},
		data() {
			return {
				workList: []
			}
		},
		methods: {
			setSendMd5() {
				let str = JSON.stringify(this.dateTypeObj)
				return md5(str)
			},
			initData() {
				if (this.dateTypeObj.censusUserType > 0) {
					let sendMd5 = this.setSendMd5()
					if (sendMd5 !== this.sendMd5) {
						this.sendMd5 = sendMd5
						this.getUserWorkload()

					}
				}
			},
			getUserWorkload() {
				getUserWorkload(this.dateTypeObj).then((res) => {
					if (res.code === 1) {
						this.$refs.workChartObj.setPeakChartData(res.data.items)
						this.$refs.workListObj.setDataList(res.data.items)
					}
				})
			},
		}
	}
</script>

<style>
</style>