<!--
 * @Author: zwq
 * @Date: 2023-08-22 15:01:54
 * @LastEditors: zwq
 * @LastEditTime: 2024-10-09 14:25:40
 * @Description:
-->
<template>
	<div class="app-container">
		<search-bar
			:formConfigs="formConfig"
			ref="searchBarForm"
			@headBtnClick="buttonClick" />
		<el-row :gutter="20">
			<el-col :span="23">
				<pieChart
					title="饼状图分析"
					ref="pieChart"
					height="650px"
					v-if="tableData.totalNumber"
					:total-number="tableData.totalNumber"
					:pie-data="tableData.list" />
				<el-empty
        v-else
        :image-size="300"
        :image="require('../../../assets/images/empty.png')" />
			</el-col>
		</el-row>
	</div>
</template>

<script>
import basicPage from '../mixins/basic-page';
import pieChart from '../chart/PieChart.vue';
import { getPieChart } from '@/api/asrs/warehouseStorehouseStorage';

export default {
	mixins: [basicPage],
	data() {
		return {
			urlOptions: {
				getDataListURL: getPieChart,
			},
			listQuery: {
				warehouseId: '1696803324030865409',
				startTime: '',
				endTime: '',
			},
			formConfig: [
				{
					type: 'datePicker',
					label: '时间',
					dateType: 'daterange',
					format: 'yyyy-MM-dd',
					valueFormat: 'yyyy-MM-dd',
					rangeSeparator: '-',
					startPlaceholder: '开始时间',
					endPlaceholder: '结束时间',
					param: 'searchTime',
				},
				{
					type: 'button',
					btnName: '搜索',
					name: 'search',
					color: 'primary',
				},
			],
		};
	},
	components: {
		pieChart,
	},
	created() {
    this.listQuery.warehouseId = this.bId
  },
	methods: {
		// 获取数据列表
		getDataList() {
			if (this.listQuery.startTime) {
				this.urlOptions.getDataListURL(this.listQuery).then((response) => {
					if (response.data) {
						this.tableData = response.data;
						this.$nextTick(() => {
							this.$refs.pieChart.initChart();
						});
					}
				});
			}
		},
		buttonClick(val) {
			switch (val.btnName) {
				case 'search':
					if (val.searchTime) {
						this.listQuery.createTime = val.searchTime;
						this.listQuery.startTime = val.searchTime ? val.searchTime[0] : '';
						this.listQuery.endTime = val.searchTime ? val.searchTime[1] : '';
						this.getDataList();
					} else {
						this.$modal.msgWarning('请选择时间');
					}
					break;
				case 'reset':
					this.$refs.searchBarForm.resetForm();
					this.listQuery = {};
					this.getDataList();
					break;
				case 'add':
					this.addOrEditTitle = '新增';
					this.addOrUpdateVisible = true;
					this.addOrUpdateHandle();
					break;
				case 'export':
					this.handleExport();
					break;
				default:
					console.log(val);
			}
		},
	},
};
</script>
