<template>
	<view class="content">
		<view class="top_box">
			<text class="yue-tit">当前余额：</text>
			<text class="yue-num">￥{{ now_money | parseFloatNum }}</text>
		</view>
		<view class="line_box"></view>
		<view class="cz_box">
			<view class="cz_wrap">
				<text class="cz_tit">￥</text>
				<input class="cz_input" type="number" v-model="money" @focus="changeNum()" placeholder="请输入充值金额"
					placeholder-class="placeholder" />
			</view>
			<view class="zc_list_box">
				<view class="zc_list_price" :class="{ seletPrice: seletNum == item.price }"
					@click="seletChange(item, index)" v-for="(item, index) in list" :key="index">
					{{ item.price | parseFloatNum }}元
				</view>
			</view>
		</view>
		<view class="line_box"></view>
		<!-- <view class="cz-type" @click="type = 'weixin'">
			<view class="type-left">
				<view class="icon iconfont iconweixin"></view>
				<view class="tit">微信充值</view>
			</view>
			<view class="right">
				<radio value="weixin" color=" #EB001C" :checked="type == 'weixin'" />
			</view>
		</view> -->
		<!-- #ifdef APP-PLUS -->
		<view class="cz-type" @click="type = 'ali'">
			<view class="type-left">
				<view class="icon iconfont iconzhifubao"></view>
				<view class="tit">支付宝充值</view>
			</view>
			<view class="right">
				<radio value="ali" color=" #EB001C" :checked="type == 'ali'" />
			</view>
		</view>
		<!-- #endif -->
		<button class="add-btn up" :class="{ 'active-bg': payLoding }"
			@click="!payLoding ? confirm() : ''">立即充值</button>
	</view>
</template>

