import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import {
  ContractCollectionPageVO,
  ContractCollectionStageDetailVO,
  ErpProjectPlanVO,
  ErpProjectPlanForm,
  ErpProjectPlanQuery
} from '@/api/oa/erp/erpProjectPlan/types';
import { ErpProjectPlanStageForm, ErpProjectPlanStageVO } from '@/api/oa/erp/erpProjectPlanStage/types';

/**
 * 查询项目计划列表
 * @param query
 * @returns {*}
 */

export const listErpProjectPlan = (query?: ErpProjectPlanQuery): AxiosPromise<ErpProjectPlanVO[]> => {
  return request({
    url: '/oa/erp/erpProjectPlan/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询项目计划详细
 * @param projectPlanId
 */
export const getErpProjectPlan = (projectPlanId: string | number): AxiosPromise<ErpProjectPlanVO> => {
  return request({
    url: '/oa/erp/erpProjectPlan/' + projectPlanId,
    method: 'get'
  });
};

/**
 * 新增项目计划
 * @param data
 */
export const addErpProjectPlan = (data: ErpProjectPlanForm) => {
  return request({
    url: '/oa/erp/erpProjectPlan',
    method: 'post',
    data: data
  });
};

/**
 * 修改项目计划
 * @param data
 */
export const updateErpProjectPlan = (data: ErpProjectPlanForm) => {
  return request({
    url: '/oa/erp/erpProjectPlan',
    method: 'put',
    data: data
  });
};

/**
 * 删除项目计划
 * @param projectPlanId
 */
export const delErpProjectPlan = (projectPlanId: string | number | Array<string | number>) => {
  return request({
    url: '/oa/erp/erpProjectPlan/' + projectPlanId,
    method: 'delete'
  });
};

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

/**
 * 提交项目计划并发起流程
 * @param data
 */
export const projectPlanSubmitAndFlowStart = (data: ErpProjectPlanForm): AxiosPromise<ErpProjectPlanVO> => {
  return request({
    url: '/oa/erp/erpProjectPlan/projectPlanSubmitAndFlowStart',
    method: 'post',
    data: data
  });
};

/**
 * 查询项目计划回款阶段列表
 */
export const collectionStageList = (projectPlanId: string | number): AxiosPromise<ErpProjectPlanStageVO[]> => {
  return request({
    url: '/oa/erp/erpProjectPlan/collectionStageList/' + projectPlanId,
    method: 'get'
  });
};

/**
 * 项目计划阶段回款确认
 */
export const confirmCollectionStage = (data: ErpProjectPlanStageForm) => {
  return request({
    url: '/oa/erp/erpProjectPlan/confirmCollectionStage',
    method: 'post',
    data
  });
};

/**
 * 合同回款页面主列表
 */
export const contractCollectionPage = (query?: ErpProjectPlanQuery): AxiosPromise<ContractCollectionPageVO[]> => {
  return request({
    url: '/oa/erp/erpProjectPlan/contractCollectionPage',
    method: 'get',
    params: query
  });
};

/**
 * 合同回款页面阶段详情
 */
export const contractCollectionStageDetail = (projectPlanId: string | number): AxiosPromise<ContractCollectionStageDetailVO[]> => {
  return request({
    url: '/oa/erp/erpProjectPlan/contractCollectionStageDetail/' + projectPlanId,
    method: 'get'
  });
};
