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

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

/**
 * add func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function addSupplier (parameter) {
  return axios({
    url: '/purchase/suppliers',
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: parameter
  })
}

/**
 * update func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function updateSupplier (parameter) {
  return axios({
    url: '/purchase/suppliers/' + parameter.id,
    method: 'PUT',
    data: parameter
  })
}

/**
 * submit func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function submit (parameter) {
  return axios({
    url: '/purchase/suppliers/' + parameter.id + '/submit',
    method: 'PUT'
  })
}

/**
 * audit func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function audit (parameter) {
  return axios({
    url: '/purchase/suppliers/' + parameter.id + '/audit',
    method: 'PUT',
    data: parameter
  })
}

/**
 * close func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function close (parameter) {
  return axios({
    url: '/purchase/suppliers/' + parameter.id + '/close',
    method: 'PUT',
    data: parameter
  })
}

/**
 * fetch single func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function fetchSupplier (parameter) {
  return axios({
    url: '/purchase/suppliers/' + parameter.id,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

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

/**
 * delete batch func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function deleteSuppliers (parameter) {
  return axios({
    url: '/purchase/suppliers',
    method: 'DELETE',
    data: parameter
  })
}

/**
 * delete single func
 * parameter: { }
 * @param parameter
 * @returns {*}
 */
export function deleteSupplier (parameter) {
  return axios({
    url: '/purchase/suppliers/' + parameter.id,
    method: 'DELETE',
    data: parameter
  })
}

/**
 * export file
 * parameter: { }
 * @param parameter :
 * @returns {*}
 */
export function exportSupplier (parameter) {
  return axios({
    url: '/purchase/suppliers/export?' + stringify(parameter),
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    responseType: 'blob'
  })
}
