// 目录或者指标的删除
import apiDataEDB from '@/api/dataEDB'
import { showDialog , showToast } from 'vant';


export function useEDBDelete(){
    // 删除分类
    async function handleClassifyDelete(data){
        const res=await apiDataEDB.edbClassifyDelete({
            ClassifyId:data.ClassifyId,
            EdbInfoId:data.EdbInfoId
        })
        if(res.Ret===200){
            showToast('删除成功')
            return true
        }
    }

    async function edbClassifyDelete(data){
        const res=await apiDataEDB.edbClassifyDeleteCheck({
            ClassifyId:data.ClassifyId,
            EdbInfoId:data.EdbInfoId
        })
        if(res.Ret===200){
            if([1,3,4].includes(res.Data.DeleteStatus)){
                let message=res.Data.TipsMsg
                if(res.Data.DeleteStatus === 1) message='该目录关联指标不可删除'
                if(res.Data.DeleteStatus === 3) message='当前指标已用作画图，不可删除'
                showDialog({
                    title: '删除失败',
                    message: message,
                    confirmButtonText:'知道了'
                })
                
            }else if(res.Data.DeleteStatus === 0 && !data.EdbCode){
                await showDialog({
                    title: '提示',
                    message: '确定删除当前目录吗?',
                    showCancelButton:true,
                })
                return  handleClassifyDelete(data)
            }else if(res.Data.DeleteStatus === 0 && data.EdbCode){
                await showDialog({
                    title: '提示',
                    message: '删除后指标和指标值均不可使用，确认删除吗?',
                    showCancelButton:true,
                })
                return handleClassifyDelete(data)
            }else if(res.Data.DeleteStatus === 2){
                await showDialog({
                    title: '提示',
                    message: '确认删除当前目录及包含的子目录吗?',
                    showCancelButton:true,
                })
                return handleClassifyDelete(data)
            }
        }
    }

    return {
        edbClassifyDelete
    }
}