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

/**
 * 藏品-新增 /编辑
 */
export const API_goodsAdd = (data: any, type: '新增' | '编辑') => {
  const url = type === '新增' ? 'cms/goods/add' : 'cms/goods/edit'

  return http.post(url, data)
}

/**
 * 藏品-获取详情
 */
export const API_goodsInfo = (id: number) => {
  return http.get(`cms/goods/detail/${id}`)
}

/**
 * 藏品-弹窗-选择藏品
 */
export const API_goodsNowAdd = (url: string, data: any) => {
  return http.post(url, data)
}

/**
 * 总账-获取分页列表
 */
export const C1_APIgetList = (data: any, exportFlag?: boolean): any => {
  if (exportFlag) return http.post('cms/goods/page', data)
  else {
    return async (dispatch: AppDispatch) => {
      const res = await http.post('cms/goods/page', data)
      if (res.code === 0) {
        const obj = {
          list: res.data.records,
          total: res.data.total
        }

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