import http from '@/utils/http'
import { AppDispatch } from '..'
/**
 * 藏品总账-获取列表
 */
export const B1_APIgetlist = (data: any, exportFlag?: boolean): any => {
  if (exportFlag) return http.post('cms/goods/page', data)
  else {
    return async (dispatch: AppDispatch) => {
      const res = await http.post('cms/goods/page', data)
      if (res.code === 0) {
        const obj = {
          list: res.data.records,
          total: res.data.total
        }

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

/**
 * 藏品总账-新增藏品
 */
export const API_addGoods = (data: any) => {
  return http.post('cms/order/register/create', data)
}

/**
 * 藏品详情-获取详情
 */
export const API_getGoodsInfo = (id: number | string) => {
  return http.get(`cms/goods/detail/${id}`)
}

/**
 * 藏品详情-编辑记录
 */
export const API_getGoodsLog = (goodsId: number) => {
  return http.get(`cms/goods/order/edit/${goodsId}`)
}

/**
 * 藏品详情-库存状态
 */
export const API_getStorageLog = (goodsId: number) => {
  return http.get(`cms/goods/order/site/${goodsId}`)
}

/**
 * 附件-根据附件ids查询
 */
export const API_getFileListByIds = (data: number[]) => {
  return http.post('cms/goods/file/getList', data)
}

/**
 * 获取藏品选择列表
 */
export const API_selectGoods = (type: '入库' | '移库' | '出库', data: any) => {
  const urlType = type === '入库' ? 'in' : type === '出库' ? 'out' : 'move'

  return http.post(`cms/orderSite/${urlType}/goods/page`, data)
}
