/**
 * 公共方法封装
 * @author luolin
 */
import request from '/@/utils/request';

export function listDicData(url: string, obj?: Object) {
	return request({
		url: url,
		method: 'post',
		data: obj,
	});
}

export function listDicUrl(url: string, query?) {
	return request({
		url: url,
		method: 'get',
		params: query,
	})
}

export function listDicUrlArr(url: string, ids?, query?) {
	const lastPart = url.split('/').pop().split('?')[0];
	let name = lastPart.replace(/-(\w)/g, (match, p1) => p1.toUpperCase());

	const urlArr = ids.map(id => `${name}=${encodeURIComponent(id)}`).join('&');
	url = url + (url.includes('?') ? '&' : '?') + urlArr

	return request({
		url: url,
		method: 'get',
		params: query,
	})
}

// 参与者选择器数据
export function fetchUserRolePicker() {
	return request({
		url: '/jsonflow/user-role-auditor/user-role/picker',
		method: 'get',
	})
}

// 查询参与者下人员
export function listUsersByRoleId(roleId, jobType) {
	return request({
		url: '/jsonflow/user-role-auditor/list-users/' + roleId,
		method: 'get',
		params: {jobType: jobType}
	})
}

