import { useConfigSettingStore } from '@/store/modules/etaConfig'
import {apiCheckClassify} from '@/api/common'
import { storeToRefs } from 'pinia'
import {ref} from 'vue'
export function useReportApprove(){
    let isApprove = ref(false)
    let isOtherApprove = ref(false)
    let hasApproveFlow = ref(false)
    const configSettingStore = useConfigSettingStore()
    const { etaConfigInfo } = storeToRefs(configSettingStore)
    //获取基本配置，判断是否走审批流
    const getEtaConfig = async()=>{
        await configSettingStore.getBaseConfigSetting()
        const {IsReportApprove='',ReportApproveType=''} = etaConfigInfo.value
        isApprove.value = IsReportApprove==='true'?true:false
        isOtherApprove.value = isApprove.value&&ReportApproveType==='other' 
    }
    //检查分类是否存在审批流
    const checkClassifyNameArr = (type=1,classify=[])=>{
        let params = {
            ReportType:type,
            ClassifyFirstId:classify[classify.length-2]||0,
            ClassifySecondId:classify[classify.length-1]||0,
        }
        apiCheckClassify(params).then(res=>{
            if(res.Ret!==200) return 
            hasApproveFlow.value = res.Data||false
        })
    }
    return {
        isApprove,
        isOtherApprove,
        hasApproveFlow,
        getEtaConfig,
        checkClassifyNameArr
    }
}