<template>
    <div>
        <el-card class="!border-none mb-4" shadow="never">
            <el-form class="mb-[-16px]" :model="queryParams" inline>
                <el-form-item label="状态" prop="status">
                    <el-select v-model="queryParams.status" placeholder="请选择状态" clearable class="!flex-1">
                        <el-option label="全部" :value="0" />
                        <el-option label="带我审批" :value="1" />
                        <el-option label="我已审批" :value="2" />
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none" v-loading="pager.loading" shadow="never">
            <div class="mt-4">
                <el-table :data="pager.lists" @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55" />
                    <el-table-column label="申请人" prop="user_name" show-overflow-tooltip />
                    <el-table-column label="申请时间" prop="create_time" show-overflow-tooltip />
                    <el-table-column label="审批类型" prop="type_name" show-overflow-tooltip />
                    <el-table-column label="所属部门" prop="dept_name" show-overflow-tooltip />
                    <el-table-column label="当前审批人" prop="check_admin_users" show-overflow-tooltip />
                    <el-table-column label="审批状态" prop="check_status_text" show-overflow-tooltip />
                    <el-table-column label="操作" width="120" fixed="right">
                        <template #default="{ row }">
                            <el-button type="primary" link @click="handDetail(row)">
                                详情
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="flex mt-4 justify-end">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <detailPopup v-if="showDetail" ref="detailRef" @success="showDetail = false, getLists()"
            @close="showDetail = false, getLists()" :typeName="typeName" />
    </div>
</template>

<script lang="ts" setup name="oaSealCateLists">
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'
import { apiOaoaApprovelst } from '@/api/oa_Initiate'
import detailPopup from '@/views/oa_Initiate/detail.vue'
import { apiOaoaApproveDetail } from "@/api/oa_Initiate"

const detailRef = ref(null)
// 是否显示编辑框
const showDetail = ref(false)
const typeName = ref('')


// 查询条件
const queryParams = reactive({
    title: '',
    status: ''
})

// 选中数据
const selectData = ref<any[]>([])

// 表格选择后回调事件
const handleSelectionChange = (val: any[]) => {
    selectData.value = val.map(({ id }) => id)
}

// 获取字典数据
const { dictData } = useDictData('')

// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: apiOaoaApprovelst,
    params: queryParams
})

const handDetail = async (row: any) => {
    typeName.value = row.type_name
    let res = await apiOaoaApproveDetail({ id: row.id })
    showDetail.value = true
    await nextTick()
    detailRef.value?.open()
    detailRef.value?.setFormData(res)
}



getLists()
</script>

