import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import {
  FinAccountInstallmentVO,
  FinAccountInstallmentForm,
  FinAccountInstallmentQuery,
  FinAccountInstallmentDispatchForm
} from '@/api/oa/erp/finAccountInstallment/types';

/**
 * 查询分款信息列表
 * @param query
 * @returns {*}
 */

export const listFinAccountInstallment = (query?: FinAccountInstallmentQuery): AxiosPromise<FinAccountInstallmentVO[]> => {
  return request({
    url: '/oa/erp/finAccountInstallment/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询分款信息详细
 * @param accountInstallmentId
 */
export const getFinAccountInstallment = (accountInstallmentId: string | number): AxiosPromise<FinAccountInstallmentVO> => {
  return request({
    url: '/oa/erp/finAccountInstallment/' + accountInstallmentId,
    method: 'get'
  });
};

/**
 * 新增分款信息
 * @param data
 */
export const addFinAccountInstallment = (data: FinAccountInstallmentForm) => {
  return request({
    url: '/oa/erp/finAccountInstallment',
    method: 'post',
    data: data
  });
};

/**
 * 修改分款信息
 * @param data
 */
export const updateFinAccountInstallment = (data: FinAccountInstallmentForm) => {
  return request({
    url: '/oa/erp/finAccountInstallment',
    method: 'put',
    data: data
  });
};

/**
 * 删除分款信息
 * @param accountInstallmentId
 */
export const delFinAccountInstallment = (accountInstallmentId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/erp/finAccountInstallment/' + accountInstallmentId,
    method: 'delete'
  });
};

/**
 * 下拉框查询分款信息列表
 * @param query
 * @returns {*}
 */
export function getErpFinAccountInstallmentList (query) {
    return request({
        url: '/oa/erp/finAccountInstallment/getErpFinAccountInstallmentList',
        method: 'get',
        params: query
    });
};

/**
 * 导入分款信息
 * @param data
 */
export const importFinAccountInstallment = (data: any) => {
    return request({
        url: '/oa/erp/finAccountInstallment/import',
        method: 'post',
        data: data,
        headers: {
            'Content-Type': 'application/json'
        }
    });
};


/**
 * 下载回款模板
 * @param query
 * @returns {*}
 */
export function exportAccountInstallTemplate () {
  return request({
    url: '/oa/erp/finAccountInstallment/exportAccountInstallTemplate',
    method: 'get'
  });
};

/**
 * 派发给客户经理（可多选）
 */
export const dispatchFinAccountInstallment = (data: FinAccountInstallmentDispatchForm) => {
  return request({
    url: '/oa/erp/finAccountInstallment/dispatch',
    method: 'post',
    data
  });
};
