import axios from '@/common/services/axios-instance'
import qs from 'qs'

class SysparamsService {
  // 搜索节点
  searchNode(param) {
    return axios.post('api/framework/v1/dict-manager/query/search-dicts', { param })
  }

  getTreeData(id) {
    return axios({
      method: 'post',
      url: `api/framework/v1/dict-manager/get-alltree`,
      params: { belongOrgId: id },
    })
  }

  // 保存分类
  saveSysclassify(params) {
    return axios.post('api/framework/v1/dict-manager/keys', params)
  }

  // 删除分类
  delSysclassify(params) {
    return axios.delete(
      `api/framework/v1/dict-manager/remove?${
        params.parentId
          ? 'parentId=' + params.parentId + '&ids=' + params.ids.join()
          : 'ids=' + params.ids.join()
      }`,
      params
    )
  }

  // 保存值
  saveValues(params) {
    return axios.post('api/framework/v1/dict-manager/values', params)
  }

  // 获取值
  getValues(params) {
    return axios.post('api/framework/v1/dict-manager/getvalues', params).then((res) => {
      return res.data
    })
  }

  getExportParamsTree(params) {
    return axios
      .post(`api/framework/v1/dict-manager/get-children?${qs.stringify(params)}`)
      .then((res) => {
        return res
      })
  }

  checkParameterExist(params) {
    return axios({
      url: 'api/framework/v1/dict-manager/check-exist',
      method: 'post',
      data: params,
    })
  }

  importParameter(params) {
    return axios({
      url: 'api/framework/v1/dict-manager/import-parameter',
      method: 'post',
      data: params,
    })
  }

  exportParameter(groupId, ids) {
    return axios({
      url: 'api/framework/v1/dict-manager/export-parameter',
      method: 'post',
      params: {
        groupId,
        ids,
      },
    })
  }
}
export default new SysparamsService()
