import { AppDispatch } from '@/store'
import http from '@/utils/http'
import { APIbase } from '../layout'

/**
 * 藏品入库 - 分页列表
 */
export const F1_APIgetList = (data: any): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post('cms/orderSite/in/page', data)
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total
      }

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

/**
 * 库房-分页
 */
export const F1_APIgetStorageList = () => {
  return http.post('cms/orderSite/in/storage/pageList', {
    pageNum: 1,
    pageSize: 999
  })
}

/**
 * 藏品总账列表-分页
 */
export const F1_APIgetClueList = (data: any) => {
  return http.post('cms/orderSite/in/good/page', data)
}

/**
 * 库位-列表
 */
export const F1_APIgetShelfList = (params: any) => {
  return http.get('cms/orderSite/in/getSiteList', { params })
}

/**
 * 自动分配空置仓位
 */
export const F1_APIgetShelfEmptyList = (params: any) => {
  return http.get('cms/orderSite/in/getStorageEmpty', { params })
}

/**
 * 展览列表-分页（借展归还用，可搜索展览名称）
 */
export const F1_APIgetShowList = (data: {
  pageNum: number
  pageSize: number
  searchKey?: string
}) => {
  return http.post('cms/show/pageList', data)
}

export const F1API_obj = {
  创建订单: () => APIbase('get', 'cms/orderSite/in/create'),
  获取详情: (id: number) => APIbase('get', `cms/orderSite/in/detail/${id}`),
  草稿: (data: any) => APIbase('post', `cms/orderSite/in/saveDraft`, data),
  发起: (data: any) => APIbase('post', `cms/orderSite/in/saveApply`, data),
  重新发起: (id: number) => APIbase('get', `cms/orderSite/in/reissue/${id}`),
  审批: (data: any) => APIbase('post', `cms/orderSite/in/audit`, data),
  撤回: (id: number) => APIbase('get', `cms/orderSite/in/revocation/${id}`),
  删除: (id: number) => APIbase('get', `cms/orderSite/in/remove/${id}`)
}
