import http from '@/utils/http'
import { AppDispatch } from '..'
/**
 * 残损登记 - 获取分页列表
 */
export const E2_APIgetList = (data: any, exportFlag?: boolean): any => {
  if (exportFlag) return http.post('cms/orderPreserveDamaged/page', data)
  else {
    return async (dispatch: AppDispatch) => {
      const res = await http.post('cms/orderPreserveDamaged/page', data)
      if (res.code === 0) {
        const obj = {
          list: res.data.records,
          total: res.data.total
        }

        dispatch({ type: 'E2/getList', payload: obj })
      }
    }
  }
}

/**
 * 残损登记-删除
 */
export const E2_APIdel = (id: number) => {
  return http.get(`cms/orderPreserveDamaged/remove/${id}`)
}

/**
 * 残损登记-创建订单
 */
export const E2_APIcreate = () => {
  return http.get('cms/orderPreserveDamaged/create')
}

/**
 * 残损登记-获取详情
 */
export const E2_APIgetInfo = (id: number) => {
  return http.get(`cms/orderPreserveDamaged/detail/${id}`)
}

/**
 * 残损登记-存草稿
 */
export const E2_APIsaveDraft = (data: any) => {
  return http.post('cms/orderPreserveDamaged/saveDraft', data)
}

/**
 * 残损登记-创建
 */
export const E2_APIsaveCreate = (data: any) => {
  return http.post('cms/orderPreserveDamaged/saveCreate', data)
}

/**
 * 残损登记-编辑保存
 */
export const E2_APIsaveApply = (data: any) => {
  return http.post('cms/orderPreserveDamaged/saveApply', data)
}

/**
 * 残损登记-审批
 */
export const E2_APIsaveAudit = (data: any) => {
  return http.post('cms/orderPreserveDamaged/audit', data)
}

/**
 * 残损登记-撤回订单
 */
export const E2_APIrevocation = (id: number) => {
  return http.get(`cms/orderPreserveDamaged/revocation/${id}`)
}
