<template>
	<view class="pageBg">
		<view class="pad">
			<view class="card">
				<view class="orderInfo">
					<view class="schoolName">{{schoolName}}</view>
					<view class="price">
						<text class="uint" v-if="amount">￥</text>{{ $u.utils.priceTo(amount) }}
					</view>
					<!-- <view class="num">交易单号：65465879312</view> -->
				</view>
				<!-- <view class="li border">
					amount
					<view class="val">￥ {{info.a}}</view>
				</view> -->
				<!-- <view class="li">
					<view class="lab">订单编号</view>
					<view class="val">{{info.a}}</view>
				</view> -->
			</view>
			<view class="card">
				<view class="pay">
					<!-- <view class="h2">选择支付方式</view> -->
					<!-- <view class="row border">
						<view class="wxIcon">
							<image src="@/static/images/carIcon/xfbIcon.png" mode=""></image>
						</view>
						<view class="text">支付宝</view>
						<view class="icon">
							<!-- <image src="@/static/images/index/noSelect.png" mode=""></image> -->
					<!-- <image src="@/static/images/carIcon/isSelect.png" mode=""></image>
						</view> -->
				</view>
				<!-- <view class="row">
					<view class="wxIcon">
						<image src="@/static/images/carIcon/wxIcon.png" mode=""></image>
					</view>
					<view class="text">微信</view>
					<view class="icon">
						<image src="@/static/images/index/noSelect.png" mode=""></image>
						<image src="@/static/images/carIcon/isSelect.png" mode=""></image>
					</view>
				</view> -->
			</view>
		</view>
		<view class="footerBtn pad">
			<view class="btnBg" @click="getStudentByPayment()">确认支付</view>
			<!-- <view class="btnBg" @click="paySubmit">确认支付</view> -->
			
		</view>
	</view>
	</view>
</template>

<script>
	import {
		getStudentByPayment, pre_create, param_sign
	} from '@/config/api.js'
	export default {
		data() {
			return {
				trainingApplyId: '',
				info: {
					a: '待对接'
				},
				schoolName: '',
				amount: '0',
			}
		},
		onLoad(options) {
			if (options.trainingApplyId) {
				this.trainingApplyId = options.trainingApplyId
			}
			// this.getYSBLink()
			this.getStudentByPayment()
			this.initWx()
		},
		onPullDownRefresh() {
			// this.getStudentByPayment()
		},
		methods: {
			
			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
			},
			
			async getStudentByPayment(type) {
				console.log('来到了这没有')
				const {
					data: res
				} = await pre_create({
					trainingApplyId: this.trainingApplyId
				})
				this.amount = res.amount
				this.schoolName = res.schoolName
				console.log('创建的订单信息')
				console.log(res)
				this.param_sign(res.orderNo)
			},
			// 加密数据
			async param_sign(outOrderNo) {
				let obj = {
					outOrderNo,
					timestamp: Date.now()
				}
				console.log(JSON.stringify(obj))
				const {data: res} = await param_sign({jsonParam:JSON.stringify(obj)})
				this.encodeData = res.encodeData
				console.log('加密后的数据')
				console.log(res.encodeData)
				this.getYSBLink()
			},
			async getYSBLink() {
				if(!this.encodeData) return this.$u.toast('没有获取到支付信息')
				const channelNo = 'QD202404083509';
				//common普通的h5平台，如果当前的运行环境为微信小程序则platform的值为pay_miniPro
				const platform = 'common'; 
				//易收宝H5的前端页面地址，不同的环境详见第四章第4节
				// 测试地址
				// const preUrl = 'https://ft1wbs.zyebank.cn/cem_ysb_ft2/index.html'
				const preUrl = 'https://u8wbs.zyebank.cn/cem_ysb_u8/index.html'
				// 生产地址
				// const preUrl = 'https://zmcht.zybank.com.cn/cem_ysb/index.html'; 
				// let obj = {"outOrderNo":orderNo || "2024041211570300000308","timestamp":"1632815312300"}
				const distinctId = this.userId
				const payLink = `${preUrl}?encodeData=${this.encodeData}#/checkStandPre?platform=${platform}&channelNo=${channelNo}&checkStand_v3=true&distinctId=${distinctId}`;
				console.log('payLink')
				console.log(payLink)
				this.$store.commit('updateWebVeiwUrl', payLink)
				this.$goPage('/pages/indexEntry/enroll/payment/payh5')
				
			},
			
			
		}
	}
</script>

<style lang="scss" scoped>
	.card {
		width: 100%;
		margin-bottom: 20rpx;
		padding: 0 20rpx;

		.orderInfo {
			text-align: center;

			.schoolName {
				font-size: 28rpx;
				color: #ccc;
				padding: 40rpx 0 20rpx 0;
			}

			.price {
				font-size: 72rpx;
				font-weight: 600;

				text.uint {
					font-size: 44rpx;
					font-weight: 600;
				}
			}

			.num {
				font-size: 24rpx;
				color: #ADADAD;
			}
		}

		.li {
			display: flex;
			height: 88rpx;
			line-height: 88rpx;

			&.border {
				border-bottom: 1px solid #F6F7FA;
			}

			.lab {
				color: #ccc;
				width: 230rpx;
			}

			.val {
				font-weight: 500;
				flex: 1;
				text-align: right;
			}
		}
	}

	.pay {
		.h2 {
			font-size: 32rpx;
			font-weight: 500;
			margin-bottom: 24rpx;
		}

		.row {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 88rpx;

			&.border {
				border-bottom: 1px solid #F6F7FA;
			}

			.wxIcon {
				width: 40rpx;
				height: 40rpx;
			}

			.text {
				margin-left: 20rpx;
				flex: 1;
				text-align: left;
				font-size: 28rpx;
				color: #333;
			}

			.icon {
				width: 40rpx;
				height: 40rpx;
			}
		}
	}
</style>