<template>
	<view class="">
		<web-view :src="$store.state.webViewUrl"  @onPostMessage="postMessage" @message="postMessage"></web-view>
		<!-- <web-view src="http://192.168.1.44:92/vue/wxStudentCertificate3"  @onPostMessage="postMessage" @message="postMessage"></web-view> -->
	</view>
</template>

<script>
	export default {
		onLoad() {
			this.initWx()
		},
		methods: {
			postMessage(res) {
				console.log('监听到了')
				let item = res.detail.data[0]
				console.log(res)
				console.log('监听到的发送事件')
				console.log(item)
				if(item.action=='lyxc-wxPay') {
					this.$u.toast('用户点击了微信支付')
					this.wxPay(item)
				}else if(item.action=='lyxc-paySuccess') {
					this.$u.toast('支付完成，app跳转页面吧')
				}
			},
			// "action": "lyxc-wxPay",
			// "miniProgramType": 2,
			// "miniAppId": "gh_89b377cbc340",
			// "path": "/pages/wxPayOnly/wxPayOnly?channelNo=QD202404083509&orderNo=20240423170705024771&inpartNo=820198016000045&merchantName=中原智慧新校园&amount=1&redMsg=&payType=04"
			wxPay(item) {
				console.log(item)
				// #ifdef APP-PLUS
				this.sweixin ? this.sweixin.launchMiniProgram({
					path: item.path, //跳转小程序页面路径 pages/index/index
					type: item.miniProgramType, //可取值： 0-正式版； 1-测试版； 2-体验版。 默认值为0。
					id: item.miniAppId //小程序的原始id
				}) : plus.nativeUI.alert('当前环境不支持微信操作!');
				// #endif
			},
			initWx() {
				// #ifdef APP-PLUS
				plus.share.getServices((s) => {
					var shares = {};
					for (var i = 0; i < s.length; i++) {
						var t = s[i];
						console.log("...........", t);
						shares[t.id] = t;
					}
					var sweixin = shares['weixin'];
					this.sweixin = sweixin
				}, function(e) {
					console.log("获取分享服务列表失败：" + e.message);
				});
				// #endif
			},
		}
	}
</script>

<style>
</style>