<template>
	<div class="snapshot-config-volunteer-report-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" inline @submit.native.prevent :disabled="gridOptions.loading">
						<el-form-item label="施工人员姓名" prop="Name">
							<el-input
								v-model="state.queryParams.Name"
								placeholder="请填写施工人员姓名"
								clearable
								@keyup.enter="handleQuery"
								class="keyword-input"
							/>
						</el-form-item>
						<el-form-item label="联系电话" prop="PhoneNumber">
							<el-input
								v-model="state.queryParams.PhoneNumber"
								placeholder="请填写联系电话"
								clearable
								@keyup.enter="handleQuery"
								class="keyword-input"
							/>
						</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"> <SvgIcon name="ele-Refresh" class="mr5" />重置 </el-button>
						</el-form-item>
					</el-form>
				</template>
				<template #action="{ row }">
					<el-button link type="primary" @click="onView(row)"> 查看 </el-button>
				</template>
				<template #pager>
					<pagination
						@pagination="queryList"
						:total="state.total"
						v-model:current-page="state.queryParams.PageIndex"
						v-model:page-size="state.queryParams.PageSize"
						:disabled="state.loading"
					/>
				</template>
			</vxe-grid>
		</div>
		<report-detail ref="reportDetailRef" />
	</div>
</template>

<script lang="tsx" setup name="snapshotConfigVolunteerReport">
import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
import { FormInstance } from 'element-plus';
import { getReportList } from '@/api/snapshot/config';

// 引入组件
const pagination = defineAsyncComponent(() => import('@/components/ProTable/components/Pagination.vue')); // 分页
const ReportDetail = defineAsyncComponent(() => import('@/views/snapshot/config/volunteer/components/Report-detail.vue')); // 上报详情

// 定义变量内容
const state = reactive<any>({
	loading: false,
	queryParams: {
		// 查询参数
		PageIndex: 1,
		PageSize: 20,
		Name: null, // 线索名称
		PhoneNumber: null, // 电话
	},
	total: 0, // 总条数
});

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();
			},
		},
	},
	customConfig: {
		storage: true,
	},
	id: 'snapshotConfigVolunteerReport',
	rowConfig: { isHover: true, height: 30, isCurrent: true, useKey: true },
	height: 'auto',
	columns: [
		{
			field: 'jobType',
			title: '行业类型',
		},
		{
			field: 'phoneNumber',
			title: '联系电话',
		},
		{
			field: 'fullAddress',
			title: '施工地点',
		},
		{
			field: 'creationTime',
			title: '上报时间',
			formatter: 'formatDate',
		},
		{
			field: 'volunteer',
			title: '志愿者姓名',
		},
		{
			field: 'volunteerPhone',
			title: '志愿者电话',
		},
		{
			field: 'isApprovalProcess',
			title: '生产经营单位内部是否按规定办理审批手续',
			slots:{
				default ({row}) {
					return row.isApprovalProcess ? '是' : '否';
				}
			}
		},
		{
			field: 'isProfessionalCertificate',
			title: '电气焊作业人员是否取得职业资格证书',
			slots:{
				default ({row}) {
					return row.isProfessionalCertificate ? '是' : '否';
				}
			}
		},
		{
			field: 'isSiteMonitoring',
			title: '是否落实作业现场监护人员',
			slots:{
				default ({row}) {
					return row.isSiteMonitoring ? '是' : '否';
				}
			}
		},
		{
			field: 'isFireWork',
			title: '是否在人员密集场所营业期间动火作业',
			slots:{
				default ({row}) {
					return row.isFireWork ? '是' : '否';
				}
			}
		},
		{
			field: 'isClearSafety',
			title: '是否清除作业现场及周围易燃物品或落实有效安全防范措施',
			slots:{
				default ({row}) {
					return row.isClearSafety ? '是' : '否';
				}
			}
		},
		{
			field: 'hasFireEquipment',
			title: '作业现场是否配备能满足现场灭火应急需求消防器材',
			slots:{
				default ({row}) {
					return row.hasFireEquipment ? '是' : '否';
				}
			}
		},
		{
			field: 'isToolSafety',
			title: '作业现场使用的工器具是否进行安全检查',
			slots:{
				default ({row}) {
					return row.isToolSafety ? '是' : '否';
				}
			}
		},
		{ title: '操作', width: 90, fixed: 'right', align: 'center', slots: { default: 'action' } },
	],
	data: [],
});
const ruleFormRef = ref<any>(null); // 表单ref
/** 搜索按钮操作 节流操作 */
const handleQuery = () => {
	state.queryParams.PageIndex = 1;
	queryList();
};
// 获取参数列表
const queryList = () => {
	state.loading = true;
	gridOptions.loading = true;
	getReportList(state.queryParams)
		.then((res) => {
			state.loading = false;
			gridOptions.data = res.result.items ?? [];
			state.total = res.result.total ?? 0;
			gridOptions.loading = false;
		})
		.finally(() => {
			state.loading = false;
			gridOptions.loading = false;
		});
};
// 重置表单
const resetQuery = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
	queryList();
};
// 查看
const reportDetailRef = ref<RefType>();
const onView = (row: any) => {
	reportDetailRef.value.openDialog(row);
};
// 页面加载时
onMounted(() => {
	queryList();
});
</script>
