<template>
	<view class="content">
		<view class="content-swiper">
			{{payInfo.title}}
		</view>
		<view class="content-price">
			<text>￥</text>{{payInfo.sumPrice}}
		</view>
		<view class="content-company">
			<text>收款方</text>
			<text>上海印宏网络科技有限公司</text>
		</view>
		<button @click="jump">立即支付</button>
	</view>
</template>

<script>
	import apiBaseConfig from '@/config/index.js';
	import {createPayOrder} from '@/api/system/index.js'
	export default {
		data() {
			return {
				imgBgUrl: apiBaseConfig.imgBgUrl,
				globalData: getApp().globalData,
				scrollTopHeader: 0,
				orderQuery:{},
				payInfo:{
					sumPrice:0,
					title:''
				}
			};
		},
		onLoad(option) {
			if(option.orderQuery){
				let info = JSON.parse(decodeURIComponent(option.orderQuery))
				console.log(info,'打算今年')
				this.orderQuery = info
			}
			if(option.sumPrice){
				this.payInfo.sumPrice = option.sumPrice
				this.payInfo.title = option.title
			}
		},
		methods: {
			// 支付接口
			async handlePay(){
				let that = this
				const data_back = await createPayOrder(that.orderQuery)
				const {code,data} = data_back
				if(code === 200){
					uni.requestPayment({
						provider:'wxpay',
						nonceStr: data.nonceStr, // 随机字符串
						package: data.packageValue, // 固定值
						timeStamp:data.timeStamp, // 时间戳（单位：秒）
						signType: data.signType,
						paySign: data.paySign,
						success: (res) => {
							if (res.errMsg == 'requestPayment:ok') {
								that.$uniGo.navigateTo({
									url:'/demand/prosperity/index'
								})
							}
						},
						fail(err) {
							console.log('失败')
							if (err.errMsg == 'requestPayment:fail cancel') {
								
							}
						
						}
					})
				}
			},
			async jump(){
				this.handlePay()
				// this.$uniGo.navigateTo({
				// 	url: `/demand/prosperity/index`
				// });
			}
		}
	}
</script>
<style lang="scss" scoped>
	.content {
		&-swiper {
			margin-top: 60rpx;
			width: 100%;
			text-align: center;
			font-size: 26rpx;
			font-weight: 400;
			color: #333333;
		}

		&-price {
			width: 100%;
			text-align: center;
			margin-top: 10rpx;
			font-size: 80rpx;
			font-weight: 700;
			color: #F55726;
			>text{
				font-size: 50rpx;
			}
		}
		&-company{
			margin: 109rpx 20rpx 0rpx;
			padding: 20rpx;
			border-top: 1rpx solid #D4D4D4;
			border-bottom: 1rpx solid #D4D4D4;
			>text:nth-child(1){
				font-size: 28rpx;
				font-weight: 400;
				color: #999999;
				margin-right: 20rpx;
			}
			>text:nth-child(2){
				font-size: 30rpx;
				font-weight: 400;
				color: #333333;
			}
		}
		>button{
			position: absolute;
			bottom: 98rpx;
			height: 80rpx;
			line-height: 80rpx;
			background: #2C66FF;
			border-radius: 10rpx;
			width: calc(100% - 20rpx * 2);
			margin-left: 20rpx;
			font-size: 26rpx;
			text-align: center;
			font-weight: 500;
			color: #FFFFFF;
		}
	}
</style>
