<template>
	<view class=" ">
		<view class="font header">
			优惠码价格:{{price}}元/个
		</view>
		<view class="font header">
			<view class="font">
				你要购买的数量:
			</view>
			<view class="input-two">
				<input  type="text" class="input" v-model="num" />
			</view>
			<view class="font3">
				个
			</view>
		</view>
		<view class="font2 header">
			<view class="font">
				有效期:
			</view>
			<view class="input-two">
				<input  type="text" class="input" v-model="day" />
			</view>
			<view class="font3">
				天.(最长90天)
			</view>
		</view>
		<view class="font2 header">
			合计：{{num*price}}元
		</view>
		<view class="button">
			<button type="primary" @click="buy()" class="button2">
				<p class="p">购买</p>
			</button>
		</view>
		<view class="" style="margin: auto;">
			<font class="font1">{{title}}</font>
			<image class="img"  :src=img mode=""></image>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				price:null,
				num:'10',
				day:'30',
				title:'',
				img:null
			}
		},
		onLoad() {
		},
		onShow() {
			this.findPrice();
		},
		methods: {
			findPrice(){
				var token = uni.getStorageSync("token");
				uni.request({
					url: this.serverurl + '/TPromoCode/findPrice',
					method: "GET",
					header:{
						'token':token
					},
					success: (res) => {
						
						this.price = res.data.data;
					}
				})
			},
			buy(){
				if(this.day>90){
					uni.showModal({
						content: '有效期不能超过90天',
						showCancel: false
					});
					return null;
				}
				var p = this.price;
				var n = this.num;
				var pri = p*n;
				if(pri==0){
					uni.showModal({
						content: '价格为0',
						showCancel: false
					});
					return null;
				}
				var globalUser = uni.getStorageSync("globalUser");
				var id = globalUser.id;
				uni.request({
					url: this.serverurl + '/TPromoCode/buy?pri='+pri+'&adminId='+id+'&day='+this.day,
					method: "GET",
					success: (res) => {
						var img = res.data.data;
						this.title = "请用微信扫码支付";
						this.img = img;
					}
				})
			}
		},

	}
</script>

<style>
	.header {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		padding-left: 20upx;
	}
	.font{
		padding-top: 20upx;
		height: 70upx;
		color: #363D44;
		font-size: 36upx;
		font-family: "PingFang-SC-Bold";
	}
	.font2{
		padding-top: 40upx;
		padding-bottom: 30upx;
		height: 70upx;
		color: #363D44;
		font-size: 36upx;
		font-family: "PingFang-SC-Bold";
	}
	.font3{
		padding-left: 30upx;
		padding-top: 23upx;
		height: 70upx;
		color: #363D44;
		font-size: 36upx;
		font-family: "PingFang-SC-Bold";
	}
	.input-two {
		width: 80upx;
		height: 30upx;
		padding-top: 23upx;
		padding-left: 30upx;
	}
	.input {
		padding-left: 20upx;
		
		background-color: #FFFFFF;
		width: 80upx;
		height: 30upx;
		box-shadow: 0upx 0upx 20upx #D3D3D3;
		border-radius: 5upx;
	}
	.button{
		padding-top: 70upx;
		margin: auto;
		width: 80%;
		height: 100upx;
	}
	.button2{
		margin: auto;
		width: 80%;
		height: 100upx;
	}
	.p{
		padding-top: 2upx;
		margin: 0 auto;
		font-size: 45upx;
		font-family: "PingFang-SC-Bold";
	}
	.font1{
		color: #F4AE1B;
		padding-left: 300upx;
		padding-top: 100upx;
		font-size: 25upx;
		font-family: "PingFang-SC-Bold";
	}
	.img{
		height: 650upx;
		weight:650upx;
		margin: auto;
	}
</style>
