<template>
	<view class="">
		<StatSingleData ref="workTotalObj" :total-num="totalNum" :total-money="totalMoney"></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 {
		getUserPerformance
	} 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: [],
        totalNum:0,
        totalMoney:0,
			}
		},
		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.getUserPerformance()


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

<style>
</style>
