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

/**
 * 凭证中心-获取分页列表
 */
export const API_getGoodsList = (data: any): any => {
  return async (dispatch: AppDispatch) => {
    const res = await http.post(`cms/workVoucher/pageList`, data)
    if (res.code === 0) {
      const obj = {
        list: res.data.records,
        total: res.data.total
      }

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

/**
 * 凭证中心-获取全部数据
 */
export const API_getGoodsListAll = () => {
  return http.post(`cms/workVoucher/pageList`, {
    moduleName: '',
    pageNum: 1,
    pageSize: 99999,
    searchKey: ''
  })
}

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

/**
 * 凭证中心-删除附件
 */
// export const API_delFiles = (ids: number[]) => {
//   return http.post(`cms/workVoucher/removes`, ids)
// }

/**
 * 通用下载-批量下载
 */
export const API_download = (ids: number[]) => {
  return http.post(`cms/file/downloadBatch`, ids)
}
