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

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

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

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

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

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

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

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


export const exportData = () => {
    return new Promise(resolve => {
        fetch('/api/bs/hrmorganization/common/department/export').then(res => res.blob().then(blob => {
            resolve();
            var filename=`${getLabel(547606,'部门档案数据')}.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 selectVersions = (params) => {
    return WeaTools.callApi('/api/bs/hrmorganization/version/departmentfielddefined/getVersion', 'GET', params);
}

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

export const add = (params) => {
    return WeaTools.callApi('/api/bs/hrmorganization/dept/saveBaseForm', 'POST', params);
}

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

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

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

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

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

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


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


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