<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">
			合计：{{num*price}}元
		</view>
		<view class="button">
			<button type="primary" @click="buy()" class="button2">
				<p class="p">购买</p>
			</button>
		</view>
		<font class="font1">{{title}}</font>
		<view class="" style="margin: auto;">
			<image class=""  :src=img mode=""></image>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				price:'',
				num:'10',
				title:'',
				img:null
			}
		},
		onLoad() {
		},
		onShow() {
			this.findPrice();
		},
		methods: {
			...mapActions('chart', ['getPrice','pay']),
			findPrice(){
				var name = "timesPay";
				this.getPrice(name)
					.then(data => {
						this.price = data;
					}, _ => void uni.stopPullDownRefresh());
			},
			buy(){
				var p = this.price;
				var n = this.num;
				var pri = p*n;
				if(pri==0){
					uni.showModal({
						content: '请选择数量',
						showCancel: false
					});
					return null;
				}
				const param = {};
				param['price'] = pri;
				param['type'] = "1";
				param['equipmentId'] = uni.getStorageSync("nowEquipmentId");
				param['adminId'] = uni.getStorageSync("globalUser").id;
				this.pay(param).then(data => {
					this.title = "请用微信扫码支付";
					this.img = data;
				}, _ => void uni.stopPullDownRefresh());
				
			}
		},

	}
</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: 600upx;
		weight:600upx;
		margin: auto;
	}
</style>
