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

/**
 * 藏品登记 -获取分页列表
 */
export const D1_APIgetList = (data: any): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post('cms/order/register/page', data)
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total
      }

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

/**
 * 藏品登记-藏品新增|编辑
 */
export const D1_APIgoodsSave = (data: any) => {
  return http.post('cms/order/register/add', data)
}

/**
 * 藏品登记-获取藏品征集列表
 */
export const D1_APIgetClueList = (data: any) => {
  return http.post('cms/order/register/collect/getList', data)
}

export type APItxtType =
  | '创建订单'
  | '获取详情'
  | '草稿'
  | '发起'
  | '重新发起'
  | '审批'
  | '撤回'
  | '删除'

export type API_objType = { [x in APItxtType]: any }

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