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

/**
 * 藏品盘点 - 分页列表
 */
export const F4_APIgetList = (data: any, res?: boolean): any => {
  if (res) {
    return http.post('cms/orderSite/check/page', { pageNum: 1, pageSize: 99999, status: 4 })
  } else {
    return async (dispatch: AppDispatch) => {
      const res = await http.post('cms/orderSite/check/page', data)
      if (res.code === 0) {
        const obj = {
          list: res.data.records,
          total: res.data.total
        }

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

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

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

/**
 * 盘点登记-列表
 * type: SG-事故登记 XZ-现状登记 XF-修复登记
 */
export const F4_APIgetRelatedOrderList = (num: string, type?: 'SG' | 'XZ' | 'XF') => {
  return http.get(`cms/orderSite/check/relatedOrderByNum/${num}`, { params: { type } })
}
