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

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

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

/**
 * 移库-创建订单
 */
export const D5_APIcreate = () => {
  return http.get('cms/orderMove/create')
}

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

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

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

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

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

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

/**
 * 移库-自动分配分库号
 */
export const D5_APIgetStorageNum = (num: number, storageId: number) => {
  return http.get(`cms/orderMove/getStorageNum?limit=${num}&storageId=${storageId}`)
}

/**
 * 移库-检查分库号是否使用
 */
export const D5_APIcheckSiteNum = (data: any) => {
  return http.post('cms/orderMove/checkSiteNum', data)
}

/**
 * 移库-保存审核快照
 */
export const D5_APIauditSnap = (data: any) => {
  return http.post('cms/orderMove/auditSnap', data)
}
