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

/**
 * 获取藏品登记列表信息
 */
export const getObject2List = (data: any): any => {
  return async (dispatch: AppDispatch) => {
    // 获取列表数据
    const res: any = await http.post('cms/ledger/pageList', data)
    const list = res.data.records
    list.forEach((v: any) => {
      v.storageStatusTxt = storageStatusObj[v.storageStatus]
    })
    const obj = {
      list,
      total: res.data.total
    }
    dispatch({ type: 'object2/getList', payload: obj })
  }
}

/**
 * 通过id获取藏品总账详情
 */
export const getObj2InfoInAPI = (id: number) => {
  return http.get(`cms/ledger/detail/${id}`)
}

/**
 * 藏品总账里面修改藏品
 */
export const editObj2GoodsAPI = (data: any) => {
  return http.post('cms/edit/save', data)
}

/**
 * 藏品总账里面的申请移库
 */
export const editObj2StoresAPI = (data: any) => {
  return http.post('cms/move/save', data)
}

/**
 * 藏品总账里面的操作记录
 */
export const getObj2LogListAPI = (data: any): any => {
  return async (dispatch: AppDispatch) => {
    // 获取列表数据
    const res: any = await http.post('cms/ledger/order/pageList', data)
    const obj = {
      list: res.data.records,
      total: res.data.total
    }
    dispatch({ type: 'object2/getLogList', payload: obj })
  }
}
