<template>
	<div class="snapshot-config-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" 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="ApproveOrgName">
							<el-input v-model="state.queryParams.ApproveOrgName" 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="addIndustry" v-auth="'snapshot:config:industry:add'">
						<SvgIcon name="ele-Plus" class="mr5" />新增行业
					</el-button>
				</template>
				<template #action="{row}">
					<el-button link type="primary" @click="editIndustry(row)" v-auth="'snapshot:config:industry: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>
		<!--  行业新增  -->
		<industry-add ref="industryAddRef" @updateList="queryList" />
		<!--  行业编辑  -->
		<industry-edit ref="industryEditRef" @updateList="queryList" />
	</div>
</template>

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

// 引入组件
const IndustryAdd = defineAsyncComponent(() => import('@/views/snapshot/config/industry/components/Industry-add.vue')); // 行业新增
const IndustryEdit = defineAsyncComponent(() => import('@/views/snapshot/config/industry/components/Industry-edit.vue')); // 行业修改
const pagination = defineAsyncComponent(() => import('@/components/ProTable/components/Pagination.vue')); // 分页

// 定义变量内容
const state = reactive<any>({
	loading: false,
	queryParams: {
		// 查询参数
		PageIndex: 1,
		PageSize: 20,
		Name: null, // 行业名称
		ApproveOrgName: 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: 'snapshotConfigIndustry',
	rowConfig: { isHover: true, height: 30, isCurrent: true, useKey: true },
	height: 'auto',
	columns: [
		{
			field: 'name',
			title: '行业名称',
		},
		{
			field: 'approveOrgName',
			title: '审批部门',
		},
		{
			field: 'citizenReadPackAmount',
			title: '市民红包',
		},	{
			field: 'guiderReadPackAmount',
			title: '网格员红包',
		},
		{
			field: 'isEnable',
			title: '启用状态',
			width: 100,
			slots: {
				default: ({ row }: any) => {
					return row.isEnable ? '启用' : '禁用';
				},
			},
		},
		{
			field: 'acceptType',
			title: '关联受理类型',
		},
		{
			field: 'titleSuffix',
			title: '标题追加信息',
		},
		{
			field: 'pageUrl',
			title: '页面URL',
		},
		{
			field: 'txtRemarks',
			title: '帮助说明',
		},
		{
			field: 'displayOrder',
			title: '排序',
		},
		{
			field: 'txtCareRemarks',
			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;
	getIndustryList(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 industryAddRef = ref<RefType>(); // 参数行业
const addIndustry = () => {
	industryAddRef.value.openDialog();
};
// 编辑行业
const industryEditRef = ref<RefType>();
const editIndustry = (row: any) => {
	industryEditRef.value.openDialog(row.id);
};
// 页面加载时
onMounted(() => {
	queryList();
});
</script>