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

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

/**
 * 获取藏品登记列表顶部数字信息
 */
export const getStores3ListNum = (): any => {
  return async (dispatch: AppDispatch) => {
    // 获取统计数据
    const res: any = await http.get('cms/move/countByStatus')

    const data = [
      { id: null, name: '全部', num: res.data.all ? res.data.all : 0 },
      // { id: 0, name: "待办理", num: res.data[0] ? res.data[0] : 0 },
      { id: 1, name: '待审核', num: res.data[1] ? res.data[1] : 0 },
      { id: 2, name: '审核不通过', num: res.data[2] ? res.data[2] : 0 },
      { id: 3, name: '已完成', num: res.data[3] ? res.data[3] : 0 }
    ]
    dispatch({ type: 'stores3/getListNum', payload: data })
  }
}

/**
 * 删除外层表格数据
 */
export const stores3DelAPI = (id: number) => {
  return http.get(`cms/move/remove/${id}`)
}

/**
 * 通过id获取信息
 */
export const stores3infoOutAPI = (id: number) => {
  return http.get(`cms/move/detail/${id}`)
}

/**
 * 审核入库信息
 */
export const auditStores3API = (data: any) => {
  return http.post('cms/move/audit', data)
}
