<template>
	<div class="statistics-call-transfer-out-container layout-pd">
		<!-- 搜索  -->
		<el-card shadow="never">
			<el-form :model="state.queryParams" ref="ruleFormRef" @submit.native.prevent  inline>
				<el-form-item label="外线号码" prop="CDPN">
					<el-input v-model="state.queryParams.CDPN" placeholder="外线号码" clearable @keyup.enter="queryList" class="keyword-input" />
				</el-form-item>
				<el-form-item label="受理人" prop="UserName">
					<el-input v-model="state.queryParams.UserName" placeholder="受理人" clearable @keyup.enter="queryList" class="keyword-input" />
				</el-form-item>
				<el-form-item label="转外线时间" prop="crTime">
					<el-date-picker
						v-model="state.queryParams.crTime"
						type="datetimerange"
						unlink-panels
						range-separator="至"
						start-placeholder="开始时间"
						end-placeholder="结束时间"
						:shortcuts="shortcuts"
						@change="queryList"
						value-format="YYYY-MM-DD[T]HH:mm:ss"
					/>
				</el-form-item>
				<el-form-item label-width="0">
					<el-button type="primary" @click="queryList" :loading="state.loading"> <SvgIcon name="ele-Search" class="mr5" />查询 </el-button>
					<el-button @click="resetQuery(ruleFormRef)" class="default-button" :loading="state.loading">
						<SvgIcon name="ele-Refresh" class="mr5" />重置
					</el-button>
				</el-form-item>
			</el-form>
		</el-card>
		<el-card shadow="never">
			<!-- 表格 -->
			<el-table :data="state.tableData" v-loading="state.loading" row-key="userId" ref="multipleTableRef" @selection-change="handleSelectionChange">
				<el-table-column type="selection" width="55" align="center" />
				<el-table-column prop="cdpn" label="外线号码" show-overflow-tooltip align="center"></el-table-column>
				<el-table-column prop="cpn" label="来电号码" show-overflow-tooltip align="center"></el-table-column>
				<el-table-column prop="telNo" label="转接分机号" show-overflow-tooltip align="center"></el-table-column>
				<el-table-column prop="invalid" label="转外线时间" show-overflow-tooltip align="center">
					<template #default="{ row }">
						<span>{{ formatDate(row.createdTime, 'YYYY-mm-dd HH:MM:SS') }}</span>
					</template>
				</el-table-column>
				<el-table-column prop="userName" label="受理人" show-overflow-tooltip align="center"></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>
	</div>
</template>
<script setup lang="ts" name="statisticsCallTransferOut">
import { onMounted, reactive, ref } from 'vue';
import { ElButton, FormInstance } from 'element-plus';
import { throttle } from '@/utils/tools';
import { callTransfer } from '@/api/statistics/call';
import { shortcuts } from '@/utils/constants';
import { formatDate } from '@/utils/formatTime';
import dayjs from 'dayjs';
// 定义变量内容
const ruleFormRef = ref<RefType>(); // 表单ref
const state = reactive(<any>{
	queryParams: {
		// 查询条件
		PageIndex: 1,
		PageSize: 10,
		Keyword: null, // 关键词
		crTime: [dayjs().startOf('day').format('YYYY-MM-DD HH:mm:ss'), dayjs().endOf('day').format('YYYY-MM-DD HH:mm:ss')], // 时间默认今天开始到今天结束
	},
	tableData: [], //表单
	loading: false, // 加载
	total: 0, // 总数
});
/** 获取列表 */
const queryList = throttle(() => {
	state.loading = true;
	let StartTime = null;
	let EndTime = null;
	if (state.queryParams?.crTime) {
		StartTime = state.queryParams?.crTime[0];
		EndTime = state.queryParams?.crTime[1];
	}
	const request = {
		StartTime,
		EndTime,
		UserName: state.queryParams.UserName,
		CDPN: state.queryParams.CDPN,
		PageIndex: state.queryParams.PageIndex,
		PageSize: state.queryParams.PageSize,
		Keyword: state.queryParams.Keyword,
		SortField: state.queryParams.SortField,
		SortRule: state.queryParams.SortRule,
	};
	callTransfer(request)
		.then((res: any) => {
			state.tableData = res.result?.items ?? [];
			state.total = res.result?.total ?? 0;
			state.loading = false;
		})
		.catch(() => {
			state.loading = false;
		});
}, 300);
/** 重置按钮操作 */
const resetQuery = throttle((formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
	queryList();
}, 300);
// 表格多选
const multipleTableRef = ref<RefType>();
const multipleSelection = ref<any>([]);
const handleSelectionChange = (val: any[]) => {
	multipleSelection.value = val;
};

onMounted(() => {
	queryList();
});
</script>
