<template>
	<div class="m-zyqd">
		<el-row :gutter="16">
			<el-col :span="8">
				<div class="kuangkuang">
					<h3>发布政策数</h3>
					<h2>256</h2>
				</div>
			</el-col>
			<el-col :span="8">
				<div class="kuangkuang">
					<h3>指派服务数</h3>
					<h2>2545</h2>
				</div>
			</el-col>
			<el-col :span="8">
				<div class="kuangkuang">
					<h3>政策找人数</h3>
					<h2>2545</h2>
				</div>
			</el-col>
		</el-row>
		<div class="pieMain">
			<div class="pie"><screen-echarts-frame @myChartMethod="pieInitOk" ref="pieChart"></screen-echarts-frame></div>
		</div>
	</div>
</template>
<script>
import screenEchartsFrame from '@/views/dataBoard/cpts/screen-echarts-frame/index';
import { pieOption } from './fwBarOption.js';
import { requestPostBi } from '@/js/dai/request-bipass';
export default {
	props: {
		orgId: {
			type: String,
			default: ''
		}
	},
	data() {
		return {
			showNoData: false,
			timer: null,
			pieChart: '',
			pieOption: {},
			pieInitState: false,
			pieData: [],
			tabList: [
				'人资源',
				'物资源',
				'场所资源'
				// "下级人口分布",
			],
			currentTab: '人资源',
			info: {
				male_count: 0,
				female_count: 0,
				resi_y_house_y_count: 0,
				resi_y_house_n_count: 0,
				resi_n_house_y_count: 0,
				primary_count: 0,
				junior_high_count: 0,
				second_speci_count: 0,
				high_school_count: 0,
				junior_college_count: 0,
				undergrad_count: 0,
				master_count: 0,
				doctor_count: 0,
				local_count: 0,
				field_count: 0,
				age50_count: 0,
				age5059_count: 0,
				age6069_count: 0,
				age7079_count: 0,
				age80_count: 0,
				culture_count: 0,
				committee_count: 0,
				capable_count: 0,
				friend_count: 0,
				agent_count: 0,
				mediator_count: 0,
				collector_count: 0,
				security_count: 0,
				party_mem_count: 0
			}
		};
	},
	components: {
		screenEchartsFrame
	},
	mounted() {
		this.init();
	},
	watch: {
		currentTab() {
			this.setPieData();
		},
		orgId() {
			this.init();
		}
	},
	methods: {
		async init() {
			await this.getInfo();
			this.getPie();
		},
		handleClickItem(item) {
			// const { type, name } = item;
			// this.$router.push({
			// 	path: '/dataBoard/renfang/resi-analyze',
			// 	query: {
			// 		org_id: this.orgId,
			// 		type,
			// 		type_category: this.currentTab,
			// 		type_name: name
			// 	}
			// });
		},
		// 获取房屋总数等
		async getInfo() {
			let url = '';
			if (this.currentTab == '人资源') {
				url = 'people_res_view';
			} else if (this.currentTab == '物资源') {
				url = 'goods_res_view';
			} else {
				url = 'people_res_view';
			}

			this.$refs.pieChart.showLoading();
			const { data, code, msg } = await requestPostBi(
				url,
				{
					queryParam: {
						org_id: this.orgId
					}
				},
				{
					// mockId: 60041615,
				}
			);
			this.$refs.pieChart.hideLoading();
			if (code === 0) {
				if (data && Array.isArray(data) && data.length > 0) {
					let info = data[0];
					this.info = {
						...this.info,
						...info
					};
				}
			} else {
				this.$message.error(msg);
			}
		},
		selItem(selItem, selIndex) {
			this.tabList.forEach((element, index) => {
				if (index === selIndex) {
					element.sel = true;
				} else {
					element.sel = false;
				}
			});
		},
		pieInitOk() {
			this.pieInitState = true;
		},
		getPie() {
			if (this.pieInitState) {
				this.setPieData();
			} else {
				setTimeout(() => {
					this.getPie();
				}, 500);
			}
		},
		setPieData() {
			const { currentTab, info } = this;

			let data = [
				{
					name: '江',
					org_id: '7b6f9a9f9f38d5f9fa7ce94a93d6eb28',
					count: 61
				},
				{
					name: '平',
					org_id: '7b6f9a9f9f38d5f9fa7ce94a93d6eb28',
					count: 63
				},
				{
					name: '究',
					org_id: '7b6f9a9f9f38d5f9fa7ce94a93d6eb28',
					count: 66
				},
				{
					name: '布',
					org_id: '7b6f9a9f9f38d5f9fa7ce94a93d6eb28',
					count: 61
				}
			];
			data = JSON.parse(JSON.stringify(data).replace(/count/g, 'value'));
			console.log('data', data);
			this.pieData = data;

			this.iniPieChart();
		},
		// 获取饼状图
		async iniPieChart() {
			this.$refs.pieChart.clear();
			// 获取pieChart配置
			this.pieOption = pieOption();
			this.pieOption.series[0].name = this.currentTab;
			this.pieOption.series[0].data = this.pieData;
			this.$refs.pieChart.setOption(this.pieOption);
		}
	}
};
</script>

<style lang="scss" src="@/assets/scss/dataBoard/renfang/index.scss" scoped></style>
