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

/**
 * 资源使用 - 分页列表
 */
export const D4_APIgetList = (data: any): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post('cms/order/resource/page', data)
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total
      }

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

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

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

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

/**
 * 资源使用 - 下载记录
 */
export const D4API_downloadLog = (ids: number[]) => {
  return http.post('cms/order/resource/downloadLog', ids)
}
