<template>
  <div>
    <el-card>
      <el-form
        :model="searchForm"
        label-width="70px"
        @submit.prevent="fnResetPaginationTransfer"
      >
        <el-row>
          <el-col :span="6">
            <el-form-item label="关键字" prop="KEYWORDS">
              <el-input
                v-model="searchForm.KEYWORDS"
                placeholder="请输入关键字"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="部门" prop="DEPTIDS">
              <layout-department
                v-model="searchForm.DEPTIDS"
                multiple
                show-checkbox
                collapse-tags
                root-disabled="Y"
              />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="时间" prop="dates">
              <el-date-picker
                v-model="searchForm.dates"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="YYYY-MM-DD"
                format="YYYY-MM-DD"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label-width="10px">
              <el-button type="primary" native-type="submit">搜索</el-button>
              <el-button native-type="reset" @click="fnResetPaginationTransfer">
                重置
              </el-button>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-form-item label-width="10px" class="end">
              <el-button
                @click="
                  router.push({
                    path: '/statistical_analysis/detection_situation/print',
                    query: {
                      STARTTIME: searchForm.dates?.[0],
                      ENDTIME: searchForm.dates?.[1],
                      DEPTIDS: searchForm.DEPTIDS?.join(','),
                    },
                  })
                "
              >
                打印
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
    <layout-card>
      <layout-table :data="list" :show-pagination="false">
        <el-table-column label="序号" width="70">
          <template v-slot="{ $index }">
            {{ serialNumber(pagination, $index) }}
          </template>
        </el-table-column>
        <el-table-column prop="DEPARTNAME_ALL" label="部门" />
        <el-table-column prop="POSTNAME" label="岗位" />
        <el-table-column prop="USERNAME" label="姓名" />
        <el-table-column prop="listCount" label="负责清单数" />
        <el-table-column prop="staCount" label="应检查清单次数" />
        <el-table-column prop="cheCount" label="实际检查次数" />
        <el-table-column prop="percent" label="检查率" />
      </layout-table>
    </layout-card>
  </div>
</template>

<script setup>
import LayoutDepartment from "@/components/department/index.vue";
import { serialNumber } from "@/assets/js/utils.js";
import useListData from "@/assets/js/useListData.js";
import {
  getDetectionSituationList,
  getDetectionSituationListTime,
} from "@/request/statistical_analysis.js";
import { useRouter } from "vue-router";

const router = useRouter();
const { list, searchForm, pagination, fnResetPagination } = useListData(
  getDetectionSituationList,
  {
    immediate: false,
  }
);
const fnResetPaginationTransfer = () => {
  fnResetPagination({
    STARTTIME: searchForm.value.dates?.[0],
    ENDTIME: searchForm.value.dates?.[1],
    DEPTIDS: searchForm.value.DEPTIDS?.join(","),
  });
};
const fnGetData = async () => {
  const resData = await getDetectionSituationListTime();
  searchForm.value.dates = [resData.pd.MINTIME, resData.pd.MAXTIME];
  fnResetPaginationTransfer();
};
fnGetData();
</script>

<style scoped lang="scss"></style>
