<template>
	<view class="main">
		<view class="body_style_money flex justify-center align-center u-flex-col">
			<view class="text-white" style="font-size: 70rpx;">
				{{vuex_user.balance/100}}<text class="u-font-35 u-margin-left-10">元</text>
			</view>
			<view class="text-white u-font-28 u-margin-top-30">
				可提现金额
			</view>
		</view>
		<view class="body_style_money u-margin-top-30 padding" style="height: 280rpx;background: #fff;">
			<view class="flex justify-between align-center">
				<u-input v-model="money" placeholder="请输入提现的金额" type="number" border />
				<button @click="allMoney" style="color: #fff;background: #F1C453;border-color: #F1C453;"
					hover-class="none" class="left_btn u-margin-left-20">全部提现</button>
			</view>
			<view class="text-black text-sm u-margin-top-15">
				提现基础额为10元，手续费{{configData.withdraw_ratio}}%
			</view>
			<view class="text-sm u-margin-top-5" style="color: #F1C453;">
				手续费：{{money*configData.withdraw_ratio/100}}元
			</view>
			<view class="text-sm u-margin-top-5" style="color: #F1C453;">
				预计到账金额为：{{money-(money*configData.withdraw_ratio/100)}}元
			</view>
		</view>
		<u-button shape="circle" @click="submit_money" hover-class="none"
			:custom-style="{...customStyle,width:'500rpx',height:'66rpx'}" throttle-time="1000">立即提现</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				money: '',
				customStyle: {
					width: '214rpx',
					height: '52rpx',
					color: '#fff',
					background: '#FBC600',
					border: 'none',
					marginTop: '30rpx'
				},
				configData:{}
			}
		},
		onLoad() {
			this.getUserConfig()
		},
		methods: {
			async getUserConfig() {
				let res = await this.$u.post("manager/sysConfig")
				if(res.code == 200){
					this.configData = res.data
				}
			},
			allMoney() {
				this.money = this.vuex_user.balance / 100
			},
			async submit_money() {
				if (this.vuex_user.bank_card == null) {
					uni.showModal({
						title: "温馨提示",
						content: "尚未绑定银行卡，是否前往绑定?",
						success: (res) => {
							if (res.confirm) {
								uni.navigateTo({
									url: "./bank_card"
								})
							}
						}
					})
					return false
				}
				if (this.money < 10) {
					uni.showToast({
						title: "金额最低为10元",
						icon: "none"
					})
					return false
				}
				let res = await this.$u.post('manager/withdraw', {
					money: this.money * 100
				})
				if (res.code == 200) {
					uni.showModal({
						title: "温馨提示",
						content: "提交成功，请等待后台审核",
						showCancel: false,
						success: (res) => {
							if (res.confirm) {
								uni.navigateBack()
							}
						}
					})
				}else{
					uni.showToast({
						title:res.message,
						icon:"none"
					})
					return false
				}
			}
		}
	}
</script>

<style>
	.main {
		padding: 50rpx;
	}

	.body_style_money {
		width: 100%;
		height: 300rpx;
		background-color: #F1C453;
		border-radius: 16rpx;
		box-shadow: 6rpx 6rpx 10rpx rgba(122, 122, 122, 0.2);
	}

	.left_btn::after {
		border: none;
	}

	.left_btn {
		padding: 0;
		color: #909399;
		/* border: 2rpx solid rgba(144, 147, 153, .5); */
		border: none;
		border-radius: 8rpx;
		width: 170rpx;
		height: 60rpx;
		font-size: 28rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background: #fff;
	}
</style>
