<template>
  <div class="p-2 flex flex-col h-full">
    <pageheader></pageheader>
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" label-width="120px" :inline="true">
            <el-form-item label="选择日期" prop="checkdata">
              <el-date-picker
                range-separator="到"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="YYYY/MM/DD"
                format="YYYY/MM/DD"
                v-model="checkdata"
                type="daterange"
                placeholder="选择日期"
              />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="handleQuery">搜索</el-button>
              <el-button @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-card class="flex-1" shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <span style="font-size: 1.2rem">统计列表</span>
          </el-col>
        </el-row>
      </template>

      <el-table v-loading="loading" border :data="routeList">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="巡检人员" align="center" prop="roleName" show-overflow-tooltip />
        <el-table-column label="计划巡检任务" align="center" prop="totalTasks" />
        <el-table-column label="按时完成" align="center" prop="completedTasks">
          <template #default="scope">
            {{ scope.row.completedTasks - scope.row.outCompletedTasks }}
          </template>
        </el-table-column>
        <el-table-column label="超时完成" align="center" prop="outCompletedTasks" />
        <el-table-column label="超时未完成" align="center" prop="outUncompletedTasks"></el-table-column>
        <el-table-column label="进行中" align="center" prop="activeTask" />
        <el-table-column label="未开始" align="center" prop="pendingTask" />
        <el-table-column label="完成率" align="center" prop="onTimeRateDisplay" />
      </el-table>
      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    </el-card>
  </div>
</template>

<script setup name="Route" lang="ts">
import { list_statapi } from '@/api/system/Inspection';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;

const routeList = ref<any[]>([]);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const queryFormRef = ref<ElFormInstance>();

const data = reactive({
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    taskTimeBegin: '',
    taskTimeEnd: ''
  }
});

const checkdata = ref([]);
const { queryParams } = toRefs(data);
/** 查询巡检路线列表 */
const getList = async () => {
  loading.value = true;
  list_statapi(queryParams.value)
    .then((res) => {
      routeList.value = res.rows;
      total.value = res.total;
    })
    .finally(() => {
      loading.value = false;
    });
};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.taskTimeBegin = checkdata.value[0];
  queryParams.value.taskTimeEnd = checkdata.value[1];
  queryParams.value.pageNum = 1;
  getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};

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

<style lang="scss" scoped>
.el-table {
  height: calc(100% - 80px);
}
</style>
