<template>
	<div class="tels-telsLog-container layout-pd">
		<el-card shadow="never">
			<!-- 通用搜索 -->
			<el-form :model="state.queryParams" ref="ruleFormRef" :inline="true" @submit.native.prevent class="mt15">
				<el-form-item label="时间" prop="time">
					<el-date-picker
						v-model="state.queryParams.time"
						type="datetimerange"
						range-separator="至"
						start-placeholder="开始时间"
						end-placeholder="结束时间"
						value-format="YYYY-MM-DD[T]HH:mm:ss"
					/>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="handleQuery" :loading="state.loading" v-waves> <SvgIcon name="ele-Search" class="mr5" />查询 </el-button>
					<el-button @click="resetQuery(ruleFormRef)" v-waves class="default-button"> <SvgIcon name="ele-Refresh" class="mr5" />重置 </el-button>
				</el-form-item>
			</el-form>
		</el-card>
		<el-card shadow="never">
			<div class="flex-center-between mb20">
				<p class="table-title">信息列表</p>
				<div></div>
			</div>
			<!-- 表格 -->
			<el-table :data="state.tableData" v-loading="state.loading" row-key="id">
				<el-table-column type="index" width="60" label="序号" />
				<el-table-column prop="phoneNo" label="电话号码" show-overflow-tooltip></el-table-column>
				<el-table-column prop="phoneNo" label="坐席" show-overflow-tooltip></el-table-column>
				<el-table-column prop="phoneNo" label="累计签入(小时)" show-overflow-tooltip></el-table-column>
				<el-table-column prop="phoneNo" label="累计小休(小时)" show-overflow-tooltip></el-table-column>
				<el-table-column prop="phoneNo" label="累计通话时常(小时)" show-overflow-tooltip></el-table-column>
				<el-table-column label="明细" width="100" fixed="right" align="center">
					<template #default="{row}">
						<el-button link type="primary" @click="onDetail(row)" v-auth="'200202'" title="查看明细"> 查看明细 </el-button>
					</template>
				</el-table-column>
				<template #empty>
					<Empty />
				</template>
			</el-table>
			<!-- 分页 -->
			<pagination :total="state.total" v-model:page="state.queryParams.PageIndex" v-model:limit="state.queryParams.PageSize" @pagination="queryList" />
		</el-card>

		<operation-record ref="operationRecordRef" />
	</div>
</template>

<script lang="ts" setup name="telsLog">
import { defineAsyncComponent, ref, reactive, onMounted } from 'vue';
import type { FormInstance } from 'element-plus';
import { blacklistPaged } from '/@/api/tels/blacklist';
import { throttle } from '/@/utils/tools';
// 引入组件
const OperationRecord = defineAsyncComponent(() => import('/@/views/tels/telsLog/component/Operation-record.vue'));

// 定义接口来定义对象的类型
interface QueryState {
	queryParams: {
		PageIndex: number;
		PageSize: number;
		time: Array<any>;
	};
	loading: boolean;
	total: number;
	tableData: Array<any>;
	multipleSelection: Array<any>;
}

// 定义变量内容
const state = reactive<QueryState>({
	queryParams: {
		PageIndex: 1,
		PageSize: 10,
		time: [],
	},
	loading: false,
	total: 0,
	tableData: [],
	multipleSelection: [],
});
const ruleFormRef = ref<FormInstance>();
const operationRecordRef = ref<RefType>();
/** 搜索按钮操作 节流操作 */
const handleQuery = throttle(() => {
	state.queryParams.PageIndex = 1;
	queryList();
}, 500);
/** 获取用户列表 */
const queryList = () => {
	state.loading = true;
	blacklistPaged(state.queryParams)
		.then((response: any) => {
			state.tableData = response?.result.items;
			state.total = response?.result.total;
			state.loading = false;
		})
		.catch(() => {
			state.loading = false;
		});
};
/** 重置按钮操作 */
const resetQuery = throttle((formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
	handleQuery();
}, 500);
// 查看坐席话务明细
const onDetail = (row: any) => {
	operationRecordRef.value.openDialog(row);
};
onMounted(() => {
	queryList();
});
</script>
