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: any) {
  const res = await http.request({
    url: `/flow/task/listalldata`,
    method: 'get',
    params: {
      pageSize: page.pageSize,
      currPage: page.pageNo,
      keyword: page.keyword,
    },
  })

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

/**
 * 审核
 * @param param
 */
export async function audit(params) {
  return http.request({
    url: `/flow/task/completeBatchFlow?`,
    method: 'post',
    params,
  })
}

/**
 * 移动到可疑文件夹
 * @returns
 */
export async function dubiousfileyd(params) {
  const res = await http.request({
    url: `/ocr/dubiousfile/dubiousfileyd`,
    method: 'get',
    params,
  })

  return res
}

/**
 * 显示可疑文件夹列表
 * @returns
 */
export async function dubiousfilelist(params) {
  const res = await http.request({
    url: `/ocr/dubiousfile/dubiousfilelist`,
    method: 'get',
    params,
  })

  return res
}

/**
 * 显示可疑文件夹列表
 * @returns
 */
export async function removeFiles(params) {
  const res = await http.request({
    url: `/ocr/dubiousfile/dubiousfileyc`,
    method: 'get',
    params,
  })

  return res
}

/**
 *  获取某个任务详情(相似图片列表)
 * @param packageid 任务包id
 * @param taskchildpictureid 任务详情的id
 * @param params
 * @returns
 */
export async function getSimilarityList(params: any) {
  const res = await http.request({
    url: `/backstage/jifen/ocrtaskchildpicture/getSimilarityList`,
    method: 'get',
    params,
  })

  const { data: { records, pages, total } } = res
  // 精简一下数据
  const list = records.map((item) => {
    return {
      id: item.id,
      taskId: item.taskId,
      taskname: item.fromtaskname,
      assignee: item.assignee,
      pictureid: item.pictureid,
      imgurl: item.imgUrl,
      thumburl: item.imgUrl,
      iztrueorfalse: item.iztrueorfalse,
      states: item.states,
    }
  })

  return {
    pageCount: pages,
    data: records,
    total,
  }
}

/**
 * 获取某个任务详情(字段信息)
 * @param id 任务id
 * @param packageid 任务包id
 * @returns
 */

export async function getTaskDetailInfo(taskId: string, packageid: string) {
  const pid = packageid || 0
  const res = await http.request({
    url: `/backstage/jifen/ocrtaskchildpicture/getdata/${taskId}/${pid}`,
    method: 'get',
  })

  return res.data
}
