<template>
	<div class="snapshot-info-audit-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="CaseName">
							<el-input v-model="state.queryParams.CaseName" placeholder="请填写线索分类" clearable @keyup.enter="handleQuery" class="keyword-input" />
						</el-form-item>
						<el-form-item label="行业类型" prop="IndustryName">
							<el-input v-model="state.queryParams.IndustryName" 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 #toolbar_buttons>
					<el-button type="primary" @click="onAdd" v-auth="'snapshot:config:clue:add'">
						<SvgIcon name="ele-Plus" class="mr5" />新增线索
					</el-button>
				</template>
				<template #action="{row}">
					<el-button link type="primary" @click="onEdit(row)" v-auth="'snapshot:config:clue:edit'" title="编辑线索"> 编辑 </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>
		<!--  新增线索  -->
		<clue-add ref="clueAddRef" @updateList="queryList" />
		<!--  修改线索  -->
		<clue-edit ref="clueEditRef" @updateList="queryList" />
	</div>
</template>

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

// 引入组件
const pagination = defineAsyncComponent(() => import('@/components/ProTable/components/Pagination.vue')); // 分页
const ClueAdd = defineAsyncComponent(() => import('@/views/snapshot/config/clue/components/Clue-add.vue')); // 新增线索
const ClueEdit = defineAsyncComponent(() => import('@/views/snapshot/config/clue/components/Clue-edit.vue')); // 修改线索

// 定义变量内容
const state = reactive<any>({
	loading: false,
	queryParams: {
		// 查询参数
		PageIndex: 1,
		PageSize: 20,
		CaseName: null, // 线索名称
		IndustryName: 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();
			},
		},
		slots: {
			buttons: 'toolbar_buttons',
		},
	},
	customConfig: {
		storage: true,
	},
	id: 'snapshotConfigClue',
	rowConfig: { isHover: true, height: 30, isCurrent: true, useKey: true },
	height: 'auto',
	columns: [
		{
			field: 'name',
			title: '行业类型',
		},
		{
			field: 'industryName',
			title: '线索分类',
		},
		{
			field: 'citizenReadPackAmountTxt',
			title: '市民红包',
		},	{
			field: 'guiderReadPackAmountTxt',
			title: '网格员红包',
		},
		{
			field: 'isEnable',
			title: '启用状态',
			width: 100,
			slots: {
				default: ({ row }: any) => {
					return row.isEnable ? '启用' : '禁用';
				},
			},
		},
		{
			field: 'displayOrder',
			title: '排序',
		},
		{ 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;
	getClueList(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 clueAddRef = ref<RefType>(); // 参数行业
const onAdd = () => {
	clueAddRef.value.openDialog();
};
// 编辑
const clueEditRef = ref<RefType>();
const onEdit = (row: any) => {
	clueEditRef.value.openDialog(row.id);
};
// 页面加载时
onMounted(() => {
	queryList();
});
</script>