112 lines
3.0 KiB
TypeScript
112 lines
3.0 KiB
TypeScript
import request from '@/utils/request';
|
|
import type { ApiResult } from '@/api';
|
|
import type { ApprovalInstance, ApprovalUser } from '../model';
|
|
import { THINK_API_URL } from '@/config/setting';
|
|
|
|
/**
|
|
* 待办数量(个人中心红点)
|
|
*/
|
|
export async function getTodoCount() {
|
|
const res = await request.get<ApiResult<number>>(
|
|
THINK_API_URL + '/approval/todo/count'
|
|
);
|
|
if (res.data.code === 0 && res.data.data !== undefined) {
|
|
return res.data.data;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
|
|
/**
|
|
* 通过(意见可选)
|
|
*/
|
|
export async function approveTask(id: number, opinion?: string) {
|
|
const res = await request.post<ApiResult<ApprovalInstance>>(
|
|
THINK_API_URL + '/approval/task/' + id + '/approve',
|
|
{ opinion }
|
|
);
|
|
if (res.data.code === 0 && res.data.data) {
|
|
return res.data;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
|
|
/**
|
|
* 驳回(意见必填)
|
|
*/
|
|
export async function rejectTask(id: number, opinion: string) {
|
|
const res = await request.post<ApiResult<ApprovalInstance>>(
|
|
THINK_API_URL + '/approval/task/' + id + '/reject',
|
|
{ opinion }
|
|
);
|
|
if (res.data.code === 0 && res.data.data) {
|
|
return res.data;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
|
|
/**
|
|
* 存档确认(无意见,只能确认)
|
|
*/
|
|
export async function confirmTask(id: number) {
|
|
const res = await request.post<ApiResult<ApprovalInstance>>(
|
|
THINK_API_URL + '/approval/task/' + id + '/confirm'
|
|
);
|
|
if (res.data.code === 0 && res.data.data) {
|
|
return res.data;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
|
|
/**
|
|
* 归档(或签,归档后单据只读)
|
|
*/
|
|
export async function archiveTask(id: number) {
|
|
const res = await request.post<ApiResult<ApprovalInstance>>(
|
|
THINK_API_URL + '/approval/task/' + id + '/archive'
|
|
);
|
|
if (res.data.code === 0 && res.data.data) {
|
|
return res.data;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
|
|
/**
|
|
* 派单候选池(仅派单节点、本人待办)
|
|
*/
|
|
export async function listDispatchCandidates(id: number) {
|
|
const res = await request.get<ApiResult<ApprovalUser[]>>(
|
|
THINK_API_URL + '/approval/task/' + id + '/candidates'
|
|
);
|
|
if (res.data.code === 0 && res.data.data) {
|
|
return res.data.data;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
|
|
/**
|
|
* 派单(选定 1 人即完成派单节点)
|
|
*/
|
|
export async function dispatchTask(id: number, targetUserId: number) {
|
|
const res = await request.post<ApiResult<ApprovalInstance>>(
|
|
THINK_API_URL + '/approval/task/' + id + '/dispatch',
|
|
{ targetUserId }
|
|
);
|
|
if (res.data.code === 0 && res.data.data) {
|
|
return res.data;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|
|
|
|
/**
|
|
* 撤回
|
|
*/
|
|
export async function withdrawInstance(id: number) {
|
|
const res = await request.post<ApiResult<ApprovalInstance>>(
|
|
THINK_API_URL + '/approval/instance/' + id + '/withdraw'
|
|
);
|
|
if (res.data.code === 0 && res.data.data) {
|
|
return res.data;
|
|
}
|
|
return Promise.reject(new Error(res.data.message));
|
|
}
|