import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CrmQuoteInfoForm, CrmQuoteInfoQuery, CrmQuoteInfoVO } from '@/api/oa/crm/crmQuoteInfo/types';

/**
 * 查询报价单信息列表
 * @param query
 * @returns {*}
 */

export const listCrmQuoteInfo = (query?: CrmQuoteInfoQuery): AxiosPromise<CrmQuoteInfoVO[]> => {
  return request({
    url: '/oa/crm/crmQuoteInfo/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询报价单信息详细
 * @param quoteId
 */
export const getCrmQuoteInfo = (quoteId: string | number): AxiosPromise<CrmQuoteInfoVO> => {
  return request({
    url: '/oa/crm/crmQuoteInfo/' + quoteId,
    method: 'get'
  });
};

/**
 * 新增报价单信息
 * @param data
 */
export const addCrmQuoteInfo = (data: CrmQuoteInfoForm) => {
  return request({
    url: '/oa/crm/crmQuoteInfo',
    method: 'post',
    data: data
  });
};

/**
 * 修改报价单信息
 * @param data
 */
export const updateCrmQuoteInfo = (data: CrmQuoteInfoForm) => {
  return request({
    url: '/oa/crm/crmQuoteInfo',
    method: 'put',
    data: data
  });
};

/**
 * 删除报价单信息
 * @param quoteId
 */
export const delCrmQuoteInfo = (quoteId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/crm/crmQuoteInfo/' + quoteId,
    method: 'delete'
  });
};

/**
 * 下拉框查询报价单信息列表
 * @param query
 * @returns {*}
 */
export function getCrmQuoteInfoList(query) {
  return request({
    url: '/oa/crm/crmQuoteInfo/getCrmQuoteInfoList',
    method: 'get',
    params: query
  });
}

/**
 * 查看同一次的多轮报价集合
 * @param quoteId
 */
export const listQuoteRounds = (quoteId: string | number): AxiosPromise<CrmQuoteInfoVO[]> => {
  return request({
    url: '/oa/crm/crmQuoteInfo/rounds/' + quoteId,
    method: 'get'
  });
};

/**
 * 根据报价明细回写主表金额汇总
 * @param quoteId
 */
export const recalcQuoteTotals = (quoteId: string | number): AxiosPromise<boolean> => {
  return request({
    url: '/oa/crm/crmQuoteInfo/recalc/' + quoteId,
    method: 'post'
  });
};

/**
 * 旧版后端直出模板导出接口（已停用）
 * 统一改为前端路由到 /quote/quoteView，通过模板变量赋值后由前端导出 PDF
 */
/* export const exportQuoteTemplate = (quoteId: string | number) => {
  return request({
    url: '/oa/crm/crmQuoteInfo/exportTemplate/' + quoteId,
    method: 'get',
    responseType: 'blob'
  });
}; */

/**
 * 提交报价单并发起流程
 * @param data
 */
export const quoteSubmitAndFlowStart = (data: CrmQuoteInfoForm): AxiosPromise<CrmQuoteInfoVO> => {
  return request({
    url: '/oa/crm/crmQuoteInfo/quoteSubmitAndFlowStart',
    method: 'post',
    data: data
  });
};
