let goMiniAppFlag = false

const route = {
	//跳转小程序
	goMiniApp(data, item) {
		if (goMiniAppFlag) return
		goMiniAppFlag = true
		let myData = JSON.parse(data)
		wx.navigateToMiniProgram({
			...myData,
			success: (res) => {
				// 打开成功
				goMiniAppFlag = false
				item && applist.BrowseRecordAdd(item.id)
			},
			fail: () => {
				goMiniAppFlag = false
			}
		})

	},
	//跳转页面
	goPage(url, type, data) {
		if (type == 'reLaunch') {
			uni.reLaunch({
				url
			});
			return
		}
		if (type == 'redirectTo') {
			uni.redirectTo({
				url
			});
			return
		}
		uni.navigateTo({
			url,
			success: function(res) {
				// 通过eventChannel向被打开页面传送数据
				res.eventChannel.emit('passParameters', data)
			}
		});
	},
	//页面接受参数
	goPageGetData() {
		return new Promise((res) => {
			const eventChannel = this.getOpenerEventChannel()
			eventChannel.on('passParameters', function(data) {
				res(data)
			})
		})
	},
	//根据类型跳转
	clickJumpType(item) {
		console.log(item)
		if (item.jumpUrlType == 'goMiniApp') {
			route.goMiniApp(item.jumpUrl)
		}
		if (item.jumpUrlType == 'goPage') {
			route.goPage(item.jumpUrl)
		}
		if (item.jumpUrlType == 'goWebView') {
			route.goPage(`/pages/webview/webview?src=${item.jumpUrl}`)
		}
	},
}

export default route
