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

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

/**
 * 事故登记-删除
 */
export const E1_APIdel = (id: number) => {
  return http.get(`cms/orderPreserveAccident/remove/${id}`)
}

/**
 * 事故登记-创建订单
 */
export const E1_APIcreate = () => {
  return http.get('cms/orderPreserveAccident/create')
}

/**
 * 事故登记-获取详情
 */
export const E1_APIgetInfo = (id: number) => {
  return http.get(`cms/orderPreserveAccident/detail/${id}`)
}

/**
 * 事故登记-存草稿
 */
export const E1_APIsaveDraft = (data: any) => {
  return http.post('cms/orderPreserveAccident/saveDraft', data)
}

/**
 * 事故登记-创建
 */
export const E1_APIsaveCreate = (data: any) => {
  return http.post('cms/orderPreserveAccident/saveCreate', data)
}

/**
 * 事故登记-编辑保存
 */
export const E1_APIsaveApply = (data: any) => {
  return http.post('cms/orderPreserveAccident/saveApply', data)
}

/**
 * 事故登记-审批
 */
export const E1_APIsaveAudit = (data: any) => {
  return http.post('cms/orderPreserveAccident/audit', data)
}

/**
 * 事故登记-撤回订单
 */
export const E1_APIrevocation = (id: number) => {
  return http.get(`cms/orderPreserveAccident/revocation/${id}`)
}

/**
 * 事故登记-通过事故藏品编号获取藏品列表-下拉框使用
 */
export const E1_APIgetGoodsList = (typeName: string) => {
  return http.post(`cms/orderPreserveAccident/goods/getList?typeName=${typeName}`)
}
