import request from '@/api/request.js'

/**
 * 免账号密码使用userId登录，大家需要使用自己的登录逻辑
 * @param {String} userId 用户userId
 */
export function login(userId) {
	return request({
		url: `/sys/auth/login/ignore/${userId}`
	})
}

//查询组织架构列表
export function getOrgTree(params) {
	return request({
		url: '/oa/org/tree',
		data: params
	})
}

//查询用户历史签名
export function getUserSign() {
	return request({
		url: '/oa/org/user/sign'
	})
}

// 查询系统角色列表
export function getRole() {
	return request({
		url: '/oa/org/role'
	})
}

// 搜索人员
export function getUserByName(params) {
	return request({
		url: '/oa/org/tree/user/search',
		data: params,
		header: {
			Tenantid: JSON.parse(uni.getStorageSync("loginUser")).sn
		}
	})
}

// 搜索部门
export function getDeptByName(params) {
	return request({
		url: '/oa/org/tree/dept/search',
		data: params,
		header: {
			Tenantid: JSON.parse(uni.getStorageSync("loginUser")).sn
		}
	})
}

// 搜索组织
export function getEnterpriseByName(params) {
	return request({
		url: '/oa/org/tree/enterprise/search',
		data: params,
		header: {
			Tenantid: JSON.parse(uni.getStorageSync("loginUser")).sn
		}
	})
}

// 搜索人员
export function getUserDepts(userId) {
	return request({
		url: `/oa/org/user/${userId}/dept`
	})
}

// 获取审批代理人
export function getUserAgent() {
	return request({
		url: `/oa/org/user/agent`
	})
}

// 获取审批代理人
export function setUserAgent(params) {
	return request({
		url: `/oa/org/user/agent`,
		method: 'PUT',
		data: params,
	})
}

// 取消审批代理人
export function cancelUserAgent() {
	return request({
		url: `/oa/org/user/agent`,
		method: 'DELETE',
	})
}

// 查询用户详细资料
export function getUserDetail(userId) {
	return request({
		url: `/oa/org/user/${userId}/detail`,
		method: 'GET',
	})
}


export default {
	login,
	getOrgTree,
	getUserSign,
	getRole,
	getUserByName,
	getUserDepts,
	getUserAgent,
	setUserAgent,
	cancelUserAgent,
	getUserDetail
}