<template>
	<view class="">
		<HeadData :money-data="moneyData"></HeadData>
		<StatLoanChart ref="outObj" :genre="1" :leftText="'放款汇总占比'"></StatLoanChart>
		<StatLoanChart ref="putObj" :genre="2" :leftText="'回款汇总占比'"></StatLoanChart>
		<stat_gather is_group is_subsection :leftText="'汇总明细'" :out-list="outList" :put-list="putList"></stat_gather>
		<view class="sys-background-fff r-30">
			<StatCapital :leftColor="0" :rightColor="1" :leftText="'任务资金汇总'" :tabulate-data="sysPassageData">
			</StatCapital>
			<view class="view_line"></view>
			<StatRanking ref="rankingObj" :is_margin_top="false" :is_type="2" :leftText="'个人业绩排行'"
				:data-list="userList"></StatRanking>
		</view>
		<StatSituation ref="situationObj" :date-type-obj="dateTypeObj" :type="1"></StatSituation>
	</view>
</template>

<script>
	import StatLoanChart from "../module/stat_loan_chart.vue"
	import StatRanking from "../module/stat_ranking.vue"
	import StatCapital from "../module/stat_capital.vue"
	import StatSituation from "../module/stat_situation.vue"
	import HeadData from "@/pages/statistics/module/head_data.vue";
	import {
		getDepartmentMoney,
		getRanking,
		getSysPassage
	} from "@/api/statistics";
	import md5 from "js-md5";
	import Stat_gather from "@/pages/statistics/module/stat_gather.vue";

	export default {
		props: {
			'dateTypeObj': {
				default: () => {
					return {
						dateType: 4,
						selectDate: '2023-02-25',
						money_type: 1,
						censusUserType: 0,
						product_id: 5,
					}
				}
			}
		},
		components: {
			Stat_gather,
			HeadData,
			StatLoanChart,
			StatRanking,
			StatCapital,
			StatSituation
		},
		watch: {
			'dateTypeObj': function() {
				this.initData()
			}
		},
		mounted() {
			this.initData()
		},
		data() {
			return {
				moneyData: {
					out_money: 0,
					out_num: 0,
					put_money: 0,
					put_num: 0,
				},
				outList: [],
				putList: [],
				sendMd5: '',
				sysPassageData: {
					consume_money: 0,
					consume_num: "0",
					consume_ratio: 0,
					pledge_money: 0,
					pledge_num: "0",
					pledge_ratio: 0,
					list: [{
						name: "",
						ratio: 0,
						value: 0,
						labelText: ""
					}, {
						name: "",
						ratio: 0,
						value: 0,
						labelText: ""
					}]
				},
				userList: []
			}
		},
		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.getDepartmentMoney(1)
						this.getDepartmentMoney(2)
						this.getSysPassage()
						this.setUserRanking()
						this.$refs.situationObj.startList()
					}
				}
			},
			//管理员-任务资金汇总
			getSysPassage() {
				getSysPassage(this.dateTypeObj).then((res) => {
					if (res.code === 1) {
						this.sysPassageData = res.data
					} else {
						// this.$refs.chartsPieView.setNoList()
					}
				})
			},
			getDepartmentMoney(money_type) {
				let selectData = this.dateTypeObj
				selectData.money_type = money_type
				getDepartmentMoney(selectData).then((res) => {
					if (res.code === 1) {
						if (money_type === 1) {
							this.moneyData.out_money = res.data.moneyData.loanMoney
							this.moneyData.out_num = res.data.moneyData.loanNum
							this.outList = res.data.items
							this.$refs.outObj.setPeakChartData(this.outList)
						} else {
							this.moneyData.put_money = res.data.moneyData.loanMoney
							this.moneyData.put_num = res.data.moneyData.loanNum
							this.putList = res.data.items
							this.$refs.putObj.setPeakChartData(this.putList)
						}
					}

				})
			},
			//设置员工排名
			setUserRanking() {
				let fromData = this.dateTypeObj
				fromData.pageNum = 3
				getRanking(fromData).then((res) => {
					if (res.code === 1) {
						this.userList = res.data.items
						console.log(this.userList)
						this.$refs.rankingObj.setDataList(this.userList)
					}
				})
			},
		},
	}
</script>

<style>
</style>