<template>
	<view class="index">
		<view class="top">
			<view class="content">
				<image class="content-img" src="../../static/top.png" />
				<view class="content-left">
					<u-row style="margin: 10rpx;">
						<u-col>
							AI头条3.0，半AI写作，简单易操作
						</u-col>
					</u-row>
					<u-row justify="space-between" style="margin: 20rpx; font-size: 12px;">
						<u-col span="4">
							级别:初级
						</u-col>
						<u-col span="4">
							18人学习
						</u-col>
					</u-row>
					<u-row justify="space-between" style="margin: 10rpx; font-size: 16px;">
						<u-col span="4" style="color: #ff7800;">
							￥4.00
						</u-col>
						<!-- <u-col span="4" style="text-decoration:line-through">
							￥29.90
						</u-col> -->
					</u-row>
				</view>
			</view>
		</view>
		<view class="cell">
			<view class="cell-box">
				<view>
					无法查看资源内容，请购买!
				</view>
			</view>
		</view>

		<view class="book">
			<view class="book-text">
				<view style="padding-top: 20rpx;font-size: 14px;">资源介绍</view>
				<image class="book-img" src="../../static/top.png" />
				<view>
					《AI头条3.0--半A1写作变现新玩法》
				</view>
				<view>
					在当今 AI 飞速发展的时代，今日头条这个存在已久的平台也焕发出了新的活力。A1头条
					3.0项目为你带来全新的变现机遇，门槛极低，无需粉丝基础，新号即可直接上手操作，仅需一部手机，让你随时随地开启赚钱之旅。
					<view></view>
					这个项目的粉丝和收益转化率极为可观，经过实测，众多账号在发布文章后的短短两三天内，粉丝量就能轻松破千。无论你是新手小白，还是有经验的创作者，都能在这个项目中找到属于自己的机会。
				</view>

			</view>
		</view>
		
		
		<view class="bottom-flex">
			
			<view class="icon">
				<u-icon name="server-man"
				size="40rpx"
				></u-icon>
				客服
			</view>
			
			<view class="icon">
				<u-number-box
				style="margin: 0 auto;"
				v-model="registerForm.num"
				:min="1">
					<view slot="minus" class="minus">
						<u-icon name="minus" size="12"></u-icon>
					</view>
					<view slot="plus" class="plus">
						<u-icon name="plus" color="#FFFFFF" size="12"></u-icon>
					</view>
				</u-number-box>
			</view>
			
			<view class="button">
				<view class="button-right">
					<view>
						立即购买 ({{ price * registerForm.num }}￥)
					</view>
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	
	// wxf173d7bec0f1bbe0
	import api from '@/plugins/api.js'
	export default {
		data() {
			return {
				registerForm: {
					num: 1
				},
				price : 4,
			}
		},
		onLoad() {
			// if(this.GetQueryString('code')){		//路径上面有code说明微信已授权
			// 	this.code = this.GetQueryString('code');
			// 	//直接去登录发起请求
			// 	this.toWxLogin(this.code)
			// }else{
			// 	this.getwx_authorize()
			// }
		},
		methods: {
			valChange() {},
			getwx_authorize() {
				// let vid = uni.getStorageSync("ivcode");
				let redirect_uri = encodeURIComponent(this.VITE_REDIRECT_URI);
				let appid = this.VITE_APPID;
				window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appid +
					'&redirect_uri=' + redirect_uri +
					'&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect' + '&t=' + new Date().getTime();
			},
			//获取url中参数的方法
			GetQueryString(name) {
				var url = window.location.href;
				try {
					var cs = url.split('?')[1]; //获取?之后的参数字符串
					var cs_arr = cs.split('&'); //参数字符串分割为数组
					for (var i = 0; i < cs_arr.length; i++) { //遍历数组，拿到json对象
						if (cs_arr[i].split('=')[0] == name) {
							return cs_arr[i].split('=')[1];
						}
					}
					return "";
				} catch {
					return "";
				}
			},
			clickService() {
				uni.makePhoneCall({
					phoneNumber: this.phone,
					success: () => {},
					fail: () => {}
				});
			},
			//微信登录
			toWxLogin(code) {
				console.log(code);
				api('wxLogin', {
					code
				}, res => {
					if (res.code == 200) {
						if (this.type == 0) {
							this.price = res.result.money
						} else {
							this.price = res.result.price
						}
						localStorage.setItem("token", res.result.token)
						localStorage.setItem("userInfo", JSON.stringify(res.result.userInfo))
					} else {
						location.href = this.VITE_REDIRECT_URI
					}
				})
			},
			Register() {
				if (!localStorage.getItem('token')) {
					this.getwx_authorize()
				}

				if (this.registerForm.name.trim() === '') return uni.$u.toast('请输入姓名')
				else if (this.registerForm.phone.trim() === '') return uni.$u.toast('请输入手机号')
				if (!/^1[3-9]\d{9}$/.test(this.registerForm.phone)) {
					return uni.$u.toast('手机号格式不合法')
				}

				api('createOrder', {
					...this.registerForm,
					type: this.type
				}, res => {
					if (res.code == 200) {
						this.chooseWXPay(res.result)
					}
				})

			},
			chooseWXPay(res) {
				let self = this
				self.$jweixin.config({
					debug: false,
					appId: res.appId, //必填
					jsApiList: ['chooseWXPay']
				});
				self.$jweixin.ready(function() {
					self.$jweixin.chooseWXPay({
						appId: res.appId,
						timestamp: res
							.timeStamp, // 支付签名时间戳，注意微信 jssdk 中的所有使用 timestamp 字段均为小写。但最新版的支付后台生成签名使用的 timeStamp 字段名需大写其中的 S 字符
						nonceStr: res.nonceStr, // 支付签名随机串，不长于 32 位
						package: res.packageValue, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=\*\*\*）
						signType: res.signType, // 微信支付V3的传入 RSA ,微信支付V2的传入格式与V2统一下单的签名格式保持一致
						paySign: res.paySign, // 支付签名
						success: function(res) {
							// 支付成功后的回调函数
							uni.showToast({
								icon: 'none',
								title: '支付成功',
							});

							self.registerForm.name = ''
							self.registerForm.phone = ''
						}
					});
				});
				self.$jweixin.error(function(res) {
					uni.showToast({
						icon: 'none',
						title: '支付失败了',
					});
				});
			},
		}
	}
