import axios from '../bc-libs/api.request'

export const getAllTree = (url,params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: url,
      method: 'GET',
      params:params
    }).then(response => {
      resolve(response.data);
    }).catch(err => {
      reject(err)
    })
  })
}

export const getCompanyTree = (url,params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: url + params.areaId,
      method: 'GET',
    }).then(response => {
      resolve(response.data);
    }).catch(err => {
      reject(err)
    })
  })
}

/**
 * 根据编制获取单位
 * @type {string}
 */
let sequences = [];
export function getSequenceTree(areaids,fn) {
  post('cas/v1/base/company/treeBySequence/'+areaids).then(response=>{
    sequences = response.result;
    fn(sequences);
  }).catch(err=>{
    console.log(err);
  });
}

export const getTreeData = (url,params) => {
  return new Promise((resolve, reject) => {
    axios.request({
      url: url,
      method: 'GET',
      params:params
    }).then(response => {
      resolve(response.data);
    }).catch(err => {
      reject(err)
    })
  })
}
