<template>
    <div>

        <CardCommon :type='type' :search-data-by-name="findSceneLabelFun" :get-data="getSceneLabelListFun"
            :delete-table-data="deleteSceneLabelFun" :submit-drawer="updateSceneLabelFun" :add-data="saveSceneLabelFun">
        </CardCommon>

    </div>
</template>

<script setup lang="ts">
import { updateSceneLabel, getSceneLabelList, deleteSceneLabel, findSceneLabelByName, saveSceneLabel, SceneLabel } from '@/api/template/template';
import { ElMessage, ElMessageBox } from 'element-plus';
import CardCommon, { TableModel } from './CardCommon.vue'
import { DataCommon } from './TitleCommon.vue';
import { ref } from 'vue';
const type = ref('标签');


// 添加数据
function saveSceneLabelFun(data: SceneLabel) {
    return saveSceneLabel(data).then(res => {
        console.log(res);
        return res;

    }).catch(error => {
        ElMessageBox.alert(error, '异常', {
            confirmButtonText: 'OK',
            callback: () => {
                ElMessage({
                    type: 'info',
                    message: `添加数据失败`,
                })
            },
        })
    });
};

// 根据名称查找
function findSceneLabelFun(data: DataCommon) {
    console.log('findSceneLabelByName', data.name, data.page, data.size);
    return findSceneLabelByName(data.name, data.page, data.size).then((res) => {
        console.log(res)
        return res;
    }).catch(error => {
        ElMessageBox.alert(error, '异常', {
            confirmButtonText: 'OK',
            callback: () => {
                ElMessage({
                    type: 'info',
                    message: `查询数据失败`,
                })
            },
        })
    });
}

// 查找数据列表-finish
function getSceneLabelListFun(data) {
    return getSceneLabelList(data.page, data.size).then((res) => {
        return res
    }).catch(error => {
        ElMessageBox.alert(error.message, '异常', {
            confirmButtonText: 'OK',
            callback: () => {
                ElMessage({
                    type: 'info',
                    message: `查询数据失败`,
                })
            },
        })
    });
}

// 删除数据
function deleteSceneLabelFun(data: TableModel) {
    console.log('detele', data);
    return deleteSceneLabel(data.id).then(res => {
        console.log(res);
        return res;

    }).catch(error => {
        ElMessageBox.alert(error, '异常', {
            confirmButtonText: 'OK',
            callback: () => {
                ElMessage({
                    type: 'info',
                    message: `删除数据失败`,
                })
            },
        })
    });
}

// 编辑数据
function updateSceneLabelFun(data: SceneLabel) {
    console.log('edit', data);
    return updateSceneLabel(data).then(res => {
        console.log(res);
        return res;

    }).catch(error => {
        ElMessageBox.alert(error, '异常', {
            confirmButtonText: 'OK',
            callback: () => {
                ElMessage({
                    type: 'info',
                    message: `编辑数据失败`,
                })
            },
        })
    });
}





</script>

<style scoped></style>