<template>
	<view class="content">
		<view class="myBalance">
			<view class="myBalanceTopModel">
				<view class="myBalanceNum">
					{{userInfo.balance}}
				</view>
				<view class="myBalanceTitle">
					总金额(元)
				</view>
			</view>
		</view>
		<view class="withdrawalModel">
			<view class="withdrawalTitle">
				提现金额<span class="withdrawalTitleTipicon">*</span><span class="withdrawalTitleTip"> 起提金额1元起，服务费为1%
				</span>
			</view>
			<view class="withdrawalInitModel">
				<!-- <u--input :value="money" @change="changeValue" border="none" placeholder="请输入提现金额" clearable></u--input> -->
				<input v-model="money" type="text" @change="check_price()" placeholder="请输入提现金额">
			</view>
			<!-- 	<view class="withdrawalTitle">
				提现到微信零钱
			</view>
			<view class="withdrawalInitModel">
				<view class="wxIcon">

				</view>
				<view class="wxText">
					微信零钱
				</view>
				<view class="winxinApply">
					微信授权
				</view>
			</view> -->
			<view class="withdrawalTip">
				提现须知
			</view>
			<view class="withdrawalTipInfo">
				<u-parse :content="intro"></u-parse>
			</view>

		</view>
		<view class="applyModel">
			<view class="applyBtn" @click="applyWithdrawal">提交</view>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				money: null,
				userInfo: null,
				inputValue: null,
				intro: null,
			}
		},
		onLoad() {
			this.userInfo = uni.getStorageSync('userInfo');
			this.getTip()
		},
		methods: {
			check_price() {
				var price = '' + this.money;
				price = price.replace(/[^\d.]/g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '')
					.replace('$#$', '.').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); // 只能输入两个小数
				if (price.indexOf('.') < 0 && price != '') {
					// 以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
					price = parseFloat(price);
				}
				this.money = price;
			},
			//申请提现
			applyWithdrawal() {
				if (this.money == null || this.money == '') {
					this.$refs.uToast.show({
						type: 'error',
						message: '请输入提现金额！',
						iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/error.png'
					})
					return
				}
				this.$request('/income-add', 'POST', {
					type: '1',
					money: '' + this.money
				}).then(res => {
					console.log(res.data)
					this.money = null
					this.$refs.uToast.show({
						type: 'success',
						message: "提现申请，已提交！",
						iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/jump.png',
						complete() {}
					})
				}).catch(err => {
					uni.showToast({

						icon: 'error',

						title: '' + err.message

					})
				})

			},
			//获取体现须知
			getTip() {
				this.$request('/cashout-intro', 'GET', {}).then(res => {
					console.log('请求成功');
					this.intro = res.data.intro;
				}).catch(err => {
					uni.showToast({

						icon: 'error',

						title: '' + err.message

					})
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100vw;
		height: 100vh;
		background: linear-gradient(to bottom, #f3d4d7, #f8f8f8, #f8f8f8);
	}

	.myBalance {
		width: 100%;
		height: 126rpx;
		padding: 78rpx 0;
		text-align: center;
		display: flex;
		flex-direction: row;
		justify-content: center;

		.myBalanceTopModel {
			width: calc(100% / 3);

			.myBalanceNum {
				line-height: 88rpx;
				font-size: 56rpx;
				color: #D3195E;
				font-weight: 500;
				font-style: normal;
			}

			.myBalanceTitle {
				line-height: 38rpx;
				font-size: 24rpx;
				color: #666666;
			}
		}

	}


	.withdrawalModel {
		width: calc(100% - 60rpx);
		padding: 0 30rpx;
		height: auto;
		overflow-y: scroll;
		padding-top: 40rpx;
		background-color: #ffffff;
		border-radius: 40rpx 40rpx 0 0;

		.withdrawalTitle {
			font-size: 28rpx;
			color: #333333;
			height: 60rpx;
		}

		.withdrawalTitleTip {
			font-size: 24rpx;
		}

		.withdrawalTitleTipicon {
			color: #FF3141;
			font-size: 24rpx;
			margin-left: 10rpx;
		}

		.withdrawalInitModel {
			width: calc(100% - 60rpx);
			padding: 30rpx;
			background-color: #F6F7F8;
			border-radius: 20rpx;
			margin-bottom: 20rpx;
			min-height: 60rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;
		}

		.wxIcon {
			width: 50rpx;
			height: 50rpx;
			background-color: #333333;
		}

		.wxText {
			flex: 1;
			margin-left: 20rpx;
			font-size: 30rpx;
		}

		.winxinApply {
			text-align: center;
			width: 140rpx;
			height: 58rpx;
			font-size: 24rpx;
			background-color: #E9799F;
			color: #ffffff;
			line-height: 58rpx;
			border-radius: 58rpx;
		}

		.withdrawalTip {
			font-size: 32rpx;
			color: #333333;
			height: 60rpx;
			font-weight: 600;
			margin-bottom: 20rpx;
		}

		.withdrawalTipInfo {}
	}
</style>