<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>

	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) => {
				console.log('onPushMessage',res);
				if(null==res.data.payload||undefined==res.data.payload||''==res.data.payload){
					return;
				}
				console.log('111',res.data.payload);
				//var str ='{vnp_BankCode=NCB, vnp_PayDate=20231218110305, vnp_TransactionNo=14248123, vnp_TmnCode=CITYTTTT, vnp_OrderInfo=25142218, vnp_TxnRef=1702872034164, vnp_Amount=1600000, vnp_CardType=ATM, vnp_TransactionStatus=00, vnp_BankTranNo=VNP14248123, vnp_ResponseCode=00}';
				var str = res.data.payload;
				var str=str.split('{').join('{"');
				var str=str.split('}').join('"}');
				var str=str.split('=').join('":"');
				var str4=str.split(', ').join('", "');
				var payload = JSON.parse(str4);
				console.log('完成支付订单',payload);
				//判断ddid正确则返回
				if(payload.vnp_TxnRef==this.ddid){
					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
							})
						}
					}
					if(this.ddid.slice(0,2)=="99"){
						uni.setStorageSync("OrderList",1);
						setTimeout(function() {
						  // 这里写要延时执行的代码
						  uni.switchTab({
						  	url:'/pages/OrderList/OrderList'
						  })
						}, 2000);
					}
					else{
						setTimeout(function() {
						  // 这里写要延时执行的代码
						  uni.switchTab({
						  	url:'/pages/index/mindex/mindex'
						  })
						}, 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>
