import api from './api'
import {
	VUE_APP_API_URL
} from '@/config'
import cookie from '@/utils/cookie'


export function userGetUserInfo(data) {
	return api.get('/system/user/profile/get', data, {
		login: true
	})
}


export function getSimpleUserList(data) {
	return api.get('/system/user/page', data, {
		login: true
	})
}

export function getSimpleUserList2(data) {
	return api.get('/system/user/simple-list', data, {
		login: true
	})
}

export function getFlowUsers(data) {
	return api.get('/crm/flow/flow-users', data, {
		login: true
	})
}

export function updateUser(data) {
	return api.put('/system/user/profile/update', data, {
		login: true
	})
}


export function updateUserProfilePassword(data) {
	return api.put('/system/user/profile/update-password', data, {
		login: true
	})
}

export function getAllUserList(data) {
	return api.get('/system/user/list-all', data, {
		login: true
	})
}

export function deleteBpmFile(data) {
	return api.delete(`/infra/file/deleteBpmFile?url=${data.url}`, data, {
		login: true
	})
}


//上传文件 流程的
export function uploadFile(filePath, cancelLoading) {
	return new Promise((resolve, reject) => {
		if (!cancelLoading) {
			uni.showLoading({
				title: '上传中'
			})
		}
		let url = VUE_APP_API_URL + '/infra/file/bpmUpload'
		uni.showLoading({
			title: '正在上传'
		})
		uni.uploadFile({
			url,
			name: 'uploadFiles',
			filePath: filePath,
			header: {
				'Authorization': 'Bearer ' + cookie.get('accessToken'),
				'tenant-id': '1'
			},
			success: res => {
				console.log(res)
				uni.hideLoading()
				if (JSON.parse(res.data).code == 200 || JSON.parse(res.data).code == 0) {
					resolve(JSON.parse(res.data).data)
				} else if (JSON.parse(res.data).code == 401) {
					uni.showToast({
						title: '登录过期，请重新登录',
					});
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/components/pages/login/login'
						})
					}, 1000)
					reject(res)
				} else {
					uni.showToast({
						title: JSON.parse(res.data).msg
					});
					reject(res)
				}
			},
			fail: err => {
				uni.hideLoading()
				reject(err)
			}
		})
	})
}