<template>
	<div class="snapshot-statistics-industry-container layout-padding">
		<div class="layout-padding-auto layout-padding-view pd20">
			<vxe-grid v-bind="gridOptions" ref="gridRef">
				<template #form>
					<el-form :model="state.queryParams" ref="ruleFormRef" @submit.native.prevent inline :disabled="gridOptions.loading">
						<el-form-item prop="crTime">
							<statistical-time v-model="state.queryParams.crTime" @change="handleQuery" ref="statisticalTimeRef" :disabled="state.loading" />
						</el-form-item>
						<el-form-item>
							<el-button type="primary" @click="handleQuery" :loading="state.loading"> <SvgIcon name="ele-Search" class="mr5" />查询 </el-button>
							<el-button @click="resetQuery(ruleFormRef)" class="default-button" :loading="state.loading">
								<SvgIcon name="ele-Refresh" class="mr5" />重置
							</el-button>
						</el-form-item>
					</el-form>
				</template>
			</vxe-grid>
		</div>
	</div>
</template>

<script lang="tsx" setup name="snapshotStatisticsIndustry">
import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
import { FormInstance } from 'element-plus';
import { defaultDate } from '@/utils/constants';
import { getSSPStatisticsProcess, getSSPStatisticsProcessExport } from '@/api/snapshot/statistics';
import Other from '@/utils/other';
import { useRouter } from 'vue-router';

// 引入组件
const StatisticalTime = defineAsyncComponent(() => import('@/components/StatisticalTime/index.vue')); // 日期类型选择组件

// 定义变量内容
const state = reactive<any>({
	loading: false,
	queryParams: {
		// 查询参数
		crTime: defaultDate, // 时间默认今天开始到今天结束
		StartTime: null,
		EndTime: null,
	},
});

