<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="班组" prop="teamName">
        <el-input v-model="queryParams.teamName" placeholder="请输入班组" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="处理人" prop="handler">
        <el-input v-model="queryParams.handler" placeholder="请输入处理人" clearable @keyup.enter="handleQuery" />
      </el-form-item>
      <el-form-item label="整改状态" prop="isRectified">
        <el-select v-model="queryParams.isRectified" placeholder="请选择" clearable style="width:130px">
          <el-option label="整改完毕" value="整改完毕" />
          <el-option label="整改中" value="整改中" />
          <el-option label="未整改" value="未整改" />
        </el-select>
      </el-form-item>
      <el-form-item label="台账日期">
        <el-date-picker v-model="dateRange" type="daterange" value-format="YYYY-MM-DD"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" clearable />
      </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-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['ledger:trainingIssue:export']">导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" />
    </el-row>
    <el-table v-loading="loading" :data="list">
      <el-table-column label="问题台账日期" align="center" prop="recordDate" width="170">
        <template #default="{ row }">{{ row.recordDate }}</template>
      </el-table-column>
      <el-table-column label="班组" align="center" prop="teamName" width="120" />
      <el-table-column label="处理人" align="center" prop="handler" width="100" />
      <el-table-column label="问题台账内容" align="center" prop="ledgerContent" min-width="200" show-overflow-tooltip />
      <el-table-column label="具体问题" align="center" prop="specificProblem" min-width="150" show-overflow-tooltip />
      <el-table-column label="二次复核问题" align="center" prop="recheckProblem" min-width="150" show-overflow-tooltip />
      <el-table-column label="是否完成整改" align="center" prop="isRectified" width="120">
        <template #default="{ row }">
          <el-tag :type="row.isRectified === '整改完毕' ? 'success' : row.isRectified === '整改中' ? 'warning' : 'danger'">
            {{ row.isRectified || '-' }}
          </el-tag>
        </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" />
  </div>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue'
import { listTrainingIssue, exportTrainingIssue } from '@/api/ledger/index'
import { parseTime } from '@/utils/ruoyi'
defineOptions({ name: 'LedgerTrainingIssue' })
const loading = ref(false), list = ref([]), total = ref(0), showSearch = ref(true)
const dateRange = ref([]), queryRef = ref(null)
const queryParams = reactive({ pageNum: 1, pageSize: 10, teamName: '', handler: '', isRectified: '' })
function getList() {
  loading.value = true
  const p = { ...queryParams }
  if (dateRange.value?.length === 2) { p['params[beginTime]'] = dateRange.value[0]; p['params[endTime]'] = dateRange.value[1] }
  listTrainingIssue(p).then(r => { list.value = r.rows; total.value = r.total }).finally(() => loading.value = false)
}
function handleQuery() { queryParams.pageNum = 1; getList() }
function resetQuery() { dateRange.value = []; queryRef.value?.resetFields(); handleQuery() }
function handleExport() {
  const p = { ...queryParams }
  if (dateRange.value?.length === 2) { p['params[beginTime]'] = dateRange.value[0]; p['params[endTime]'] = dateRange.value[1] }
  exportTrainingIssue(p)
}
onMounted(getList)
</script>
