<template>
	<view class="">
		<HeadData :money-data="moneyData"></HeadData>
		<stat_finance_chart :money-data="moneyData"></stat_finance_chart>
		<stat-finance ref="financeObj" :date-type-obj="dateTypeObj"></stat-finance>
		<view class="sys-background-fff r-30">
			<StatCapital :leftColor="0" :rightColor="1" :leftText="'任务资金汇总'" :tabulate-data="sysPassageData">
			</StatCapital>
			<view class="view_line"></view>
			<StatCapital :leftColor="1" :rightColor="2" :bgChartColor="['#2B7DFA','#ED9A2C']" :leftText="'在途资金汇总'"
				:tabulate-data="sysCapitalMoney">
			</StatCapital>
		</view>
		<stat-industry></stat-industry>
		<stat-age-chart ref="ageRef"></stat-age-chart>
	</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 {
		getSysCashier,
		getSysPassage,
		getCapitalMoney,
		getSysIndustry,
		getSysAge
	} from "@/api/statistics";
	import Stat_finance_chart from "@/pages/statistics/module/stat_finance_chart.vue";
	import StatFinance from "@/pages/statistics/module/stat_finance.vue";
	import md5 from 'js-md5'
	import StatIndustry from "@/pages/statistics/module/stat_industry.vue";
	import StatAgeChart from "@/pages/statistics/module/stat_age_chart.vue";

	export default {
		props: {
			'dateTypeObj': {
				default: () => {
					return {
						dateType: 4,
						selectDate: '2023-02-25',
						money_type: 1,
						censusUserType: 0,
						product_id: 5,
					}
				}
			}
		},
		components: {
			StatAgeChart,
			StatIndustry,
			StatFinance,
			Stat_finance_chart,
			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,
				},
				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: ""
					}]
				},
				sysCapitalMoney: {
					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: ""
					}]
				},
				industryList: {},
				ageList: {},
				sendMd5: ''
			};
		},
		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.getSysCashier()
						this.getSysPassage()
						this.getCapitalMoney()
						this.getSysIndustry()
						this.getSysAge()
            this.$refs.financeObj.startList()
					}
				}
			},
			getSysCashier() {
				getSysCashier(this.dateTypeObj).then((res) => {
					if (res.code === 1) {
						this.moneyData = res.data
					}
				})
			},
			//管理员-任务资金汇总
			getSysPassage() {
				getSysPassage(this.dateTypeObj).then((res) => {
					if (res.code === 1) {
						this.sysPassageData = res.data
					} else {
						// this.$refs.chartsPieView.setNoList()
					}
				})
			},
			//管理员-在途资金汇总
			getCapitalMoney() {
				getCapitalMoney(this.dateTypeObj).then((res) => {
					if (res.code === 1 && res.data.items.length > 0) {
						let totalMoney = res.data.items[0].value + res.data.items[1].value
						this.sysCapitalMoney.consume_money = res.data.items[0].value
						this.sysCapitalMoney.consume_num = res.data.items[0].total_num
						this.sysCapitalMoney.consume_ratio = (res.data.items[0].value / totalMoney * 100).toFixed(
							2)
						this.sysCapitalMoney.pledge_money = res.data.items[1].value
						this.sysCapitalMoney.pledge_num = res.data.items[1].total_num
						this.sysCapitalMoney.pledge_ratio = (res.data.items[1].value / totalMoney * 100).toFixed(2)
						this.sysCapitalMoney.list[0] = {
							name: res.data.items[0].name,
							ratio: this.sysCapitalMoney.consume_ratio,
							value: this.sysCapitalMoney.consume_money,
							labelText: ""
						}
						this.sysCapitalMoney.list[1] = {
							name: res.data.items[1].name,
							ratio: this.sysCapitalMoney.pledge_ratio,
							value: this.sysCapitalMoney.pledge_money,
							labelText: ""
						}
					}
				})
			},

			// //管理员-行业统计
			getSysIndustry() {
				getSysIndustry(this.dateTypeObj).then((res) => {
					if (res.code === 1) {
						this.industryList = res.data
						// let ret = {
						//   series:[{data:res.data.roseData}]
						// }
						// this.$refs.chartsRose.show = true
						// this.$refs.chartsRose.chartData2 = JSON.parse(JSON.stringify(ret))
					} else {
						// this.$refs.chartsRose.setNoList()
					}
				})
			},

			//管理员-年龄区域统计
			getSysAge() {
				getSysAge(this.dateTypeObj).then((res) => {
					if (res.code === 1) {
						this.ageList = res.data
            this.$refs.ageRef.setData( res.data)
						// this.$refs.chartsAdminThree.show = true
						// this.$refs.chartsAdminThree.chartData4 = JSON.parse(JSON.stringify(ret));
					} else {
						// this.$refs.chartsAdminThree.setNoList()
					}
				})
			},
		},
	}
</script>

<style>
</style>