export default {
	// 链接处理
	getLink(params: AnyObject) {
		let url = "/components/dialog/dialogCom";
		if (params) {
			let paramStr = "";
			for (let name in params) {
				paramStr += `&${name}=${params[name]}`
			}
			if (paramStr) {
				url += `?${paramStr.substr(1)}`
			}
		}
		return url;
	},

	// 全局弹窗
	dialog(params = {}, callback: Function) {
		uni.navigateTo({
			url: this.getLink(params),
			success(e) {
				uni.$off("jx_dialog");
				uni.$on("jx_dialog", (type) => {
					callback && callback(type)
				})
			}
		})
	},

	// 弹出提示弹窗
	alert(data = {}, callback: Function, close?: Function) {
		let obj1 = { type: "alert", isCloseBtn: '0', isMaskClose: '0' };
		let params = Object.assign(obj1, data)
		this.dialog(params, (type: string) => {
			if ("confirm" == type) {
				callback && callback()
			} else {
				close && close()
			}
		})
	},

	// 确认提示框弹窗
	confirm(data = {}, confirm: Function, cancel: Function) {
		let obj1 = { type: "confirm", isCloseBtn: '0', isMaskClose: '0' };
		let params = Object.assign(obj1, data)
		this.dialog(params, (type: string) => {
			if ("confirm" == type) {
				confirm && confirm()
			} else if ("cancel" == type) {
				cancel && cancel()
			}
		})
	}
}