<!-- 处理日志弹窗 -->
<template>
    <ele-modal
        :width="700"
        v-model="visible"
        title="处理日志"
        @open="handleOpen"
        :body-style="{ padding: '0' }"
    >
        <common-table
            ref="pageRef"
            :pageConfig="pageConfig"
            :columns="columns"
            :tools="false"
            :immediate="false"
        />
        <template #footer>
            <el-button @click="handleCancel">关闭</el-button>
        </template>
    </ele-modal>
</template>

<script setup>
    import { ref, reactive } from 'vue';
    import request from '@/utils/request';
    import CommonTable from '@/components/CommonPage/CommonTable.vue';

    const pageRef = ref(null);
    /** 弹窗是否打开 */
    const visible = defineModel({ type: Boolean });
    /** 当前记录ID */
    const currentId = ref(null);

    /** 关闭弹窗 */
    const handleCancel = () => {
        visible.value = false;
    };

    /** 弹窗打开事件 */
    const handleOpen = (id) => {
        if (id) {
            currentId.value = id;
            visible.value = true;
            pageConfig.value.pageUrl = `/book/bookNoData/getDisposeLog/${id}`;
            pageRef.value?.reload();
        }
    };
    // 1-检测 2-导出 3-爬虫 4-手动新增图书
    const typeList = ref([
        { label: '检测', value: 1 },
        { label: '导出', value: 2 },
        { label: '爬虫', value: 3 },
        { label: '手动新增图书', value: 4 }
    ]);

    /** 表格列配置 */
    const columns = ref([
        {
            label: '处理方式',
            prop: 'disposeType',
            align: 'center',
            formatter: (row) => {
                return typeList.value.find((d) => d.value == row.disposeType)
                    ?.label;
            }
        },
        { label: '处理人', prop: 'disposeName', align: 'center' },
        { label: '处理时间', prop: 'createTime', align: 'center', width: 180 }
    ]);

    const pageConfig = ref({
        pageUrl: '',
        fileName: '处理日志',
        cacheKey: 'deal-log'
    });

    defineExpose({
        handleOpen
    });
</script>
