import { config, networkUtils } from '../../utils';

const { request } = networkUtils;
const { api } = config;
const { supp ,fm} = api;
const { supps, certType, qualifys, download} = supp;

export async function query(params) {
  return request({
    url: supps,
    method: 'get',
    data: params,
  });
}

export async function getSingle(id) {
  return request({
    url: `${supps}/${id}`,
    method: 'get',
  });
}

export async function create(params) {
  return request({
    url: supps,
    method: 'post',
    data: params,
  });
}

export async function remove(ids) {
  return request({
    url: `${supps}/del`,
    method: 'post',
    data: ids,
  });
}

export async function disable(id) {
  return request({
    url: `${supps}/${id}/disable`,
    method: 'post',
  });
}

export async function update(params) {
  return request({
    url: `${supps}/put`,
    method: 'post',
    data: params,
  });
}

export async function adjust(params) {
  return request({
    url: `${supps}/adjust`,
    method: 'post',
    data: params,
  });
}

export async function reject(id) {
  return request({
    url: `${supps}/apprstatus/${id}/rejected`,
    method: 'post',
  });
}

export async function getItem() {
  return request({
    url: `${api.common.udc.query.replace('{udc}', 'SUPP.GYSYLSX')}`,
    method: 'get',
  });
}

export async function fetchData(repo) {
  return repo !== undefined && networkUtils.request({
    url: fm.list.replace('{repo}', repo),
    method: 'get',
  });
}

export async function getStaffs(id) {
  return request({
    url: `/api/supp/${id}/purchasing-staffs`,
    method: 'get',
  });
}

export async function getQualifys(addrNo) {
  return request({
    url: `${qualifys}/${addrNo}`,
    method: 'get',
  });
}

export async function requireQualifys(params) {
  return request({
    url: certType,
    method: 'get',
    data: params,
  });
}

export async function pack(params) {
  return request({
    url: download,
    method: 'post',
    data: params,
  });
}

