<template>
    <div class="tit" v-if="baseData.tit">{{ baseData.tit }}</div>

    <div style="float: right;"> <el-dropdown>
            <span class="el-dropdown-link">
                操作
                <el-icon class="el-icon--right">
                    <arrow-down />
                </el-icon>
            </span>
            <template #dropdown>
                <el-dropdown-menu>
                    <el-dropdown-item @click="handleAdd">添加</el-dropdown-item>
                    <el-dropdown-item> 编辑</el-dropdown-item>
                    <el-dropdown-item> 删除</el-dropdown-item>
                    <export-data :fetch-fun="baseData.fetchFun" :params="baseData.queryParams" :page-size="15"
                        :isMenuLi="true" />
                </el-dropdown-menu>
            </template>
        </el-dropdown>
    </div>

    <el-table :data="pager.lists" style="width: 100%">
        <el-table-column :label="item.label" :prop='item.prop' v-for="(item, index) in baseData.columnList" :key="index" />
    </el-table>
    <div class="flex justify-end mt-4">
        <pagination v-model="pager" @change="getLists" />
    </div>
    <EditPopup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" :project="project" />
</template>
<script setup>

import { ref, reactive, defineProps, toRaw, defineAsyncComponent } from "vue"
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
import { useDictData } from '@/hooks/useDictOptions'

const props = defineProps({
    baseData: Object,
    project: Object,
    editPath: String
})

const EditPopup = defineAsyncComponent(() => import(`../../${props.editPath}/edit.vue`));

// edit
const editRef = ref(null)
const showEdit = ref(false)

// 添加
const handleAdd = async () => {
    showEdit.value = true
    setTimeout(() => {
        editRef.value?.open('add')
    }, 700);
}

// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: props.baseData.fetchFun,
    params: props.baseData.queryParams || ""
})

getLists()


</script>
<style lang="scss" scoped>
.tit {
    font-size: 1.2em;
    margin-bottom: 10px;
}


.example-showcase .el-dropdown-link {
    cursor: pointer;
    color: var(--el-color-primary);
    display: flex;
    align-items: center;
}
</style>