<template>
	<div class="snapshot-re-audit-grid-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="Status">
							<el-radio-group v-model="state.queryParams.Status" @change="handleQuery">
								<el-radio :value="0">审批中</el-radio>
								<el-radio :value="1">审批同意</el-radio>
								<el-radio :value="2">审批拒绝</el-radio>
								<el-radio :value="-1">全部</el-radio>
							</el-radio-group>
						</el-form-item>
						<el-form-item label="工单编码" prop="No">
							<el-input v-model="state.queryParams.No" placeholder="请填写工单编码" clearable @keyup.enter="handleQuery" class="keyword-input" />
						</el-form-item>
						<el-form-item label="工单标题" prop="Title">
							<el-input v-model="state.queryParams.Title" 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 #statusTxt="{ row }">
					<el-text type="danger" tag="b" v-if="[1, 2, 3, 9, 101, 102, 103, 104, 105, 200].includes(row.status)">{{ row.statusTxt }}</el-text>
					<span v-else>{{ row.statusTxt }}</span>
				</template>
				<template #order_detail="{ row }">
					<order-detail :order="row" @updateList="queryList">{{ row.title }}</order-detail>
				</template>
				<template #action="{ row }">
					<el-button link type="primary" @click="onAudit(row)" v-if="state.queryParams.Status === 0"> 审批 </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>
		<!--	红包审批	-->
		<re-audit ref="reAuditRef" @updateList="queryList" />
	</div>
</template>

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

// 引入组件
const pagination = defineAsyncComponent(() => import('@/components/ProTable/components/Pagination.vue')); // 分页
const OrderDetail = defineAsyncComponent(() => import('@/components/OrderDetail/index.vue')); // 工单详情
const ReAudit = defineAsyncComponent(() => import('@/views/snapshot/reAudit/components/Re-audit.vue')); // 红包审批

// 定义变量内容
const state = reactive<any>({
	loading: false,
	queryParams: {
		// 查询参数
		PageIndex: 1,
		PageSize: 20,
		No: null, // 工单编码
		Title: null, // 工单标题
		Status: 0, // 审批状态 默认审批中
	},
	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: 'snapshotReSendCitizen',
	rowConfig: { isHover: true, height: 30, isCurrent: true, useKey: true },
	height: 'auto',
	columns: [
		{ type: 'checkbox', width: 50, align: 'center' },
		{
			field: 'statusTxt',
			title: '工单状态',
			slots: {
				default: 'statusTxt',
			},
			width: 100,
		},
		{
			field: 'sourceChannel',
			title: '来源渠道',
			width: 110,
		},
		{
			field: 'no',
			title: '工单编码',
			width: 140,
		},
		{
			field: 'title',
			title: '工单标题',
			slots: { default: 'order_detail' },
			minWidth: 200,
		},
		{
			field: 'fromName',
			title: '来电人姓名',
			width: 120,
		},
		{
			field: 'fromPhone',
			title: '来电人号码',
			width: 140,
		},
		{
			field: 'approvedAmount',
			title: '网格员奖励金额',
			width: 120,
		},
		{
			field: 'isIssued',
			title: '网格员奖励发放结果',
			width: 150,
			slots: {
				default: ({ row }) => {
					return row.isIssued === null ? '' : row.isIssued ? '已发放' : '未发放';
				},
			},
		},
		{
			field: 'county',
			title: '区域',
			width: 140,
		},
		{
			field: 'isRectify',
			title: '部门是否整改完成',
			width: 150,
			slots: {
				default: ({ row }) => {
					return row.isRectify === null ? '' : row.isRectify ? '是' : '否';
				},
			},
		},
		{
			field: 'isTruthDepartment',
			title: '部门是否属实',
			width: 140,
			slots: {
				default: ({ row }) => {
					return row.isTruthDepartment === null ? '' : row.isTruthDepartment ? '是' : '否';
				},
			},
		},
		{
			field: 'isTruth',
			title: '网格员是否属实',
			width: 140,
			slots: {
				default: ({ row }) => {
					return row.isTruth === null ? '' : row.isTruth ? '是' : '否';
				},
			},
		},
		{
			field: 'isRepetition',
			title: '是否重复',
			width: 100,
			slots: {
				default: ({ row }) => {
					return row.isRepetition === null ? '' : row.isRepetition ? '是' : '否';
				},
			},
		},
		{
			field: 'isDeal',
			title: '网格员是否办理',
			width: 140,
			slots: {
				default: ({ row }) => {
					return row.isDeal === null ? '' : row.isDeal ? '是' : '否';
				},
			},
		},
		{
			field: 'networkENumber',
			title: '网格E通编号',
			width: 140,
		},
		{
			field: 'creationTime',
			title: '受理时间',
			formatter: 'formatDate',
			width: 160,
		},
		{
			field: 'levelOneStatusTxt',
			title: '区县审批状态',
			width: 160,
		},
		{
			field: 'levelOneAuditName',
			title: '区县审批人',
			width: 120,
		},
		{
			field: 'levelOneAuditOrgName',
			title: '区县审批部门',
			width: 140,
		},
		{
			field: 'levelOneAuditTime',
			title: '区县审批时间',
			formatter: 'formatDate',
			width: 160,
		},
		{
			field: 'networkRemark',
			title: '网格员办理状态',
			width: 140,
		},
		{
			field: 'levelOneAuditRemark',
			title: '区县审批意见',
			minWidth: 200,
		},
		{
			field: 'levelTwoStatusTxt',
			title: '审批状态',
			width: 120,
		},
		{
			field: 'levelTwoAuditTime',
			title: '审批时间',
			formatter: 'formatDate',
			width: 160,
		},
		{
			field: 'levelTwoAuditRemark',
			title: '审批意见',
			minWidth: 200,
		},
		{
			title: '操作',
			width: 90,
			fixed: 'right',
			showOverflow: false,
			align: 'center',
			slots: { default: 'action' },
		},
	],
	data: [],
});
/** 搜索按钮操作 节流操作 */
const handleQuery = () => {
	state.queryParams.PageIndex = 1;
	queryList();
};
// 获取参数列表
const queryList = () => {
	state.loading = true;
	gridOptions.loading = true;
	getGridRedEnvelopeApprovalList(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 ruleFormRef = ref<any>(null); // 表单ref
const resetQuery = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
	queryList();
};
// 审批
const reAuditRef = ref<RefType>();
const onAudit = (row: any) => {
	reAuditRef.value.openDialog(row, '网格员');
};
// 页面加载时
onMounted(() => {
	queryList();
});
</script>
