<template>
	<view class="content">
		<!-- <view class="settlement" @click="settlement">去支付</view> -->
		<view class="boxtop">
			<view class="money">￥{{money}}</view>
			<view class="moneyMS">在线支付金额</view>
		</view>
		
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				payInfo:'',
				redisId:'',
				money:'',
				id:'',
				type:'',
			}
		},
		onLoad(opt) {
			var that=this;
			console.log(opt)
			if(opt.redisId){
				this.redisId=opt.redisId
				this.money=opt.money
				this.id=opt.id
				this.type=opt.type
				this.getPayInfoByRedis()
			}
			/* this.redisId='91CA851E-624C-44DE-ACDE-15EC5D0CC4B4'
			this.getPayInfoByRedis() */
			//console.log(opt.payInfo)
			var data='{"appId":"wx89476d27c81a7a13","timeStamp":"1646302786","nonceStr":"813d19ffa04b471ba70d6a6f18fb15be","package":"prepay_id=wx031819462930106b0546efa10c765c0000","signType":"RSA","paySign":"TJW8aXN3foPeba9a2skAP0deAAPZ+9HPzGAYjd87V8WIo8joDnDqfu2+qBGIAIZ6pzS/r4nFY1FcOV+hB5sCETbGZJ1Q9V8OfDKFHmto5X8UDz1d75ZOZTAO+1KyimiJr2nQH24nNyt7cuutcs00R1+mY0xpfk3+udPPvn7P8AArKhsDefkGB0Wc/taSDSdMeOKgkJsDshC79KyvYsMjqNlXj/wWPGunuaP3VtSYk4ktCxTQUNQQPw6XanpF95x8cs76i1bAxN0Cj+TVRbrUg6oKDY3qnVdert2bTJ2Wrj9PZUWSsWvpIS0oFPr66tuo1DVy/XLnU0Oqa9UwHgf7Ww=="}'
			this.payInfo=JSON.parse(data)
			
			
		},
		methods: {
		  getPayInfoByRedis(){
			  var that=this;
			   this.$http('km66MiniApp/sys/getPayInfoByRedis', {
			     redisId:this.redisId,
			    
			   },'GET').then(res => {
			  	console.log(res)
			   this.payInfo=JSON.parse(res.data)
			   this.settlement()
			  })
		  },
          settlement(){
			  var that=this
			  console.log(this.payInfo)
			  uni.requestPayment({
			      provider: 'wxpay',
			     // timeStamp: String(Date.now()),
			  	  timeStamp:that.payInfo.timeStamp,
			      nonceStr: that.payInfo.nonceStr,
			      package: that.payInfo.package,
			      signType: that.payInfo.signType,
			      paySign: that.payInfo.paySign,
			      success: function (res) {
			          console.log('success:' + JSON.stringify(res));
			  		
			  				uni.showToast({
			  					 title: '支付成功',
			  					icon:'none',
			  					 duration: 2000
			  				 });		   
			  		
			  		uni.reLaunch({
			  			url:'../index/index?id='+that.id+'&type='+that.type
			  		})
			  		
			      },
			      fail: function (err) {
			          console.log('取消支付fail:' + JSON.stringify(err));
			  		uni.reLaunch({
			  			url:'../index/index?id='+that.id+'&type='+that.type+'&quxiao=1'
			  		})			 
			      }
			  }); 
		  }
		}
	}
</script>

<style scoped>
	.settlement{
		width: 203rpx;
		height: 74rpx;
		background: #FF4F00;
		border-radius: 37rpx;
		text-align: center;
		line-height: 74rpx;
		font-size: 30rpx;
		font-family: PingFangSC-Medium, PingFang SC;
		font-weight: 500;
		color: #FEFFFE;
		margin-top: 23rpx;
		margin-right: 32rpx;
	}
	.content{
		height: 100vh;
		background:#F4F5F7 ;
	}
	.boxtop{
		background: #FFFFFF;
		text-align: center;
	}
	.money{
		color: #FF4F00;
		font-size: 50rpx;
		padding-top: 50rpx;
	}
	.moneyMS{
		color: #999999;
       font-size: 28rpx;
	   padding: 20rpx;
	}
</style>
