<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="100px">
      <el-row :gutter="16">

        <el-form-item label="任务标题" prop="taskName">
          <el-input v-model="queryParams.taskName" placeholder="请输入任务标题" clearable style="width: 200px;" />
        </el-form-item>


        <el-form-item label="检查人" prop="checkerName">
          <el-input v-model="queryParams.checkerName" placeholder="请输入检查人" clearable style="width: 200px;" />
        </el-form-item>


        <el-form-item label="检查时间" prop="checkTime">
          <el-date-picker clearable v-model="dateRange" value-format="YYYY-MM-DD" type="daterange" range-separator="-"
            start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>


        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>

      </el-row>
    </el-form>

    <el-table v-loading="loading" :data="checkRecordList">
      <el-table-column label="任务编号" align="center" prop="taskCode" width="180" />
      <el-table-column label="任务标题" align="center" prop="taskName" />
      <el-table-column label="检查人" align="center" prop="checkerName" width="100" />
      <el-table-column label="检查时间" align="center" prop="checkTime" width="180">
        <template #default="scope">
          <span>{{ parseTime(scope.row.checkTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="被检查级别" align="center" prop="checkedLevel" width="100">
        <template #default="scope">
          <dict-tag :options="check_checked_level" :value="scope.row.checkedLevel" />
        </template>
      </el-table-column>
      <el-table-column label="被检查人/班组/主管" align="center" prop="checkedLevel">
        <template #default="scope">
          <div v-if="scope.row.checkedLevel === 'DEPARTMENT_LEVEL'">{{ scope.row.checkedDepartmentName }}</div>
          <div v-if="scope.row.checkedLevel === 'TEAM_LEVEL'">{{ scope.row.checkedTeamName }}</div>
          <div v-if="scope.row.checkedLevel === 'PERSONNEL_LEVEL'">{{ scope.row.checkedPersonnelName }}</div>
          <div v-if="scope.row.checkedLevel === 'BRIGADE_LEVEL'">{{ scope.row.checkedBrigadeName }}</div>
        </template>
      </el-table-column>
      <el-table-column label="整改状态" align="center" prop="statusDesc" width="100" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
        <template #default="scope">
          <el-button link type="info" icon="View" @click="handleDetail(scope.row)"
            v-hasPermi="['check:checkRecord:query']">详情</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize" @pagination="getList" />
    <Details v-model:show="show" :id="cellRecord.id" />
  </div>
</template>

<script setup name="CheckRecord">
import { checkCorrection } from "@/api/check/checkCorrection"
import Details from "./components/Deatils.vue"
import { useDict } from '@/utils/dict'
import { onMounted } from 'vue'
const { check_checked_level } = useDict('check_checked_level')

const checkRecordList = ref([])
const loading = ref(false)
const total = ref(0)
const dateRange = ref([])
const queryParams = ref({
  taskName: undefined,
  checkerName: undefined,
  checkTime: undefined,
  pageNum: 1,
  pageSize: 10
})

/** 查询检查记录列表 */
function getList() {
  loading.value = true
  let params = {
    ...queryParams.value,
    startDate: dateRange.value[0],
    endDate: dateRange.value[1]
  }

  checkCorrection(params).then(response => {
    checkRecordList.value = response.rows
    total.value = response.total
  }).finally(() => {
    loading.value = false
  })
}
const cellRecord = ref({})
const show = ref(false)
const handleDetail = (record) => {
  cellRecord.value = record
  show.value = true
}

const handleQuery = () => {
  getList()
}

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

<style>
.record-card {
  margin-bottom: 12px;
  padding: 8px 12px;
  /* border-left: 4px solid #52c41a;    */
  /* background: #f6ffed; */
  border-radius: 4px;
}

.record-line {
  display: flex;
  margin-bottom: 4px;
  font-size: 14px;
  line-height: 1.5;
}

.label {
  color: #666;
  margin-right: 6px;
  flex-shrink: 0;
  width: 70px;
}

.value {
  color: #333;
  flex: 1;
}
</style>