<!-- 视频列表 -->
<template>
    <div class="table-box">
        <ProTable
            ref="proTableRef"
            :formData="dataStore.formData"
            :columns="dataStore.columns"
            :request-api="getAttachmentTrashListApi"
            :init-param="dataStore.initParam"
        >
            <template #image="scope">
                <el-image :src="scope.row.image ? h + scope.row.image : ''" style="width: 60px; height: 60px" />
            </template>
            <template #status="scope">
                <el-tag type="danger" effect="dark">{{ scope.row.status ? "删除" : "删除" }}</el-tag>
            </template>

            <template #operation="scope">
                <el-button size="small" type="danger" @click="handleBtnClick('删除', scope.row)">删除</el-button>
                <el-button size="small" type="primary" @click="handleBtnClick('恢复', scope.row)">恢复</el-button>
            </template>
        </ProTable>
    </div>
</template>

<script setup lang="ts" name="downloadRecycleListIndex">
import ProTable from "@/components/ProTable/index.vue";
import { messageBox } from "@/utils/messageBox";
import { useMsg } from "@/hooks/useMsg";
//列表接口
import { getAttachmentTrashListApi, getAttachmentTrashRestoreApi, getAttachmentTrashDelApi } from "@/api/modules/downloadRecycle";
import { getCategorysApi } from "@/api/modules/downloadClass";
//深拷贝方法
import { cloneDeep } from "lodash-es";
//表格和搜索條件
import { RULE_FORM, FORM_DATA, COLUMNS } from "./constant/index";
// 获取 ProTable 元素，调用其获取刷新数据方法（还能获取到当前查询参数，方便导出携带参数）
const proTableRef = ref<any>(null);
//图片地址
import { h } from "@/utils/url";
// 数据源
const dataStore = reactive<any>({
    columns: COLUMNS, //列表配置项
    initParam: cloneDeep(RULE_FORM), // 初始化搜索条件|重置搜索条件
    ruleForm: cloneDeep(RULE_FORM), // 搜索參數
    formData: FORM_DATA //搜索配置项
});
//分类列表
const getCategorys = async () => {
    const result = await getCategorysApi({ is_show: 0 });

    if (result?.code === 0) {
        let arr: any[] = [];
        result?.data?.forEach((item: any) => {
            let obj = {
                value: item.id,
                label: item.name
            };
            arr.push(obj);
        });
        dataStore.formData[1].options = arr;
    }
};
getCategorys();
//删除
const getAttachmentTrashDel = (id: any) => {
    messageBox("你确定要删除?", async () => {
        const result = await getAttachmentTrashDelApi(id);
        if (result?.code === 0) {
            const { msg } = result;
            useMsg("success", msg);
            proTableRef?.value?.getTableList();
        }
    });
};
//恢复
const getAttachmentTrashRestore = async (id: any) => {
    const result = await getAttachmentTrashRestoreApi(id);
    if (result?.code === 0) {
        useMsg("success", result?.msg);
        proTableRef?.value?.getTableList();
    }
};
//按钮点击事件
const handleBtnClick = (type: any, row: any) => {
    if (type === "恢复") {
        getAttachmentTrashRestore(row.id);
    }
    //删除
    if (type === "删除") {
        getAttachmentTrashDel(row.id);
    }
};
</script>

<style scoped></style>