<script>
	import {
		getMoneyStyle
	} from '@/utils/rocessor.js';
	
	// #ifdef H5
	import {
		rechargeWechat,
		rechargeAli
	} from '@/api/wallet.js';
	// #endif
	// #ifdef MP
	import {
		rechargeRoutine,
	} from '@/api/wallet.js';
	// #endif
	// #ifdef APP-PLUS
	import {
		rechargeAli
	} from '@/api/wallet.js';
	// #endif
	import {
		mapState
	} from 'vuex';
	import {
		spreadCommission,
		userBalance,
		moneyChong
	} from '@/api/wallet.js';
	export default {
		filters: {
			getMoneyStyle,
			// 去处小数点后的0
			parseFloatNum(clock) {
				return parseFloat(clock);
			}
		},
		data() {
			return {
				type: 'weixin',
				money: '', //充值金额
				payLoding: false, //是否加载中
				list: [
					'300',
					'200',
					'150',
					'100',
					'50'
				],
				now_money: '',
				seletNum: '300', // 选中
				zhuyi: [],
				quota: '', // 送的钱
				typeText: 0, // 0-微信 1-佣金
			};
		},
		onLoad(options) {
			this.loadData();
		},
		computed: {
			// #ifdef H5
			...mapState(['weichatObj', 'userInfo'])
			// #endif
			// #ifdef MP
			...mapState(['userInfo'])
			// #endif
		},
		methods: {
			// 跳转
			navTo(url) {
				uni.navigateTo({
					url: url
				});
			},
			changeNum() {
				this.seletNum = this.money = '';
				console.log(this.seletNum, this.money);
			},
			seletChange(item, index) {
				this.seletNum = item.price;
				this.seletMoney = item.price;
				this.money = item.price
			},
			// 切换选中对象
			tabRadio(e) {
				this.type = e.detail.value;
				if (e.detail.value == 'weixin') {
					this.typeText = 0
				} else {
					this.typeText = 1
				}
			},
			// 充值金额
			rechargeXuan(item) {
				this.money = item.price;
				this.quota = item.quota;
			},

			loadData() {
				moneyChong({}).then(({
					data
				}) => {
					console.log(data, "123456789");
					this.list = data.recharge_quota;
				});
				userBalance({}).then(({
					data
				}) => {
					this.now_money = data.now_money;
				});
			},

			// 提交
			confirm() {
				let obj = this;
				obj.payLoding = true;
				if (!obj.money) {
					obj.$api.msg('请输入金额');
					obj.payLoding = false;
					return;
				}
				// 微信支付
				if(obj.type=='weixin'){
					// #ifdef H5
					rechargeWechat({
							price: this.money,
							from: this.type,
						}).then(e => {
							let da = e.data.data;
							obj.weichatObj.chooseWXPay({
								timestamp: da.timestamp,
								nonceStr: da.nonceStr,
								package: da.package,
								signType: da.signType,
								paySign: da.paySign,
								success: function(res) {
									uni.showToast({
										title: '充值成功',
										duration: 2000,
										position: 'top',
										success: function(res) {
											uni.navigateBack()
										}
									});
								}
							});
							obj.payLoding = false;
						})
						.catch(e => {
							obj.payLoding = false;
							console.log(e);
						});
					// #endif
					// #ifdef MP
					rechargeRoutine({
							price: this.money
						})
						.then(e => {
							let da = e.data;
							wx.requestPayment({
								timeStamp: da.timestamp,
								nonceStr: da.nonceStr,
								package: da.package,
								signType: da.signType,
								paySign: da.paySign,
								success: function(res) {
									uni.showToast({
										title: '充值成功',
										duration: 2000,
										position: 'top',
										success: function(res) {
											uni.navigateBack()
										}
									});
								},
					
							})
					
							obj.payLoding = false;
						})
						.catch(e => {
							obj.payLoding = false;
							console.log(e);
						});
					// #endif
				}
				// #ifdef APP-PLUS
				if(obj.type=='ali'){
					rechargeAli({
						price: this.money
					}).then((data)=>{
						const url = data.msg;
						uni.requestPayment({
							provider: 'alipay',
							orderInfo: url,
							success: res => {
								uni.showToast({
									title: '支付成功',
									duration: 2000
								});
								obj.paySuccessTo();
							},
							fail: e => {
								console.log(e);
							},
							complete: () => {}
						});
						obj.payLoding = false;
						return
					}).catch()
				}
				// #endif
			},
		}
	};
</script>

