const standardDict = { // 测量设备
  '/standard/changeApply': '更换申请',
  '/standard/pauseApply': '暂停申请',
  '/standard/cancelApply': '撤销申请',
  '/standard/resumeApply': '恢复申请',
  '/standard/checkApply': '复查申请',
  '/stateManage/unusedApply': '设备闲置申请',
  '/stateManage/sealupApply': '设备封存申请',
  '/stateManage/openApply': '设备启封申请',
  '/stateManage/scrapApply': '设备报废申请',
  '/stateManage/handleApply': '设备处置申请',
}
const standardApplyType = { // 标准装置申请类型
  更换申请: '1',
  暂停申请: '2',
  撤销申请: '3',
  恢复申请: '4',
  复查申请: '5',
} as any

const equipmentManageType = {
  设备闲置申请: '3',
  设备封存申请: '4',
  设备启封申请: '5',
  设备报废申请: '6',
  设备处置申请: '10',
} as any

/**
 * 审批提醒跳转业务系统详情
 * @param $router 路由
 * @param url // 跳转路径
 * @param row // 参数
 */

export function useChangePage($router: any, url: string, row: any) {
  let approvalStatus = '2'
  let approvalStatusName = '待审批'
  if (row.messageTitle === '结果通知') {
    approvalStatus = '4'
    approvalStatusName = '已通过'
  }

  if (url === '/file/approve') { // 文件审批
    console.log('文件审批')
    $router.push({
      name: 'approveDetail',
      query: {
        title: '详情',
        ...row.skipParamsObject,
        id: row.businessId,
        taskId: row.taskId,
        processId: row.processId,
        decisionItem: `${row.decisionItem}`, // 同意、驳回、拒绝
        approvalStatus,
        approvalStatusName,
      },
    })
  }
  else if (url === '/train/trainPlanApprove') { // 培训计划审批
    console.log('培训计划审批')
    $router.push({
      path: `/train/trainPlanApprove/2/${row.businessId}`, // 2待审批
      query: {
        ...row.skipParamsObject,
        id: row.businessId,
        taskId: row.taskId,
        processId: row.processId,
        decisionItem: `${row.decisionItem}`, // 同意、驳回、拒绝
        approvalStatus,
        approvalStatusName,
      },
    })
  }
  else if (url === '/source/approve') { // 溯源供方审批
    $router.push({
      path: `/source/approve/2/${row.businessId}`,
      query: {
        taskId: row.taskId,
        processId: row.processId,
        decisionItem: `${row.decisionItem}`, // 同意、驳回、拒绝
        approvalStatus,
        approvalStatusName,
      },
    })
  }
  // 标准装置更换申请、暂停、撤销、复查、恢复
  else if (url === '/standard/changeApply' || url === '/standard/pauseApply' || url === '/standard/cancelApply' || url === '/standard/resumeApply' || url === '/standard/checkApply') {
    const routeMetaTitle = standardDict[url]
    const applyType = standardApplyType[routeMetaTitle] // 申请类型
    $router.push({
      name: 'standardListAdd',
      params: {
        type: 'detail',
      },
      query: {
        title: '详情',
        id: row.businessId,
        routeMetaTitle,
        applyType,
        formId: row.formId,
        processId: row.processId,
        decisionItem: `${row.decisionItem}`, // 同意、驳回、拒绝
        taskId: row.taskId,
        approvalStatus,
        approvalStatusName,
      },
    })
  }
  // 设备闲置申请、封存、启封、报废、处置
  else if (url === '/stateManage/unusedApply' || url === '/stateManage/sealupApply' || url === '/stateManage/openApply' || url === '/stateManage/scrapApply' || url === '/stateManage/handleApply') {
    const routeMetaTitle = standardDict[url]
    const applyType = equipmentManageType[routeMetaTitle] // 申请类型
    $router.push({
      name: 'stateManageDetail',
      params: {
        type: 'detail',
        id: row.businessId,
      },
      query: {
        title: '详情',
        name: routeMetaTitle,
        applyType,
        approvalStatus,
        approvalStatusName,
        decisionItem: `${row.decisionItem}`, // 同意、驳回、拒绝
        taskId: row.taskId,
      },
    })
  }
  else if (url === '/receive/applyList' || url === '/borrow/borrowapply') { // 设备领用、借用
    const path = url === '/receive/applyList' ? '/receive/detail' : '/borrow/detail'
    $router.push({
      path,
      query: {
        typeValue: 'detail',
        id: row.businessId,
        taskId: row.taskId,
        processId: row.processId, // 查询审批记录使用
        approvalStatus,
        approvalStatusName,
        decisionItem: `${row.decisionItem}`,
      },
    })
  }
  else if (url === '/maintenance/maintenanceList') { // 设备检修申请
    $router.push({
      path: `/maintenance/maintenanceList/detail/${row.businessId}/${approvalStatusName}/${row.processId}`,
      query: {
        decisionItem: `${row.decisionItem}`, // 同意、驳回、拒绝
        taskId: row.taskId,
      },
    })
  }
  else if (url === '/maintenance/maintenanceCheckList') { // 设备检修保养验收单
    $router.push({
      path: `/maintenance/maintenanceCheckList/detail/${row.businessId}/${approvalStatusName}/${row.processId}`,
      query: {
        processId: row.processId, // 流程实例
        decisionItem: `${row.decisionItem}`, // 同意、驳回、拒绝
        taskId: row.taskId,
      },
    })
  }
  else if (url === '/lab/measureDataList') { // 证书报告
    row.approvalStatusName = approvalStatusName
    row.approvalStatus = approvalStatus
    $router.push({
      // path: `/lab/reportOnCredentialsApproval/detail/${row.businessId}`,
      path: `/lab/measureData/detail/${row.businessId}`,
      query: {
        processId: row.processId,
        row: JSON.stringify(row),
        // approvalStatus: '2', // 待审批
        // approvalStatusName: '待审批',
        decisionItem: `${row.decisionItem}`,
        taskId: row.taskId,
      },
    })
  }
  else if (url === '/subpackage/itemApply') { // 分包项目申请
    $router.push({
      path: `/subpackage/subpackage/apply/detail/${row.businessId}`,
      query: {
        formId: row.formId,
        approvalStatusName,
        decisionItem: `${row.decisionItem}`, // 控制同意、驳回、拒绝按钮
        applyProcessId: row.processId, // 流程实例
        taskId: row.taskId, // 任务id，用于审批
      },
    })
  }
  else if (url === '/subpackage/itemCheck') { // 分包项目验收
    $router.push({
      path: `/subpackage/subpackage/check/detail/${row.businessId}`,
      query: {
        formId: row.formId,
        approvalStatusName,
        checkProcessId: row.processId, // 流程实例
        taskId: row.taskId,
        decisionItem: `${row.decisionItem}`,
      },
    })
  }
  else if (url === '/subpackage/qualificationApprove') { // 分包方资格审批
    $router.push({
      path: `/subpackage/subpackage/qualificationApprove/detail/${row.businessId}`,
      query: {
        formId: row.formId,
        approvalStatusName,
        processId: row.processId, // 流程实例
        taskId: row.taskId,
        decisionItem: `${row.decisionItem}`,
      },
    })
  }
  else if (url === '/fieldTest/approve') { // 现场检测审批
    $router.push({
      path: `/fieldTest/approve/detail/${row.businessId}`,
      query: {
        approvalStatusName,
        processId: row.processId, // 流程实例
        decisionItem: row.decisionItem, // 控制同意、驳回、拒绝按钮
        taskId: row.taskId, // 任务id，用于同意、驳回、拒绝审批
      },
    })
  }
  else if (url === '/contractManagement/list') { // 收入合同审批
    $router.push({
      path: `/contractManagement/detail/${row.businessId}`,
      query: {
        approvalStatusName,
        processId: row.processId, // 流程实例
        decisionItem: `${row.decisionItem}`, // 同意、驳回、拒绝
        taskId: row.taskId,
      },
    })
  }

  else if (url === '/schedule/certPrintList') { // 证书打印
    $router.push({
      path: '/schedule/certPrintDetail',
      query: {
        approvalStatusName, // 审批状态名称
        printFileName: row.printFileName,
        printStatus: row.printStatus, // 证书打印状态
        processId: row.processId, // 流程实例
        decisionItem: `${row.decisionItem}`, // 控制同意、驳回、拒绝按钮
        taskId: row.taskId, // 任务id，用于同意、驳回、拒绝审批
        id: row.businessId, // 业务主键id
      },
    })
  }
}
