export function msg(content) {
	uni.showToast({
		title: content,
		icon: 'none'
	})
}
// 错误消息
export function msgError(content) {
	uni.showToast({
		title: content,
		icon: 'error'
	})
}
// // 成功消息
export function msgSuccess(content) {
	uni.showToast({
		title: content,
		icon: 'success'
	})
}
// // 隐藏消息
export function hideMsg(content) {
	uni.hideToast()
}
// // 弹出提示
export function alert(content, title) {
	uni.showModal({
		title: title || '系统提示',
		content: content,
		showCancel: false
	})
}
// // 确认窗体
export function confirm(content, title) {
	return new Promise((resolve, reject) => {
		uni.showModal({
			title: title || '系统提示',
			content: content,
			cancelText: '取消',
			confirmText: '确定',
			success: function(res) {
				if (res.confirm) {
					resolve(res.confirm)
				}
			}
		})
	})
}
// // 提示信息
export function showToast(option) {
	if (typeof option === "object") {
		uni.showToast(option)
	} else {
		uni.showToast({
			title: option,
			icon: "none",
			duration: 2500
		})
	}
}
// // 打开遮罩层
export function loading(content) {
	uni.showLoading({
		title: content,
		icon: 'none'
	})
}
// // 关闭遮罩层
export function closeLoading() {
	uni.hideLoading()
}

// /**
//  * 显示模态弹窗
//  * @param content 提示的标题
//  */
export function showConfirm(content) {
	return new Promise((resolve, reject) => {
		uni.showModal({
			title: '提示',
			content: content,
			cancelText: '取消',
			confirmText: '确定',
			success: function(res) {
				resolve(res)
			}
		})
	})
}

/**
 * 参数处理
 * @param params 参数
 */
export function tansParams(params) {
	let result = ''
	for (const propName of Object.keys(params)) {
		const value = params[propName]
		var part = encodeURIComponent(propName) + "="
		if (value !== null && value !== "" && typeof(value) !== "undefined") {
			if (typeof value === 'object') {
				for (const key of Object.keys(value)) {
					if (value[key] !== null && value[key] !== "" && typeof(value[key]) !== 'undefined') {
						let params = propName + '[' + key + ']'
						var subPart = encodeURIComponent(params) + "="
						result += subPart + encodeURIComponent(value[key]) + "&"
					}
				}
			} else {
				result += part + encodeURIComponent(value) + "&"
			}
		}
	}
	return result
}