import http from '@/utils/http'
import { AppDispatch } from '..'
import { TypeD2list } from '@/pages/D_storeManage/D2storSet/type'
/**
 * 库房设置 - 获取分页列表
 */
export const D2_APIgetList = (data: any, backFu?: (arr: TypeD2list[]) => void): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post('cms/storage/st/pageList', data)
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total
      }
      dispatch({ type: 'D2/getList', payload: obj })

      if (backFu) backFu(obj.list)
    }
  }
}

/**
 * 库房设置-删除
 */
export const D2_APIdel = (id: number) => {
  return http.get(`cms/storage/st/remove/${id}`)
}

/**
 * 库房设置-新增/编辑
 */
export const D2_APIedit = (data: any) => {
  return http.post('cms/storage/st/save', data)
}

/**
 * 库房设置-获取详情
 */
export const D2_APIgetInfo = (id: number) => {
  return http.get(`cms/storage/st/detail/${id}`)
}

// ---------------------------库位设置----------------------------

/**
 * 库房设置-获取库位列表
 */
export const D2_APIgetSiteList = (id: number) => {
  return http.get(`cms/storage/site/list/${id}`)
}

// ------区域-------------

/**
 * 库房设置-获取区域-列表
 */
export const D2_APIgetAreaList = (id: number) => {
  return http.get(`cms/storage/region/getList/${id}`)
}

/**
 * 库房设置-区域-删除检查
 */
export const D2_APIareaDelCheck = (id: string) => {
  return http.get(`cms/storage/region/check/${id}`)
}

/**
 * 库房设置-区域-新增/修改
 */
export const D2_APIareaEdit = (data: any) => {
  return http.post('cms/storage/region/batchSave', data)
}

/**
 * 库房设置-区域-批量删除
 */
export const D2_APIareaDels = (data: any) => {
  return http.post('cms/storage/region/removes', data)
}

// ------库位-------------

/**
 * 库房设置-库位-批量删除
 */
export const D2_APIaddDels = (data: any) => {
  return http.post('cms/storage/site/removes', data)
}

/**
 * 库房设置-库位-新增
 */
export const D2_APIaddAdd = (data: any) => {
  return http.post('cms/storage/site/batchSave', data)
}

/**
 * 库房设置-库位-编辑
 */
export const D2_APIaddEdit = (data: any) => {
  return http.post('cms/storage/site/edit', data)
}
