<template>
    <div>
        <el-card class="!border-none mb-4" shadow="never">
            <el-form class="mb-[-16px]" :model="queryParams" inline>
                <el-form-item label="开始时间" prop="uid">
                    <el-date-picker class="flex-1 !flex" v-model="queryParams.start_time" clearable type="date"
                        value-format="YYYY-MM-DD" placeholder="选择开始时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="结束时间" prop="uid">
                    <el-date-picker class="flex-1 !flex" v-model="queryParams.end_time" clearable type="date"
                        value-format="YYYY-MM-DD" placeholder="选择结束时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="状态" prop="quit_time">
                    <el-select v-model="queryParams.status" placeholder="请选择状态" class="flex-1">
                        <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="total_amount" show-overflow-tooltip />
                    <el-table-column label="状态" prop="check_status_text" show-overflow-tooltip />
                    <el-table-column label="报销人" prop="check_admin_users" show-overflow-tooltip />
                    <el-table-column label="报销部门" prop="dept_name" show-overflow-tooltip />
                    <el-table-column label="报销保证编号" prop="" show-overflow-tooltip />
                    <el-table-column label="原始单据日期" prop="expense_time" show-overflow-tooltip />
                    <el-table-column label="入账月份" prop="income_month" show-overflow-tooltip />
                    <el-table-column label="录入时间" prop="create_time" show-overflow-tooltip />
                    <el-table-column label="当前审核人" prop="remark" show-overflow-tooltip />
                    <el-table-column label="打款人" prop="" show-overflow-tooltip />
                    <el-table-column label="打款确认时间" prop="" show-overflow-tooltip />
                    <el-table-column label="操作" width="120" fixed="right">
                        <template #default="{ row }">
                            <el-button link @click="handDetail(row.id)">
                                详情
                            </el-button>
                            <el-button type="primary" link @click="handPayment(row.id)" v-if="row.check_status != 2">
                                设置打款
                            </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()" />
    </div>
</template>

<script lang="ts" setup name="oaPersonalQuitLists">
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'
import { apiExpenseList2, apiExpenseDetail, apiExpensePayment } from '@/api/oa_financial'
import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'
import detailPopup from './detail.vue'

const editRef = shallowRef<InstanceType<typeof EditPopup>>()
// 是否显示编辑框
const showEdit = ref(false)

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

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

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

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

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

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



// 编辑


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

const handPayment = async (id: any) => {
    let res = await apiExpensePayment({ id })
    getLists()

}


getLists()
</script>
