import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ChargesVO, ChargesForm, ChargesQuery } from '@/api/bls/charges/types';
import { data } from 'autoprefixer';

/**
 * 查询团体暂收费列表
 * @param query
 * @returns {*}
 */

export const listCharges = (query?: ChargesQuery): AxiosPromise<ChargesVO[]> => {
  return request({
    url: '/bls/charges/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询团体暂收费详细
 * @param temporaryChargeId
 */
export const getCharges = (temporaryChargeId: string | number): AxiosPromise<ChargesVO> => {
  const data = {
    temporaryChargeId
  };
  return request({
    url: '/bls/charges/query',
    method: 'post',
    data: data
  });
};

/**
 * 新增团体暂收费
 * @param data
 */
export const addCharges = (data: ChargesForm) => {
  return request({
    url: '/bls/charges/add',
    method: 'post',
    data: data
  });
};

/**
 * 修改团体暂收费
 * @param data
 */
export const editCharges = (data: ChargesForm) => {
  return request({
    url: '/bls/charges/edit',
    method: 'post',
    data: data
  });
};

/**
 * 团体暂收费提交审核
 */
export const approvalCharges = (data) => {
  return request({
    url: '/bls/charges/approval',
    method: 'post',
    data: data
  });
};

/**
 * 审批通过
 * @param temporaryChargeId
 */
export const passCharges = (temporaryChargeIds: string | number | Array<string | number>) => {
  const ids = Array.isArray(temporaryChargeIds) ? temporaryChargeIds : [temporaryChargeIds];
  const data = ids.map((id) => ({ temporaryChargeId: String(id) }));
  return request({
    url: '/bls/charges/auditpass',
    method: 'post',
    data: data
  });
};

/**
 * 财务作废
 * @param temporaryChargeId
 */
export const failCharges = (temporaryChargeIds: string | number | Array<string | number>) => {
  const ids = Array.isArray(temporaryChargeIds) ? temporaryChargeIds : [temporaryChargeIds];
  const data = ids.map((id) => ({ temporaryChargeId: String(id) }));
  return request({
    url: '/bls/charges/auditfail',
    method: 'post',
    data: data
  });
};

/**
 * 申请作废
 * @param temporaryChargeId
 */
export const applayfail = (data: string | number | Array<string | number>) => {
  // const data = {
  //   temporaryChargeId: temporaryChargeId
  // };
  return request({
    url: '/bls/charges/applayfail',
    method: 'post',
    data: data
  });
};

/**
 * 查询收款方银行账号
 */
export const getCollBank = () => {
  return request({
    url: '/bls/charges/getcollbank',
    method: 'post',
    data: data
  });
};

/**
 * 暂收费作废
 */
export const chargesCancel = (data) => {
  return request({
    url: '/bls/charges/chargesCancel',
    method: 'post',
    data: data
  });
};

/**
 * 查询可作废的暂收费
 * @param query
 * @returns {*}
 */

export const listCanelCharges = (query?: ChargesQuery): AxiosPromise<ChargesVO[]> => {
  query.matchingStatus = '0';
  query.approvalStatus = '1';
  return request({
    url: '/bls/charges/list',
    method: 'get',
    params: query
  });
};

export const listInformationCharges = (query?: ChargesQuery): AxiosPromise<ChargesVO[]> => {
  return request({
    url: '/bls/chargesInformation/informationChargesList',
    method: 'get',
    params: query
  });
};

export const listComInformationCharges = (query?: ChargesQuery): AxiosPromise<ChargesVO[]> => {
  return request({
    url: '/bls/chargesInformation/comInformationChargesList',
    method: 'get',
    params: query
  });
};

export const getCostCenter = () => {
  return request({
    url: '/bls/charges/costCenterQury',
    method: 'post'
  });
};

/**
 * 查询团体暂收费详细
 * @param temporaryChargeId
 */
export const getInformationCharges = (id: string | number): AxiosPromise<ChargesVO> => {
  const data = {
    id
  };
  return request({
    url: '/bls/chargesInformation/query',
    method: 'post',
    data: data
  });
};

export const submitInformationCharges = (data) => {
  return request({
    url: '/bls/chargesInformation/informationChargesSubmit',
    method: 'post',
    data: data
  });
};

export const queryTaxregno = (query: string | number) => {
  const data = {
    name1: query
  };
  return request({
    url: '/bls/chargesInformation/queryTaxregno',
    method: 'post',
    data: data
  });
};
