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

// 查询流程达式列表
export function listExpression(query) {
  return defHttp.get({
    url: '/flowable/expression/list',
    params: query
  })
}

// 查询流程达式详细
export function getExpression(id) {
  return defHttp.get({
    url: '/flowable/expression/' + id,
  })
}

// 新增流程达式
export function add(data) {
  return defHttp.post({
    url: '/flowable/expression/add',
    data: data
  })
}

// 修改流程达式
export function update(data) {
  return defHttp.put({
    url: '/flowable/expression/edit',
    data: data
  })
}


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


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

}