</script>

<style scoped lang="scss">
	.index {
		background-color: #ccc;
		.bottom-flex{
			position: fixed;
			left: 0;
			bottom: 0;
			width: 100%;
			display: flex;
			height: 100rpx;
			padding: 10rpx 0;
			background-color: #fff;
			justify-content: space-around;
			.icon{
				font-size: 26rpx;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
			}
		}
	}
	.top {
		padding-top: var(--status-bar-height);
		position: relative;
		height: 230rpx;
		background-color: #000;
	}

	.content {
		position: absolute;
		top: 20rpx;
		width: 100%;
		height: 250rpx;
	}

	.content-img {
		position: absolute;
		top: 20rpx;
		left: 20rpx;
		width: 220rpx;
		height: 160rpx;
		border-radius: 10rpx;
	}

	.content-left {
		position: absolute;
		color: #fff;
		font-size: 14px;
		left: 35%;
		top: 20rpx;
		line-height: 50rpx;
	}

	.cell {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 140rpx;
		background-color: #fff;
		width: 100%;
	}

	.cell-box {
		display: flex;
		width: 90%;
		background-color: rgb(253, 194, 4);
		height: 70rpx;
		border-radius: 10rpx;
		font-size: 12px;
		justify-content: center;
		align-items: center;
	}

	.book {
		margin-top: 20rpx;
		min-height: 600rpx;
		background-color: #fff;
	}

	.book-text {
		width: 94%;
		margin-left: 3%;
		min-height: 700rpx;
		font-size: 13px;
		line-height: 40rpx;
		padding-bottom: 100rpx;
	}

	.book-img {
		padding-top: 20rpx;
		width: 100%;
		height: 300rpx;
	}

	.button {
		position: relative;
		display: flex;
		top: 10rpx;
		width: 350rpx;
		height: 80%;
		font-size: 12px;
	}

	.button-left {
		display: flex;
		justify-content: center;
		align-items: center;
		flex: 1;
		height: 100%;
		background-color: rgb(253, 194, 5);
		// border-top-left-radius: 50rpx;
		// border-bottom-left-radius: 50rpx;
	}

	.button-right {
		display: flex;
		justify-content: center;
		align-items: center;
		flex: 1;
		height: 100%;
		background-color: rgb(51, 51, 51);
		// border-top-right-radius: 50rpx;
		// border-bottom-right-radius: 50rpx;
		border-radius: 50rpx;
		
		color: #fff;
	}
	
	
	
	// 步进器
	
	.minus {
		width: 22px;
		height: 22px;
		border-width: 1px;
		border-color: #E6E6E6;
		border-style: solid;
		border-top-left-radius: 100px;
		border-top-right-radius: 100px;
		border-bottom-left-radius: 100px;
		border-bottom-right-radius: 100px;
		@include flex;
		justify-content: center;
		align-items: center;
	}
	
	.input {
		padding: 0 10px;
		margin: 0 10rpx;
	}
	
	.plus {
		width: 22px;
		height: 22px;
		background-color: rgb(253, 194, 5);
		border-radius: 50%;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
		align-items: center;
	}
</style>