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

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

export function updateMenu (parameter) {
  return axios({
    url: `/upms/menus/${parameter.menuId}`,
    method: 'PUT',
    data: parameter
  })
}

export function fetchMenu (parameter) {
  return axios({
    url: `/upms/menus/${parameter.menuId}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function deleteMenu (parameter) {
  return axios({
    url: `/upms/menus/${parameter.menuId}`,
    method: 'DELETE',
    data: parameter
  })
}

export function dropMenu (menuId, parameter) {
  return axios({
    url: `/upms/menus/drop/${menuId}`,
    method: 'PUT',
    data: parameter
  })
}

export function copyMenu (params) {
  return axios({
    url: `/upms/menus/copy/${params.menuId}/${params.type}`,
    method: 'POST'
  })
}
