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

// 查询流程监听列表
export function listListener(query) {
  return defHttp.get({
    url: '/flowable/listener/list',
    params: query
  })
}

// 查询流程监听详细
export function getListener(id) {
  return defHttp.get({
    url: '/flowable/listener',
    params: {id:id}
  })
}

// 新增流程监听
export function add(data) {
  return defHttp.post({
    url: '/flowable/listener/add',
    data: data
  })
}

// 修改流程监听
export function update(data) {
  return defHttp.put({
    url: '/flowable/listener/edit',
    data: data
  })
}

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

// 删除流程定义
export function delListener(id,handleSuccess) {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除？',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete(
        {
          url: `/flowable/listener/delete?id=`+id
        }
      ).then(() => {
        handleSuccess();
      });
    }
  });
}

