/*
 * @Author: ysh
 * @Date: 2024-06-13 17:07:59
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2025-03-28 15:17:32
 */
import request from '@/utils/request'

const apiEndpoints = [
  {
    procDefName: '承接合同评审',
    apiUrl: [
      '/oa/contract/:id',
      '/oa/contractWork/:id',
      '/oa/contractComment/:id',
      '/oa/contractMeeting/:id',
      '/oa/contractPayment/:id',
      '/oa/projectContract/:id',
      '/oa/contractSubcontract/contractIds/:id',
    ]
  },
  {
    procDefName: '分包合同评审',
    apiUrl: [
      '/oa/subContract/:id',
      '/oa/contractWork/:id',
      '/oa/contractComment/:id',
      '/oa/contractMeeting/:id',
      '/oa/contractPayment/:id',
      '/oa/projectSubcontract/:id',
      '/oa/contractSubcontract/:id',
    ]
  },
  {
    procDefName: '用车审批',
    apiUrl: [
      '/oa/carApproval/:id',
    ]
  },
  {
    procDefName: '设备审批',
    apiUrl: [
      '/oa/deviceApproval/:id',
    ]
  },
  {
    procDefName: '项目流转',
    apiUrl: [
      '/oa/project/:id',
      '/oa/projectWork/:id',
      '/oa/projectContract/delete/:id'
    ]
  },
  {
    procDefName: '项目结算',
    apiUrl: [
      '/oa/settle/:id',
      '/oa/settleSummary/:id',
      '/oa/settleWork/:id',
    ]
  },
  {
    procDefName: '借款审批',
    apiUrl: [
      '/oa/borrow/:id',
      '/oa/borrowDetail/:id',
    ]
  },
  {
    procDefName: '项目变更',
    apiUrl: [
      '/oa/projectChange/:id',
    ]
  },
  {
    procDefName: '成果归档',
    apiUrl: [
      '/oa/archive/:id',
    ]
  },
  {
    procDefName: '其他结算',
    apiUrl: [
      '/oa/settle/:id',
      '/oa/settleSummary/:id',
      '/oa/settleWork/:id',
    ]
  },
  {
    procDefName: '品牌项目支付',
    apiUrl: [
      '/oa/brand/:id',
      '/oa/brandPayment/:id'
    ]
  },
  {
    procDefName: '工作填报',
    apiUrl: [
      '/oa/declare/:id'
    ]
  },
  {
    procDefName: '采购审批',
    apiUrl: [
      '/oa/procureApproval/:id',
      '/oa/procurePlan/:id'
    ]
  },
  {
    procDefName: '项目委外',
    apiUrl: [
      '/oa/outsource/:id',
      '/oa/outsourceWork/:id'
    ]
  },
  {
    procDefName: '绩效审批',
    apiUrl: [
      '/oa/performance/:id',
      '/oa/wage/batch/:id'
    ]
  },
  {
    procDefName: '项目预算',
    apiUrl: [
      '/oa/budget/:id',
      '/oa/budgetSettle/:id',
      '/oa/budgetCar/:id',
      '/oa/budgetDevice/:id',
      '/oa/budgetStaff/:id',
    ]
  },
  {
    procDefName: '技术方案',
    apiUrl: [
      '/oa/technical/:id',
    ]
  },
  {
    procDefName: '技术交底',
    apiUrl: [
      '/oa/technicalPlan/:id',
    ]
  },
  {
    procDefName: '安全交底',
    apiUrl: [
      '/oa/safe/:id',
    ]
  },
  {
    procDefName: '参培审核',
    apiUrl: [
      '/oa/trainApproval/:id',
    ]
  },
]

// 编写一个方法来处理删除请求，并同时发送所有API请求  
export async function deleteResources(procDefName, id) {
  // 查找对应的API端点  
  const endpoint = apiEndpoints.find(endpoint => endpoint.procDefName === procDefName);
  if (!endpoint) {
    throw new Error(`No API endpoints found for process definition: ${procDefName}`);
  }

  // 构建所有请求的Promise数组  
  const deletePromises = endpoint.apiUrl.map(apiUrl => {
    // 替换URL中的:id占位符  
    const url = apiUrl.replace(':id', id);
    // 发送DELETE请求并返回Promise  
    return request({
      url: url,
      method: 'delete'
    })
  });

  // 等待所有请求完成  
  try {
    return await Promise.all(deletePromises);
    console.log('删除完成！');
  } catch (error) {
    console.error('One or more deletion requests failed:', error);
  }
} 