import { defHttp } from '/@/utils/http/axios';
import { useMessage } from "/@/hooks/web/useMessage";
const { createConfirm } = useMessage();

// 查询流程表单列表
export const listForm = async (params) => {
  const list =  await defHttp.get({ 
    url:"/flowable/form/list", 
    params 
  },{ 
    joinParamsToUrl: true 
  });
  return list
};

export const listAllForm = async (params) => {
  const list =  await defHttp.get({ 
    url:"/flowable/form/listAllForm", 
    params 
  });
  return list
};

// 查询流程表单详细
export function getForm(formId) {
  return defHttp.get({
    url: '/flowable/form/queryById',
    params :{id:formId}
  })
}

// 新增流程表单
export function addForm(data) {
  return defHttp.post({
    url: '/flowable/form/add',
    method: 'post',
    data: data
  })
}

// 修改流程表单
export function updateForm(data) {
  return defHttp.put({
    url: '/flowable/form/edit',
    data: data
  })
}
// 挂载表单
export function addDeployForm(data) {
  return defHttp.post({
    url: '/flowable/form/addDeployForm',
    data: data
  })
}

// 导出流程表单
export function exportForm(query) {
  return defHttp.get({
    url: '/flowable/form/export',
    params: query
  })
}


export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete(
        {
          url: "/flowable/form/batchDelete", 
          data: params},
          {joinParamsToUrl: true}
      ).then(() => {
        handleSuccess();
      });
    }
  });
}

export function delForm(formId,handleSuccess) {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除？',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete(
        {
          url: `/flowable/form/delete?formId=${encodeURIComponent(formId)}`
        },
      ).then(() => {
        handleSuccess();
      });
    }
  });

}


export function addFlowLinkFlorm(data) {
  return defHttp.post({
    url: '/flowable/sysDeployForm/add',
    method: 'post',
    data: data
  })
}

export function getFlowFormByDeployId(deployId) {
  return defHttp.get({
    url: '/flowable/form/findFlowFormByDeployId',
    params :{id:deployId}
  })
}
