import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { ProjectInfoVO, ProjectInfoForm, ProjectInfoQuery } from '@/api/oa/erp/projectInfo/types';

/**
 * 查询项目信息列表
 * @param query
 * @returns {*}
 */

export const listProjectInfo = (query?: ProjectInfoQuery): AxiosPromise<ProjectInfoVO[]> => {
  return request({
    url: '/oa/erp/projectInfo/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询项目信息详细
 * @param projectId
 */
export const getProjectInfo = (projectId: string | number): AxiosPromise<ProjectInfoVO> => {
  return request({
    url: '/oa/erp/projectInfo/' + projectId,
    method: 'get'
  });
};

/**
 * 新增项目信息
 * @param data
 */
export const addProjectInfo = (data: ProjectInfoForm) => {
  return request({
    url: '/oa/erp/projectInfo',
    method: 'post',
    data: data
  });
};

/**
 * 修改项目信息
 * @param data
 */
export const updateProjectInfo = (data: ProjectInfoForm) => {
  return request({
    url: '/oa/erp/projectInfo',
    method: 'put',
    data: data
  });
};

/**
 * 项目信息维护（产品数量、项目状态、项目阶段、情况说明、需要开展工作）
 */
export const maintainProjectInfo = (data: ProjectInfoForm) => {
  return request({
    url: '/oa/erp/projectInfo/maintain',
    method: 'put',
    data: data
  });
};

/**
 * 删除项目信息
 * @param projectId
 */
export const delProjectInfo = (projectId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/erp/projectInfo/' + projectId,
    method: 'delete'
  });
};

/**
 * 项目信息提交并发起流程
 * @param data
 */
export const projectSubmitAndFlowStart = (data: ProjectInfoForm) => {
  return request({
    url: '/oa/erp/projectInfo/submitAndFlowStart',
    method: 'post',
    data: data
  });
};

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


/**
 * 查询项目信息列表,主要提供财务应收款使用
 * @param query
 * @returns {*}
 */
export function getErpProjectWithContractList(query) {
  return request({
    url: '/oa/erp/projectInfo/getErpProjectWithContractList',
    method: 'get',
    params: query
  });
}

/**
 * 根据合同ID查询关联项目信息列表
 * @param contractId
 */
export const listProjectInfoByContractId = (contractId: string | number): AxiosPromise<ProjectInfoVO[]> => {
  return request({
    url: '/oa/erp/projectInfo/listByContractId/' + contractId,
    method: 'get'
  });
};

