import { axios } from '@/utils/request'
import { stringify } from 'qs'

/**
 * user page func
 * parameter: {
 *     keyword: '',
 * }
 * @param parameter
 * @returns {*}
 */
export function getDictTree (parameter) {
  return axios({
    url: `/upms/dicts/tree?${stringify(parameter)}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * user page func
 * parameter: {
 *     keyword: '',
 * }
 * @param parameter
 * @returns {*}
 */
export function getDictPage (parameter) {
  return axios({
    url: '/upms/dicts/page?' + stringify(parameter),
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * role list func
 * @param parameter
 * @returns {*}
 */
export function queryDict (parameter) {
  return axios({
    url: '/upms/dicts?' + stringify(parameter),
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function addDict (parameter) {
  return axios({
    url: `/upms/dicts`,
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: parameter
  })
}

export function initDict () {
  return axios({
    url: `/upms/dicts/init`,
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function dictData () {
  return axios({
    url: `/upms/dicts/data`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function dictType (parameter) {
  return axios({
    url: `/upms/dicts/type?` + stringify(parameter),
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export async function awaitDictType (parameter) {
  var newVar = await axios({
    url: `/upms/dicts/type?` + stringify(parameter),
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
  return newVar
}

export function updateDict (parameter) {
  return axios({
    url: '/upms/dicts/' + parameter.id,
    method: 'PUT',
    data: parameter
  })
}

export function fetchDict (parameter) {
  return axios({
    url: '/upms/dicts/' + parameter.id,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function deleteDicts (parameter) {
  return axios({
    url: `/upms/dicts`,
    method: 'DELETE',
    data: parameter
  })
}
