<template>
	<div class="judicial-statistics-detail-satisfaction-container layout-padding">
		<div class="layout-padding-auto layout-padding-view pd20">
			<vxe-toolbar
				ref="toolbarRef"
				:loading="state.loading"
				custom
				:refresh="{
					queryMethod: queryList,
				}"
				:tools="[{ toolRender: { name: 'exportCurrent' } }, { toolRender: { name: 'exportAll' } }]"
			>
			</vxe-toolbar>
			<div style="overflow: hidden; width: 100%; height: 100%; flex: 1">
				<vxe-table
					border
					:loading="state.loading"
					:data="state.tableData"
					:column-config="{ resizable: true }"
					:row-config="{ isCurrent: true, isHover: true, height: 30,useKey: true }"
					ref="tableRef"
					height="auto"
					auto-resize
					show-overflow
					:scrollY="{ enabled: true, gt: 100 }"
					id="judicialStatisticsDetailSatisfied"
					:custom-config="{ storage: true }"
					:params="{ exportMethod: departmentSatisfactionDetailExport, exportParams: requestParams }"
					showHeaderOverflow
				>
					<vxe-column field="no" title="工单编码" width="160"></vxe-column>
					<vxe-column field="title" title="工单标题" min-width="200">
						<template #default="{ row }">
							<order-detail :order="row" @updateList="queryList">{{ row.title }}</order-detail>
						</template>
					</vxe-column>
					<vxe-column field="acceptType" title="受理类型" width="100"></vxe-column>
					<vxe-column field="hotspotName" title="热点分类" width="150"></vxe-column>
					<vxe-column field="enforcementOrdersHandlerText" title="执法部门" min-width="150"></vxe-column>
					<vxe-column field="incidentAddressText" title="事发地址" min-width="150"></vxe-column>
					<vxe-column field="creationTime" title="生成时间" width="160">
						<template #default="{ row }">
							{{ formatDate(row.creationTime, 'YYYY-mm-dd HH:MM:SS') }}
						</template>
					</vxe-column>
					<vxe-column field="acceptorName" title="受理人" width="120"></vxe-column>
					<vxe-column field="isPassTheBuckOrderText" title="是否推诿工单" width="120"></vxe-column>
					<vxe-column field="isTheClueTrueText" title="线索是否属实" width="120"></vxe-column>
					<vxe-column field="isEnforcementOrderText" title="是否行政执法类工单" width="150"></vxe-column>
					<vxe-column field="eventTypeName" title="事项类型" width="150"></vxe-column>
					<vxe-column title="操作" width="90" fixed="right">
						<template #default="{ row }">
							<el-button link type="primary" @click="visitDetail(row)" title="查看回访详情"> 回访详情 </el-button>
						</template>
					</vxe-column>
				</vxe-table>
			</div>
			<pagination
				@pagination="queryList"
				:total="state.total"
				v-model:current-page="state.queryParams.PageIndex"
				v-model:page-size="state.queryParams.PageSize"
				:disabled="state.loading"
			/>
		</div>
		<!-- 回访详情 -->
		<visit-detail-com ref="visitDetailRef" @updateList="queryList" />
	</div>
</template>
<script setup lang="tsx" name="judicialStatisticsDetailSatisfied">
import { onMounted, reactive, ref, defineAsyncComponent } from 'vue';
import { FormInstance } from 'element-plus';
import { departmentSatisfactionDetail, departmentSatisfactionDetailExport } from '@/api/judicial';
import { formatDate } from '@/utils/formatTime';
import { useRoute } from 'vue-router';

// 引入组件
const VisitDetailCom = defineAsyncComponent(() => import('@/views/business/visit/components/Visit-detail.vue')); // 回访
const OrderDetail = defineAsyncComponent(() => import('@/views/judicial/order/components/orderDetail.vue')); // 工单详情
const pagination = defineAsyncComponent(() => import('@/components/ProTable/components/Pagination.vue')); // 分页

const state = reactive({
	queryParams: {
		// 查询条件
		PageIndex: 1,
		PageSize: 20,
		TypeId: '1', //
		LineNum: null,
		crTime: [],
	},
	tableData: [], //表单
	loading: false, // 加载
	total: 0, // 总数
});
const route = useRoute();
const routeQueryParams: any = route.query;
if (routeQueryParams.StartTime) {
	state.queryParams.crTime = [formatDate(routeQueryParams.StartTime, 'YYYY-MM-DD'), formatDate(routeQueryParams.EndTime, 'YYYY-MM-DD')];
}
/** 获取列表 */
const requestParams = ref({});
const queryList = () => {
	state.loading = true;
	requestParams.value = {
		StartTime: routeQueryParams.StartTime,
		EndTime: routeQueryParams.EndTime,
		TypeId: routeQueryParams.TypeId,
		OrgCode: routeQueryParams.orgCode,
		DateValue: routeQueryParams.DateValue,
		PageIndex: state.queryParams.PageIndex,
		PageSize: state.queryParams.PageSize,
	};
	departmentSatisfactionDetail(requestParams.value)
		.then((res: any) => {
			state.tableData = res.result?.items ?? [];
			state.total = res.result.total ?? 0;
			state.loading = false;
		})
		.catch(() => {
			state.loading = false;
		});
};
/** 重置按钮操作 */
const resetQuery = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
	queryList();
};
// 回访详情
const visitDetailRef = ref<RefType>();
const visitDetail = (row: any) => {
	const rowData = {
		...row,
		orderId: row.id,
		id: row.visitId,
	};
	visitDetailRef.value.openDialog(rowData, '回访详情');
};
const toolbarRef = ref<RefType>();
const tableRef = ref<RefType>();
onMounted(() => {
	queryList();
	if (tableRef.value && toolbarRef.value) {
		tableRef.value.connect(toolbarRef.value);
	}
});
</script>
