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

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

/**
 * 入库-删除
 */
export const D4_APIdel = (id: number) => {
  return http.get(`cms/orderIn/remove/${id}`)
}

/**
 * 入库-创建订单
 */
export const D4_APIcreate = () => {
  return http.get('cms/orderIn/create')
}

/**
 * 入库-获取详情
 */
export const D4_APIgetInfo = (id: number) => {
  return http.get(`cms/orderIn/detail/${id}`)
}

/**
 * 入库-存草稿
 */
export const D4_APIsaveDraft = (data: any) => {
  return http.post('cms/orderIn/saveDraft', data)
}

/**
 * 入库-创建
 */
export const D4_APIsaveCreate = (data: any) => {
  return http.post('cms/orderIn/saveCreate', data)
}

/**
 * 入库-编辑保存
 */
export const D4_APIsaveApply = (data: any) => {
  return http.post('cms/orderIn/saveApply', data)
}

/**
 * 入库-审批
 */
export const D4_APIsaveAudit = (data: any) => {
  return http.post('cms/orderIn/audit', data)
}

/**
 * 入库-撤回订单
 */
export const D4_APIrevocation = (id: number) => {
  return http.get(`cms/orderIn/revocation/${id}`)
}
