<template>
	<view class="payment">
		<uni-nav-bar dark :fixed="true" background-color="#00aaff" :border="false" status-bar title="加油" />

		<view class="container">
			<uni-section title="油号" type="line" titleFontSize="34rpx"></uni-section>
			<view class="select-oil">
				<view class="oil-item">
					<view class="oil active-oil">
						<!-- <view class="unit">￥</view> -->
						<view class="number">#95</view>
					</view>
				</view>
			</view>

			<uni-section title="输入金额" type="line" titleFontSize="34rpx"></uni-section>
			<view class="money-input">
				<image src="/static/payment/money.png" mode="widthFix"></image>
				<input v-model="form.money" @focus="focus" placeholder="请输入加油金额" type="number" />
			</view>

			<view v-if="form.money" class="tip">
				折后共计{{ 
				form.money * 
				(configList.preferential ?
				configList.preferential.keyCentent
				: 1)
				}}元
			</view>
			<view class="select-money">
				<view v-for="(item, index) in rechargeList" class="money-item" :key="index">
					<view @click="selectMoney(item.price,index)" :class="{ 'active-money' : currentIndex == index }"
						class="money">
						<view class="unit">￥</view>
						<view class="number">{{ item.price }}</view>
					</view>
				</view>
			</view>
			<view class="sumit" @click="submit">提交订单</view>

		</view>

		<PrivacyAgreementPoup ref="showPrivacy"></PrivacyAgreementPoup>

		<uni-fab ref="fab" :content="content" :horizontal="horizontal" :vertical="vertical" :direction="direction"
			@trigger="clickMenu" />

		<showLogin ref="login"></showLogin>

	</view>
</template>

<script setup>
	import PrivacyAgreementPoup from "../../components/PrivacyAgreementPoup/PrivacyAgreementPoup.vue";
	import showLogin from "../../components/showLogin/showLogin.vue";
	import { mapState } from 'vuex'
	export default {
		name: 'Payment',
		component: {
			PrivacyAgreementPoup,
			showLogin
		},
		computed : {
			...mapState(['configList']),
		},
		data() {
			return {
				form: {
					money: ''
				},
				resolvePrivacyAuthorization: {},
				currentIndex: 0,
				content: [{
					iconPath: '/static/payment/wedding-celebration.png',
					text: '婚庆服务',
					active: false,
					path: '/pages/weddingCelebration/weddingCelebration'
				}],
				horizontal: 'right',
				vertical: 'bottom',
				direction: 'vertical',
				rechargeList : []
			}
		},
		onShow() {
			if (wx.onNeedPrivacyAuthorization) {
				console.log('onNeedPrivacyAuthorization');
				wx.onNeedPrivacyAuthorization(resolve => {
					console.log('onNeedPrivacyAuthorization');
					this.resolvePrivacyAuthorization = resolve
					this.$refs.showPrivacy.value.init(resolve)
				})
			}
			
			this.getRechargePage()
		},
		methods: {
			
			// 用户选择加油金额
			selectMoney(money, item) {
				this.form.money = money
				this.currentIndex = item
			},

			//输入框获得焦点
			focus() {

			},

			//用户点击了悬浮按钮
			clickMenu({
				item
			}) {
				uni.navigateTo({
					url: item.path
				})
			},

			submit() {
				if (this.$refs.login.checkLogin()) {
					return
				}
				
			},
			
			//获取充值套餐
			getRechargePage(){
				this.$api('getRechargePage', res => {
					this.rechargeList = res.result.records
				})
			}
		}
	}
</script>

<style scoped>
	.payment {
		height: 100vh;
		background: #F1F5F8;
		width: 750rpx;
		margin: 0 auto;
	}

	.container {
		width: 96%;
		margin: 0rpx auto;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 20rpx;
		overflow: hidden;
		background: white;
		margin-top: 20rpx;
	}

	.money-input {
		display: flex;
		align-items: center;
		background: #F6F7FB;
		padding: 30rpx 10rpx;
		border-radius: 20rpx;
	}

	.tip {
		color: #00aaff;
		margin-top: 10rpx;
	}

	.money-input image {
		width: 45rpx;
	}

	.money-input input {
		font-size: 36rpx;
	}

	.select-oil,
	.select-money {
		display: flex;
		justify-content: space-between;
		flex-wrap: wrap;
		margin: 30rpx 0rpx;
	}

	.select-oil {
		margin: 0;
	}

	.select-oil .oil-item,
	.select-money .money-item {
		width: 32.33%;
		background: #F1F5F8;
		border-radius: 20rpx;
		margin-bottom: 20rpx;
		overflow: hidden;
	}

	.select-oil .oil,
	.select-money .money {
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 30rpx 0rpx;
		box-sizing: border-box;
		color: #5D5C61;
	}

	.select-oil .active-oil,
	.select-money .active-money {
		background: #00aaff;
		color: white;
	}

	.select-money .unit {
		font-size: 26rpx;
	}

	.select-money .number {
		font-size: 34rpx;
	}


	.sumit {
		background: #33a5fc;
		color: white;
		font-size: 36rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		height: 80rpx;
		border-radius: 20rpx;
	}
</style>