import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { BusinessTripApplyVO, BusinessTripApplyForm, BusinessTripApplyQuery } from '@/api/oa/crm/businessTripApply/types';

/**
 * 查询出差申请列表
 * @param query
 * @returns {*}
 */

export const listBusinessTripApply = (query?: BusinessTripApplyQuery): AxiosPromise<BusinessTripApplyVO[]> => {
  return request({
    url: '/oa/crm/businessTripApply/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询出差申请详细
 * @param tripId
 */
export const getBusinessTripApply = (tripId: string | number): AxiosPromise<BusinessTripApplyVO> => {
  return request({
    url: '/oa/crm/businessTripApply/' + tripId,
    method: 'get'
  });
};

/**
 * 新增出差申请
 * @param data
 */
export const addBusinessTripApply = (data: BusinessTripApplyForm) => {
  return request({
    url: '/oa/crm/businessTripApply',
    method: 'post',
    data: data
  });
};

/**
 * 修改出差申请
 * @param data
 */
export const updateBusinessTripApply = (data: BusinessTripApplyForm) => {
  return request({
    url: '/oa/crm/businessTripApply',
    method: 'put',
    data: data
  });
};

/**
 * 删除出差申请
 * @param tripId
 */
export const delBusinessTripApply = (tripId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/crm/businessTripApply/' + tripId,
    method: 'delete'
  });
};

/**
 * 下拉框查询出差申请列表
 * @param query
 * @returns {*}
 */
export function getCrmBusinessTripApplyList(query) {
  return request({
    url: '/oa/crm/businessTripApply/getCrmBusinessTripApplyList',
    method: 'get',
    params: query
  });
}

/**
 * 提交出差申请并启动流程
 * @param data
 */
export const submitBusinessTripApplyAndFlowStart = (data: BusinessTripApplyForm) => {
  return request({
    url: '/oa/crm/businessTripApply/submitAndFlowStart',
    method: 'post',
    data: data
  });
};

/**
 * 导出出差申请单 PDF（已审批）
 * @param tripId 出差申请ID
 */
export const exportBusinessTripApplyPdf = (tripId: string | number) => {
  return request({
    url: '/oa/crm/businessTripApply/exportTripApplyPdf/' + tripId,
    method: 'get',
    responseType: 'blob'
  });
};
