<template>
  <div class="statistics-order-detail-accept-type layout-pd">
    <el-card shadow="never">
      <!-- 表格 -->
      <ProTable
        ref="proTableRef"
        :columns="columns"
        :data="state.tableData"
        @updateTable="queryList"
        :loading="state.loading"
        :total="state.total"
        v-model:page-index="state.queryParams.PageIndex"
        v-model:page-size="state.queryParams.PageSize"
        @export-current="exportCurrent"
        @export-all="exportAll"
        :key="Math.random()"
      >
        <template #expiredStatusText="{ row }">
          <span :class="'overdue-status-' + row.expiredStatus" :title="row.expiredStatusText"></span>
        </template>
        <template #title="{ row }">
          <order-detail :order="row" @updateList="queryList">{{ row.title }}</order-detail>
        </template>
      </ProTable>
    </el-card>
  </div>
</template>
<script setup lang="tsx" name="statisticsDetailSourceOrder">
import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
import type { FormInstance } from 'element-plus';
import other from '@/utils/other';
import { useRoute, useRouter } from 'vue-router';
import { formatDate } from '@/utils/formatTime';
import { departmentAcceptTypeDetail } from '@/api/statistics/order';

// 引入组件
const OrderDetail = defineAsyncComponent(() => import('@/components/OrderDetail/index.vue')); // 工单详情

// 定义变量内容
const state = reactive<any>({
  queryParams: {
    PageIndex: 1, // 当前页
    PageSize: 10, // 每页条数
  },
  tableData: [], //表单
  loading: false, // 加载
  total: 0, // 总数
});
const ruleFormRef = ref<RefType>(); // 表单ref
const route = useRoute(); // 路由
const router = useRouter(); // 路由
const proTableRef = ref<RefType>(); // 表格ref
// 表格配置项
const columns = ref<any[]>([
  { prop: 'expiredStatusText', label: '超期状态', align: 'center' ,width: 80,fixed:'left'},
  { prop: 'statusText', label: '工单状态', width: 100 },
  { prop: 'sourceChannel', label: '来源方式' },
  { prop: 'actualHandleStepName', label: '当前节点', width: 120 },
  { prop: 'reTransactNum',label: '重办次数',},
  { prop: 'no', label: '工单编码', width: 150 },
  {
    prop: 'startTime',
    label: '受理时间',
    width: 170,
    render: (scope) => {
      return <span>{formatDate(scope.row.startTime, 'YYYY-mm-dd HH:MM:SS')}</span>;
    },
  },
  { prop: 'title', label: '工单标题', width: 300 },
  {
    prop: 'expiredTime',
    label: '工单期满时间',
    width: 170,
    render: (scope) => {
      return <span>{formatDate(scope.row.expiredTime, 'YYYY-mm-dd HH:MM:SS')}</span>;
    },
  },
  { prop: 'actualHandleOrgName', label: '接办部门', width: 170 },
  {
    prop: 'actualHandleTime',
    label: '接办时间',
    width: 170,
    render: (scope) => {
      return <span>{formatDate(scope.row.actualHandleTime, 'YYYY-mm-dd HH:MM:SS')}</span>;
    },
  },
  {
    prop: 'filedTime',
    label: '办结时间',
    width: 170,
    render: (scope) => {
      return <span>{formatDate(scope.row.filedTime, 'YYYY-mm-dd HH:MM:SS')}</span>;
    },
  },
  { prop: 'acceptType', label: '受理类型', width: 150 },
  { prop: 'hotspotName', label: '热点分类', width: 200 },
  { prop: 'acceptorName', label: '受理人', width: 120 }
]);
// 手动查询，将页码设置为1
const handleQuery = () => {
  state.queryParams.PageIndex = 1;
  queryList();
};
const historyParams = history.state;
/** 获取列表 */
const queryList = () => {
  let request = other.deepClone(state.queryParams);
  request.StartDate = historyParams.StartDate;
  request.EndDate = historyParams.EndDate;
  request.OrgCode = historyParams.OrgCode;
  request.AcceptTypeCode = historyParams.AcceptTypeCode;
  request.TypeCode = historyParams.TypeCode;
  state.loading = true;
  console.log(historyParams)
  departmentAcceptTypeDetail(request)
    .then((response: any) => {
      state.tableData = response?.result.items ?? [];

      state.total = response?.result.total;
      state.loading = false;
    })
    .catch(() => {
      state.loading = false;
    });
};
/** 重置按钮操作 */
const resetQuery = (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  formEl.resetFields();
  queryList();
};
const exportCurrent = () => {
  console.log('导出当前页', proTableRef.value);
};
const exportAll = () => {
  console.log('导出全部', proTableRef.value);
};
onMounted(() => {
  queryList();
});
</script>