<style lang="scss">
	page {
		height: 100%;
		background: #111111;

	}

	.top_box {
		padding: 20rpx 26rpx 20rpx 47rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;

		.yue-tit {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
		}
	
	.yue-num {
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #A581FF;
		}
	}

	.line_box {
		width: 100%;
		height: 20rpx;
		background: #1B1B1B;
	}

	.cz_box {
		padding: 40rpx 20rpx 20rpx;

		.cz_wrap {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-bottom: 20rpx;
			border-bottom: 1px solid #e6e6e6;

			.cz_tit {
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
			}

			.cz_input {
				text-align: right;
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
			}
		}

		.zc_list_box {
			display: flex;
			flex-wrap: wrap;

			.zc_list_price {
				color: #ffffff;
				width: 202rpx;
				height: 60rpx;
				background: #111111;
				border-radius: 8rpx;
				margin-top: 36rpx;
				margin-right: 50rpx;
				display: flex;
				align-items: center;
				justify-content: center;

				&:nth-child(3n) {
					margin-right: 0;
				}
			}

			.seletPrice {
				background: linear-gradient(270deg, #6E8DF7, #9977F6);
				color: #ffffff;
			}
		}
	}

	.recha-box {
		padding: 50rpx 30rpx 0;
		display: flex;
		flex-wrap: wrap;

		.recha-frame {
			width: 210rpx;
			height: 181rpx;
			border: 1px solid #dbdede;
			border-radius: 20rpx;
			display: flex;
			align-items: center;
			flex-direction: column;
			justify-content: center;
			margin-right: 30rpx;
			margin-bottom: 30rpx;

			&:nth-child(3n) {
				margin-right: 0;
			}

			.recha-top {
				display: flex;
				align-items: center;

				.recha-img {
					width: 64rpx;
					height: 62rpx;
				}

				.recha-tit {
					margin-left: 10rpx;
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: bold;
					color: #333333;
				}
			}

			.recha-song {
				margin-top: 20rpx;
				font-size: $font-base;
				font-family: PingFang SC;
				font-weight: bold;
				color: #ff9900;
			}
		}

		.select-frame {
			border: 1px solid #ef041f;
		}
	}

	.rechar-box {
		padding: 30rpx 20rpx 0;

		.rechar-title {
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #333333;
			margin-bottom: 10rpx;
		}

		.rechar-text {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #333333;
		}
	}

	.cz-type {
		margin-top: 22rpx;
		display: flex;
		justify-content: space-between;
		padding: 32rpx;
		align-items: center;

		.type-left {
			display: flex;
			align-items: center;

			.icon {
				height: 38rpx;

				image {
					width: 48rpx;
					height: 38rpx;
				}
			}

			.iconweixin {
				color: #36cb59;
			}
			.iconzhifubao{
				color: #08aaec;
			}
			.tit {
				margin-left: 12rpx;
				font-size: 30rpx;
				color: #ffffff;
			}
		}

		.type-right {
			image {
				width: 36rpx;
				height: 36rpx;
			}
		}
	}

	.add-btn {
		&.modified {}

		&.up {
			color: #ffffff;
		}

		margin-top: 100rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 604rpx;
		height: 90rpx;
		// border: 2rpx solid #F21F5D;
		border-radius: 10rpx;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #F21F5D;
		line-height: 90rpx;
		text-align: center;
		background: linear-gradient(270deg, #6E8DF7, #9977F6);
	}

	.row-box {
		margin-top: 30rpx;
		padding: 20rpx 30rpx;
		background: #fff;

		.title {
			font-size: $font-base + 2rpx;
			color: $font-color-dark;
		}

		.row {
			display: flex;
			align-items: center;
			position: relative;
			height: 80rpx;

			.tit {
				flex-shrink: 0;
				width: 40rpx;
				font-size: 30rpx;
				color: $font-color-dark;
			}

			.input {
				flex: 1;
				font-size: 30rpx;
				color: $font-color-dark;
			}

			.iconlocation {
				font-size: 36rpx;
				color: $font-color-light;
			}

			.buttom {
				color: $font-color;
				font-size: $font-base;
			}
		}
	}

	.list {
		padding-left: 30rpx;
		margin-top: 30rpx;
		background-color: #ffffff;

		.box {
			display: flex;
			align-items: center;
			width: 100%;
			height: 120rpx;
			border-bottom: 1px solid $border-color-light;
			padding-right: 25rpx;

			.icon {
				font-size: 48rpx;
				padding-right: 20rpx;
				display: flex;
			}

			.yongjing {
				width: 48rpx;
				height: 48rpx;
			}

			.iconweixin1 {
				color: #18bf16;
			}

			.iconzhifubao {
				color: #08aaec;
			}

			.title-box {
				flex-grow: 1;
				text-align: left;

				.title {
					font-size: $font-base + 2rpx;
					color: $font-color-base;
				}

				.node {
					font-size: $font-sm;
					color: $font-color-light;
				}
			}
		}
	}

	/deep/ .uni-radio-input {
		width: 45rpx;
		height: 45rpx;
	}

	.active-bg {
		background: linear-gradient(270deg, #6E8DF7, #08aaec);
		color: #FFFFFF !important;
	}
	.aaa{
		display: flex;
		
		width: 300rpx;height: 300rpx;
		background: #fff;
		.bbb{
			width: 100rpx;height: 100rpx;
			background: red;
		}
	}
</style>
