<!-- 存档 -->
<template>
    <div style="overflow: hidden;display: flex;flex-direction: column;">
        <n-button type="primary" style="margin-bottom: 10px;width: 120px;" @click="addFun">备份存档</n-button>
        <div style="flex: 1;overflow-y: auto">
            <n-table :bordered="false" :single-line="false" :max-height="250">
                <thead>
                    <tr>
                        <th>时间</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <tr v-for="(item, index) in tableData.list" :key="index">
                        <td>{{ item.T_time }}</td>
                        <td style="display: flex;align-items: center;">
                            <n-button style="margin-right: 10px;" @click="RecFun(item)">恢复</n-button>
                            <n-button type="error" @click="delFun(item)">删除</n-button>
                        </td>
                    </tr>
                </tbody>
            </n-table>
        </div>
    </div>
</template>

<script setup>
import { TaskCopyList, TaskCopyAdd, TaskCopydel,TaskCopyRec } from '@/api';
import { watch } from 'vue'
import { useMessage, useDialog } from "naive-ui";
const message = useMessage();
const dialogs = useDialog();
const props = defineProps({
    task: {
        type: Object,
        default: () => ({}),
    },
})
const tableData = reactive({
    list: [],
})
//恢复存档
const RecFun = async (e) => {
    const { data: res } = await TaskCopyRec({
        T_task_id: props.task.T_task_id,
        T_copy_id: e.T_copy_id
    });
    console.log('存档返回', res)
    if (res.Code == 200 && res.Msg == 'ok!') {
        message.success('恢复成功')
        alldeleteApi()
    }
}
//添加存档
const delFun = (e) => {
    dialogs.warning({
        title: '提示',
        content: `删除存档，是否继续？`,
        positiveText: '删除',
        negativeText: '取消',
        onPositiveClick: async () => {
            const { data: res } = await TaskCopydel({
                T_copy_id: e.T_copy_id
            });
            console.log('存档返回', res)
            if (res.Code == 200) {
                message.success('删除存档成功')
                alldeleteApi()
            }
        },
        onNegativeClick: () => {
            message.warning('已取消删除存档')
        }
    })

}
//添加存档
const addFun = async () => {
    const { data: res } = await TaskCopyAdd({
        T_task_id: props.task.T_task_id
    });
    console.log('存档返回', res)
    if (res.Code == 200 && res.Msg == 'ok!') {
        message.success('存档成功')
        alldeleteApi()
    }
}
const alldeleteApi = async () => {
    const { data: res } = await TaskCopyList({
        T_task_id: props.task.T_task_id,
        page: 1,
        page_z: 9999,
    });
    if (res.Code == 200) {
        tableData.list = res.Data.List
    }
    console.log('返回', res)

}
watch(() => props.task, (newValue) => {//有焦点时存
    alldeleteApi()
}, { deep: true, immediate: true });

</script>

<style lang="scss" scoped></style>
  