const requestParams = ref<EmptyObjectType>({});
const gridOptions = reactive<any>({
	loading: false,
	border: true,
	showOverflow: true,
	columnConfig: {
		resizable: true,
	},
	scrollY: {
		enabled: true,
		gt: 100,
	},
	toolbarConfig: {
		zoom: true,
		custom: true,
		refresh: {
			queryMethod: () => {
				handleQuery();
			},
		},
		tools: [{ toolRender: { name: 'exportAll' } }],
	},
	customConfig: {
		storage: true,
	},
	id: 'snapshotStatisticsIndustry',
	rowConfig: { isHover: true, height: 30, isCurrent: true, useKey: true },
	height: 'auto',
	align: 'center',
	columns: [
		{
			field: 'orgName',
			title: '行业类型',
			width: 200,
			fixed: 'left',
		},
		{
			title: '上报情况',
			children: [
				{
					field: 'ybOrderCountNum',
					title: '上报数量',
					width: 100,
					slots: {
						default({ row }) {
							return (
								<el-button type="primary" onClick={() => linkDetail(row, 'ybOrderCountNum')} link>
									{row.ybOrderCountNum}
								</el-button>
							);
						},
					},
				},
				{
					field: 'ybOrderCountNum',
					title: '总办理时长',
					width: 100,
				},
				{
					field: 'zbOrderCountNum',
					title: '重点工单',
					width: 100,
					slots: {
						default({ row }) {
							return (
								<el-button type="primary" onClick={() => linkDetail(row, 'zbOrderCountNum')} link>
									{row.zbOrderCountNum}
								</el-button>
							);
						},
					},
				},
			],
		},
		{
			title: '上报区域',
			children: [
				{
					field: 'zbOrderCountNum',
					title: '自贡市',
					width: 100,
					slots: {
						default({ row }) {
							return (
								<el-button type="primary" onClick={() => linkDetail(row, 'zbOrderCountNum')} link>
									{row.zbOrderCountNum}
								</el-button>
							);
						},
					},
				},
				{
					field: 'zbOrderCountNum',
					title: '自流井区',
					width: 100,
					slots: {
						default({ row }) {
							return (
								<el-button type="primary" onClick={() => linkDetail(row, 'zbOrderCountNum')} link>
									{row.zbOrderCountNum}
								</el-button>
							);
						},
					},
				},
				{
					field: 'zbOrderCountNum',
					title: '高新区',
					width: 100,
					slots: {
						default({ row }) {
							return (
								<el-button type="primary" onClick={() => linkDetail(row, 'zbOrderCountNum')} link>
									{row.zbOrderCountNum}
								</el-button>
							);
						},
					},
				},
				{
					field: 'zbOrderCountNum',
					title: '荣县',
					width: 100,
					slots: {
						default({ row }) {
							return (
								<el-button type="primary" onClick={() => linkDetail(row, 'zbOrderCountNum')} link>
									{row.zbOrderCountNum}
								</el-button>
							);
						},
					},
				},
				{
					field: 'zbOrderCountNum',
					title: '富顺县',
					width: 100,
					slots: {
						default({ row }) {
							return (
								<el-button type="primary" onClick={() => linkDetail(row, 'zbOrderCountNum')} link>
									{row.zbOrderCountNum}
								</el-button>
							);
						},
					},
				},
				{
					field: 'zbOrderCountNum',
					title: '沿滩区',
					width: 100,
					slots: {
						default({ row }) {
							return (
								<el-button type="primary" onClick={() => linkDetail(row, 'zbOrderCountNum')} link>
									{row.zbOrderCountNum}
								</el-button>
							);
						},
					},
				},
				{
					field: 'zbOrderCountNum',
					title: '贡井区',
					width: 100,
					slots: {
						default({ row }) {
							return (
								<el-button type="primary" onClick={() => linkDetail(row, 'zbOrderCountNum')} link>
									{row.zbOrderCountNum}
								</el-button>
							);
						},
					},
				},
				{
					field: 'zbOrderCountNum',
					title: '大安区',
					width: 100,
					slots: {
						default({ row }) {
							return (
								<el-button type="primary" onClick={() => linkDetail(row, 'zbOrderCountNum')} link>
									{row.zbOrderCountNum}
								</el-button>
							);
						},
					},
				},
				{
					field: 'zbOrderCountNum',
					title: '外地',
					width: 100,
					slots: {
						default({ row }) {
							return (
								<el-button type="primary" onClick={() => linkDetail(row, 'zbOrderCountNum')} link>
									{row.zbOrderCountNum}
								</el-button>
							);
						},
					},
				},
				{
					field: 'zbOrderCountNum',
					title: '其它',
					width: 100,
					slots: {
						default({ row }) {
							return (
								<el-button type="primary" onClick={() => linkDetail(row, 'zbOrderCountNum')} link>
									{row.zbOrderCountNum}
								</el-button>
							);
						},
					},
				},
			],
		},
		{
			title: '归口部门标记',
			children: [
				{
					field: 'zbOrderCountNum',
					title: '属于本部门',
					width: 100,
					slots: {
						default({ row }) {
							return (
								<el-button type="primary" onClick={() => linkDetail(row, 'zbOrderCountNum')} link>
									{row.zbOrderCountNum}
								</el-button>
							);
						},
					},
				},
				{
					field: 'zbOrderCountNum',
					title: '不属于本部门',
					width: 100,
					slots: {
						default({ row }) {
							return (
								<el-button type="primary" onClick={() => linkDetail(row, 'zbOrderCountNum')} link>
									{row.zbOrderCountNum}
								</el-button>
							);
						},
					},
				},
				{
					field: 'zbOrderCountNum',
					title: '未标记',
					width: 100,
					slots: {
						default({ row }) {
							return (
								<el-button type="primary" onClick={() => linkDetail(row, 'zbOrderCountNum')} link>
									{row.zbOrderCountNum}
								</el-button>
							);
						},
					},
				},
			],
		},
	],
	data: [],
	params: {
		exportMethod: getSSPStatisticsProcessExport,
		exportParams: requestParams,
	},
});
/** 搜索按钮操作 节流操作 */
const handleQuery = () => {
	state.queryParams.PageIndex = 1;
	queryList();
};
// 获取参数列表
const queryList = () => {
	state.loading = true;
	gridOptions.loading = true;
	requestParams.value = Other.deepClone(state.queryParams);
	requestParams.value.StartTime = state.queryParams.crTime === null ? null : state.queryParams.crTime[0]; // 受理时间
	requestParams.value.EndTime = state.queryParams.crTime === null ? null : state.queryParams.crTime[1];
	Reflect.deleteProperty(requestParams.value, 'crTime'); // 删除无用的参数
	getSSPStatisticsProcess(requestParams.value)
		.then((res) => {
			state.loading = false;
			gridOptions.data = res.result ?? [];
			gridOptions.loading = false;
		})
		.finally(() => {
			state.loading = false;
			gridOptions.loading = false;
		});
};
// 重置表单
const ruleFormRef = ref<any>(null); // 表单ref
const statisticalTimeRef = ref<RefType>();
const resetQuery = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
	statisticalTimeRef.value.reset();
	queryList();
};
// 跳转详情
const router = useRouter();
const linkDetail = (row: any, FieldName: string) => {
	console.log(row, '11');
	router.push({
		path: '/snapshot/statistic/detailIndustry',
		query: {
			FieldName,
			OrgId: row.orgCode,
			IndustryId: state.queryParams.industryId,
			StartTime: state.queryParams.crTime[0],
			EndTime: state.queryParams.crTime[1],
		},
	});
};
// 页面加载时
onMounted(() => {
	queryList();
});
</script>
