import qs from 'qs'
import { http } from '@/utils/http/axios'
import type { ApprovalParam, PageParam } from '/#/api'
import { ContentTypeEnum } from '@/enums/httpEnum'

/**
 * 获取审核列表
 * @returns
 */
export async function getApprovalList(page: PageParam) {
  const res = await http.request({
    url: `/flow/task/listalldata`,
    method: 'get',
    params: { pageSize: page.pageSize, currPage: page.pageNo },
  })

  const { data: { list, totalCount } } = res
  return {
    pageCount: Math.ceil(totalCount / page.pageSize!),
    data: list,
  }
}

/**
 * 审核
 * @param param
 */
export async function audit(params: ApprovalParam) {
  return http.request({
    url: `/flow/task/completeBatchFlow?`,
    method: 'post',
    params: qs.stringify(params, { indices: false }),
    headers: { 'Content-Type': ContentTypeEnum.FORM_DATA },
  })
}
