<template>
	<div class="snapshot-invite-code-statistics-detail-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 prop="crTime">
							<statistical-time v-model="state.queryParams.crTime" @change="handleQuery" ref="statisticalTimeRef" :disabled="state.loading" />
						</el-form-item>
						<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="CaseName">
							<el-input v-model="state.queryParams.CaseName" placeholder="请填写电话" clearable @keyup.enter="handleQuery" class="keyword-input" />
						</el-form-item>
						<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>
							<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 #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>
		<!--  新增用户  -->
		<user-add ref="userAddRef" @updateList="queryList" />
		<!--  编辑用户  -->
		<user-edit ref="userEditRef" @updateList="queryList" />
	</div>
</template>

<script lang="tsx" setup name="snapshotInviteCodeStatisticsDetail">
import { computed, defineAsyncComponent, onMounted, reactive, ref } from 'vue';
import { FormInstance } from 'element-plus';
import { getClueList } from '@/api/snapshot/config';
import { defaultDate } from '@/utils/constants';
import Other from '@/utils/other';

// 引入组件
const pagination = defineAsyncComponent(() => import('@/components/ProTable/components/Pagination.vue')); // 分页
const UserAdd = defineAsyncComponent(() => import('@/views/snapshot/config/areaUser/components/User-add.vue')); // 新增用户
const UserEdit = defineAsyncComponent(() => import('@/views/snapshot/config/areaUser/components/User-edit.vue')); // 编辑用户
const StatisticalTime = defineAsyncComponent(() => import('@/components/StatisticalTime/index.vue')); // 日期类型选择组件

// 定义变量内容
const state = reactive<any>({
	loading: false,
	queryParams: {
		// 查询参数
		PageIndex: 1,
		PageSize: 20,
		crTime: defaultDate, //
		StartTime: null,
		EndTime: 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: 'snapshotInviteCodeStatistics',
	rowConfig: { isHover: true, height: 30, isCurrent: true, useKey: true },
	height: 'auto',
	columns: [
		{
			field: 'name',
			title: '姓名',
		},
		{
			field: 'name',
			title: '电话',
		},
		{
			field: 'name',
			title: '微信openID',
		},
		{
			field: 'name',
			title: '邀请时间',
		},
		{
			field: 'name',
			title: '邀请码',
		},
		{
			field: 'name',
			title: '部门',
		},
	],
	data: [],
});
const ruleFormRef = ref<any>(null); // 表单ref
/** 搜索按钮操作 节流操作 */
const handleQuery = () => {
	state.queryParams.PageIndex = 1;
	queryList();
};
// 获取参数列表
const requestParams = ref<EmptyObjectType>({});
const queryList = () => {
	state.loading = true;
	gridOptions.loading = true;
	requestParams.value = Other.deepClone(state.queryParams);
	requestParams.value.StartTime = state.queryParams.crTime === null ? null : state.queryParams.crTime[0];
	requestParams.value.EndTime = state.queryParams.crTime === null ? null : state.queryParams.crTime[1];
	Reflect.deleteProperty(requestParams.value, 'crTime');
	getClueList(requestParams.value)
		.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 linkDetail = (row:any)=>{

}
// 页面加载时
onMounted(() => {
	queryList();
});
</script>
