
import {
    WeaTools,WeaLocaleProvider
} from 'ecCom'
const getLabel = WeaLocaleProvider.getLabel;

export const getSearchList = (params) => {
    return WeaTools.callApi('/api/bs/hrmorganization/hrmresource/listPage', 'GET', params);
}

export const getAdvanceSearchCondition = (params) => {
    return WeaTools.callApi('/api/bs/hrmorganization/hrmresource/getSearchCondition', 'GET', params);
}

export const add = (params) => {
    return fetch('/api/bs/hrmorganization/hrmresource/saveBaseForm', {
        method: 'POST',
        mode: 'cors',
        headers: {
            'Content-Type': 'application/json'
        }, 
        body: JSON.stringify(params)
    })
}


export const getSchemeForm = (params) => {
    return WeaTools.callApi('/api/bs/hrmorganization/hrmresource/getSaveForm', 'GET', params);
}

export const getHasRight = (params) => {
    return WeaTools.callApi('/api/bs/hrmorganization/hrmresource/getHasRight', 'GET', params);
}

export const getQuickSearchCondition = (params) => {
    return WeaTools.callApi('/api/bs/hrmorganization/quicksearch/getQuickSearchCondition', 'GET', params);
}


export const editResource = (params) => {
    return WeaTools.callApi('/api/bs/hrmorganization/hrmresource/updateForm', 'POST', params);
}

export const getResourceExtendForm = (params) => {
    return WeaTools.callApi('/api/bs/hrmorganization/hrmresource/getBaseForm', 'GET', params);
}

export const version = (params) => {
    return WeaTools.callApi('/api/bs/hrmorganization/version/resourcefielddefined/save', 'POST', params);
}

export const exportResource = (ids) => {
    return new Promise(resolve => {
        fetch('/api/bs/hrmorganization/common/resource/export?ids='+ids).then(res => res.blob().then(blob => {
            resolve();
            var filename=`${getLabel(547539,'人员信息')}.xlsx`
            var a = document.createElement('a');
            var url = window.URL.createObjectURL(blob); 
            a.href = url;
            a.download = filename;
            a.click();
            window.URL.revokeObjectURL(url);
        }))
      });
}


export const saveSearchTemplate = (params) => {
    return fetch('/api/bs/hrmorganization/hrmresource/saveSearchTemplate', {
        method: 'POST',
        mode: 'cors',
        headers: {
            'Content-Type': 'application/json'
        }, 
        body: JSON.stringify(params)
    })
}

export const saveCustomTemplate = (params) => {
    return fetch('/api/bs/hrmorganization/hrmresource/saveCustomTemplate', {
        method: 'POST',
        mode: 'cors',
        headers: {
            'Content-Type': 'application/json'
        }, 
        body: JSON.stringify(params)
    })
}


export const deleteSearchTemplate = (params) => {
    return fetch('/api/bs/hrmorganization/hrmresource/deleteSearchTemplate', {
        method: 'POST',
        mode: 'cors',
        headers: {
            'Content-Type': 'application/json'
        }, 
        body: JSON.stringify(params)
    })
}

export const getSearchTemplate = (params) => {
    return WeaTools.callApi(`/api/bs/hrmorganization/hrmresource/getSearchTemplate`, 'GET',params);
}

export const getTemplateSelectKeys = (params) => {
    return WeaTools.callApi(`/api/bs/hrmorganization/hrmresource/getTemplateSelectKeys`, 'GET',params);
}

export const updateCustomTemplate = (params) => {
    return WeaTools.callApi(`/api/bs/hrmorganization/hrmresource/updateCustomTemplate`, 'POST',params);
}

export const saveColumnsCustomTemplate = (params) => {
    return WeaTools.callApi(`/api/bs/hrmorganization/hrmresource/saveColumnsCustomTemplate`, 'POST',params);
}

export const setOverAll = (params) => {
    return WeaTools.callApi(`/api/bs/hrmorganization/hrmresource/customOverall`, 'POST',params);
}

export const getEditTable = () => {
    return WeaTools.callApi('/api/bs/hrmorganization/hrmresource/getCustomTemplate', 'GET');
}

export const getCustomTransferData = (id) => {
    return WeaTools.callApi(`/api/bs/hrmorganization/hrmresource/getCustomTransferData?templateId=${id}`, 'GET');
}


