import http from '@/utils/http'
import { AppDispatch } from '..'

/**
 * 资源管理-列表
 */
export const C21_APIList = (data: any, exportFlag = false): any => {
  if (exportFlag) return http.post('/cms/orderZy/page', data)
  return async (dispatch: AppDispatch) => {
    const res = await http.post('/cms/orderZy/page', data)
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total
      }

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

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

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

/**
 * 资源管理-创建订单
 */
export const C21_APIcreate = () => {
  return http.get('/cms/orderZy/create')
}

/**
 * 资源管理-存草稿
 */
export const C21_APIsaveDraft = (data: any) => {
  return http.post('cms/orderZy/saveDraft', data)
}

/**
 * 资源管理-创建
 */
export const C21_APIsaveCreate = (data: any) => {
  return http.post('cms/orderZy/saveCreate', data)
}

/**
 * 资源管理-编辑保存
 */
export const C21_APIsaveApply = (data: any) => {
  return http.post('cms/orderZy/saveApply', data)
}

/**
 * 资源管理-审批
 */
export const C21_APIsaveAudit = (data: any) => {
  return http.post('cms/orderZy/audit', data)
}

/**
 * 批量下载-根据藏品id下载藏品附件
 */
export const C21_APIDownloadBatchZip = (ids: (string | number)[]) => {
  return http.post('cms/goodsFile/downloadBatchZip', ids)
}
