<template>
	<view>
		<!-- <web-view :webview-styles="webviewStyles" src="https://uniapp.dcloud.io/static/web-view.html"></web-view> -->
		<web-view :webview-styles="webviewStyles" :src="Url" @message="webMessage"></web-view>
		
	</view>
</template>

<script>
	import {
		pushMsg
	} from '@/pages/api/basic.js';
	export default {
		data() {
			return {
				webviewStyles: {
					progress: {
						color: '#FF3333'
					}
				},
				Url:'',
				cid:'',
				ddid:''
			}
		},
		onLoad(option) {
			this.cid = uni.getStorageSync("cid");
			this.ddid = option.ddid;
			console.log(this.ddid);
			const url = JSON.parse(decodeURIComponent(option.url));
			this.Url = url;
			// setTimeout(() => {
			// 	console.log('setTimeout');
			// 	//this.pushMsg();
			// 	//uni.navigateBack();
			// }, 10000);
			
			uni.onPushMessage((res) => {
				if(null==res.data.payload||undefined==res.data.payload||''==res.data.payload){
					return;
				}
				console.log(res);
				var payload = JSON.parse(res.data.payload);
				console.log('完成支付订单',payload);
				//判断ddid正确则返回
				var tempid = payload.vnp_OrderInfo.substring(0, 2);
				
				if('CZ'==tempid){
					if(payload.vnp_TransactionStatus=='00'&&payload.vnp_ResponseCode=='00'){
						uni.showToast({
						    title: this.$t('order.zhifuchg'),
						    icon: 'none',
						    duration: 2000
						})
					}
					else{
						if(payload.vnp_ResponseCode=='00'){
							uni.showToast({
							    title: this.$t('order.yinhangculz'),
							    icon: 'none',
							    duration: 2000
							})
						}
						else{
							uni.showToast({
							    title: this.$t('order.zhifushib'),
							    icon: 'none',
							    duration: 2000
							})
						}
					}
					setTimeout(function() {
					  // 这里写要延时执行的代码
					  uni.redirectTo({
					  	url:'/pages/tixian/Baozhengjin'
					  })
					  // uni.reLaunch({
					  // 	url:'/pages/tixian/Baozhengjin'
					  // })
					}, 2000);
				}
			});
			
		},
		onShow() {
		},
		methods:{
			webMessage(data){
				console.log(data);
			},
			async pushMsg(){//消息推送
				await this.$http.get(`${pushMsg}`, {
						cid:this.cid,
						title:'11',
						content:'22',
						payload:"{\"date\":\"20230808000230\",\"orderNo\":\"1691419030972\",\"notes\":\"\",\"sign\":\"96411cf48914fc94c24593babac979b9\",\"remark\":\"手动调为成功\",\"orderAmt\":\"1.00\",\"version\":\"V2\",\"bizAmt\":\"1.00\",\"status\":\"1\"}",
					},false)
				.then(async r => {
					console.log(r)
				})
				.catch(err => {
					console.log(err)
				})
			},
		},
	}
</script>

<style>

</style>



