<template>
	<div class="statistics-order-department-accept-type-container layout-pd">
		<!-- 搜索  -->
		<el-card shadow="never">
			<el-form :model="state.queryParams" ref="ruleFormRef" @submit.native.prevent inline>
				<el-form-item label="归档类型" prop="TypeCode">
					<el-select v-model="state.queryParams.TypeCode" placeholder="部门名称" @change="queryList">
						<el-option label="全部" value="0" />
						<el-option label="中心归档" value="1" />
						<el-option label="部门归档" value="2" />
					</el-select>
				</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>
					<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">
			<!-- 表格 -->
			<ProTable
				ref="proTableRef"
				:pagination="false"
				:columns="columns"
				:data="state.tableData"
				@updateTable="queryList"
				:loading="state.loading"
        show-summary
			>
<!--				<template #allCount="{ row }">
					<el-button type="primary" link>
						{{ row.allCount }}
					</el-button>
				</template>-->
			</ProTable>
		</el-card>
	</div>
</template>
<script setup lang="ts" name="statisticsOrderDepartmentAcceptType">
import { onMounted, reactive, ref } from 'vue';
import { ElButton, FormInstance } from 'element-plus';
import { throttle } from '@/utils/tools';
import { departmentAcceptType } from '@/api/statistics/order';
import { shortcuts } from '@/utils/constants';
import dayjs from 'dayjs';
import ProTable from '@/components/ProTable/index.vue';
// 定义变量内容
const ruleFormRef = ref<RefType>(); // 表单ref
const columns = reactive<any[]>([
	{ type: 'selection', fixed: 'left', width: 55 },
	{ prop: 'orgName', label: '部门名称',minWidth:100, align: 'center' },
	{ prop: 'orgType', label: '部门类别',minWidth:100 , align: 'center'},
	{
		prop: 'allType',
		label: '所有类型',
   align: 'center',
		_children: [
			{ prop: 'allCount', label: '总件数', align: 'center' },
			{ prop: 'allTimes', label: '总时长', align: 'center' },
			{ prop: 'averageTime', label: '总平均', align: 'center' },
		],
	},
  {
    prop: 'zxType',
    label: '咨询类',
   align: 'center',
    _children: [
      { prop: 'zxAllCount', label: '咨询件数', align: 'center' },
      { prop: 'zxAllTimes', label: '咨询时长', align: 'center' },
      { prop: 'zxAverageTime', label: '咨询平均', align: 'center' },
    ],
  },
  {
    prop: 'jbType',
    label: '举报类',
   align: 'center',
    _children: [
      { prop: 'jbAllCount', label: '举报件数', align: 'center' },
      { prop: 'jbAllTimes', label: '举报时长', align: 'center' },
      { prop: 'jbAverageTime', label: '举报平均', align: 'center' },
    ],
  },
  {
    prop: 'tsType',
    label: '投诉类',
    align: 'center',
    _children: [
      { prop: 'tsAllCount', label: '投诉件数', align: 'center' },
      { prop: 'tsAllTimes', label: '投诉时长', align: 'center' },
      { prop: 'tsAverageTime', label: '投诉平均', align: 'center' },
    ],
  },
  {
    prop: 'qzType',
    label: '求助类', align: 'center',
    _children: [
      { prop: 'qzAllCount', label: '求助件数', align: 'center' },
      { prop: 'qzAllTimes', label: '求助时长', align: 'center' },
      { prop: 'qzAverageTime', label: '求助平均', align: 'center' },
    ],
  },
  {
    prop: 'jyType',
    label: '建议类', align: 'center',
    _children: [
      { prop: 'jyAllCount', label: '建议件数', align: 'center' },
      { prop: 'jyAllTimes', label: '建议时长', align: 'center' },
      { prop: 'jyAverageTime', label: '建议平均', align: 'center' },
    ],
  },
]);
const state = reactive(<any>{
	queryParams: {
		// 查询条件
		TypeCode: '0', // 关键词
		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 StartDate = null;
	let EndDate = null;
	if (state.queryParams?.crTime) {
		StartDate = state.queryParams?.crTime[0];
		EndDate = state.queryParams?.crTime[1];
	}
	const request = {
		StartDate,
		EndDate,
		TypeCode: state.queryParams.TypeCode,
	};
	departmentAcceptType(request)
		.then((res: any) => {
			state.tableData = res.result ?? [];
			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);
onMounted(() => {
	queryList();
});
</script>
