import request from '@/utils/request'
import { MessageBox } from 'element-ui'
import qs from 'qs'
export function flow(isLoading=false) {
  return request({
    method: 'get',
    url: '/api/oa/flow',
    isLoading
  })
}
//创建配置
export function preConfig(custom_model_id,isLoading=false) {
  return request({
    method: 'get',
    url: `/api/oa/flow/create-pre/${custom_model_id}`,
    isLoading
  })
}
//获取表单字段（主要子表单）
export function fieldConfig(custom_model_id,isLoading=false) {
  return request({
    method: 'get',
    url: `/api/oa/flow/custom-model-fields/${custom_model_id}`,
    isLoading
  })
}

export function create(custom_model_id, data) {
  return request({
    method: 'post',
    url: `/api/oa/flow/create/${custom_model_id}`,
    data
    // data: qs.stringify(data, { arrayFormat: 'brackets' }),
    // headers: {
    //   'Content-Type': 'application/x-www-form-urlencoded'
    // },
  })
}
//处理
export function preDeal(flow_id,params,isLoading=false) {
  return request({
    method: 'get',
    url: `/api/oa/flow/deal-pre/${flow_id}`,
    params,
    isLoading
  })
}
export function deal(flow_id,data) {
  return request({
    method: 'post',
    url: `/api/oa/flow/deal/${flow_id}`,
    data
  })
}

export function getNextNode(params,isLoading=false) {
  return request({
    method: 'get',
    url: '/api/oa/flow/get-next-node',
    params,
    isLoading
  })
}
export function checkIsThroughNode(params,isLoading=false) {
  return request({
    method: 'get',
    url: '/api/oa/flow/check-is-through-node',
    params,
    isLoading
  })
}

export function getNextNodeUsers(params,isLoading=false) {
  return request({
    method: 'get',
    url: '/api/oa/flow/get-next-node-users',
    params,
    isLoading
  })
}

//查看列表相关
export function flowList(type,params,isLoading = false) {
  return request({
    method: 'get',
    url: `/api/oa/flow/list/${type}`,
    params,
    isLoading
  })
}

//流转
export function assign(flow_id, data) {
 return request({
   method: 'post',
   url: `/api/oa/flow/assign/${flow_id}`,
   data
 })
}

//详情
export function view(flow_id) {
  return request({
    method: 'get',
    url: `/api/oa/flow/view/${flow_id}`,
  })
}

//抄送
export function preShare(flow_id, params,isLoading = true) {
  return request({
    method: 'get',
    url: `/api/oa/flow/share-pre/${flow_id}`,
    params,
    isLoading
  })
}
export function share(flow_id, data, isLoading = true) {
  return request({
    method: 'post',
    url: `/api/oa/flow/share/${flow_id}`,
    data,
    isLoading
  })
}

//收藏
export function toggleFav(data,isLoading=true) {
  return request({
    method: 'post',
    url: '/api/oa/flow/toggle-fav',
    data,
    isLoading
  })
}

//撤回
export async function recall(data,isLoading=true) {
  await MessageBox.confirm("确认撤回？","提示")
  return request({
    method: 'post',
    url: '/api/oa/flow/recall',
    data,
    isLoading
  })
}

//删除
export async function destroy(data,isLoading=true) {
  await MessageBox.confirm("确认删除？","提示")
  return request({
    method: 'post',
    url: '/api/oa/flow/delete',
    data,
    isLoading
  })
}

//转办
export function preForward(params,isLoading=true) {
  return request({
    method: 'get',
    url: '/api/oa/flow/forward-pre',
    params,
    isLoading
  })
}
export async function forward(data,isLoading=true) {
  await MessageBox.confirm("确认转办？","提示")
  return request({
    method: 'post',
    url: '/api/oa/flow/forward',
    data,
    isLoading
  })
}

//退回节点
export async function rollback(data,isLoading=true) {
  await MessageBox.confirm("确认退回？","提示")
  return request({
    method: 'post',
    url: '/api/oa/flow/rollback',
    data,
    isLoading
  })
}
export function flowLogs(params,isLoading=false) {
  return request({
    method: 'get',
    url: '/api/oa/flow/flow-logs',
    params,
    isLoading
  })
}

export function statistics(type, params, isLoading=true) {
  return request({
    method: 'get',
    url: `/api/oa/statistics/get-chart-data/${type}`,
    params,
    isLoading
  })
}

export function updateNodeTime(params,isLoading=true) {
  return request({
    method: 'get',
    url: '/api/oa/flow/update-time',
    params,
    isLoading
  })
}

export function updateFlowTime(params,isLoading=true) {
  return request({
    method: 'get',
    url: '/api/oa/flow/update-flow-time',
    params,
    isLoading
  })
}
