<template>
	<view class="withdraw">
		<view class="header-bg"></view>
		<view class="block">
			<view class="account">
				<image class="image" src="../../static/alipay.png" mode=""></image>
				<view class="text">
					<navigator url="/pages/user/bind-alipay" hover-class="none">
						<view style="margin-bottom: 20upx;">{{this.form.name?this.form.name:'支付宝'}}</view>
						<view>{{this.form.account?this.form.account:'还没有添加支付宝账号，请点击添加'}}</view>
					</navigator>
				</view>
				<uni-icons type="arrowright" size="24" color="#CCCCCC" style="margin-left: auto;"></uni-icons>
			</view>

			<view class="withdraw-input-wrapper">
				<input class="input" type="text" v-model="form.money" :placeholder="`请输入提现金额,当前可提取余额为${money}元`" />
			</view>
			<view class="withdraw-button-wrapper">
				<button class="btn" type="default" @tap="submit">确认提取</button>
			</view>
		</view>
		<view class="block remind-wrapper">
			<view class="title">
				重要提醒
			</view>
			<view class="li">
				1.当天可提现的最高金额为100元。
			</view>
			<view class="li">
				2.单笔提现金额最低30元起。
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					account: "",
					name: "",
					money: undefined,
				}
			}
		},
		onShow() {
			uni.$emit("refresh_userinfo");
			this.form.account = this.$store.state.user.alipay
			this.form.name = this.$store.state.user.alipay_name
			this.money = this.$store.state.user.money
		},
		methods: {
			submit() {
				if (this.$verified.required(this.form.account,"请选择支付宝账户")
				&&this.$verified.required(this.form.name,"请选择支付宝账户")
				&&this.$verified.required(this.form.money,"请输入您要提取的金额")) {
					this.$http.post({
						url: "/withdraw/create",
						data: this.form,
						success: (res) => {
							console.log(res)
							uni.showModal({
								title: "提现",
								content: "提交成功，平台将于三个工作日之内为您处理",
								success: (res) => {
									if (res.confirm) {
										uni.navigateBack()
									}
								}
							})
						}
					})
				}
			}

		}
	}
</script>

<style lang="scss" scoped>
	.withdraw {
		position: relative;
		overflow: hidden;
	}

	.header-bg {
		background: $primary-color;
		height: 100upx;
		position: absolute;
		top: 0;
		width: 100%;
	}

	.block {
		background: white;
		border-radius: 20upx;
		margin: 20upx;
		padding: 20upx;
		position: relative;
		z-index: 1;
	}

	.account {
		display: flex;
		background: #eeeeee;
		padding: 20upx;
		align-items: center;
		border-radius: 10upx;
		margin: 10upx 0;

		.image {
			width: 100upx;
			height: 100upx;
		}

		.text {
			font-size: 24upx;
			color: #999;
			margin-left: 50upx;
		}
	}

	.withdraw-input-wrapper {
		margin-top: 40upx;
	}

	.input {
		background: #eeeeee;
		padding: 20upx;
		font-size: 24upx;
		border-radius: 10upx;
	}

	.withdraw-button-wrapper {
		margin-top: 40upx;

		.btn {
			font-size: 32upx;
			background: $primary-color;
			color: white;
		}

	}

	.remind-wrapper {
		.title {
			font-size: 30upx;
			border-bottom: #999999 solid 2upx;
			width: 60%;
			margin: auto;
			text-align: center;
			padding: 20upx;
			margin-bottom: 40upx;
			color: #999999;
		}

		.li {
			font-size: 24upx;
			color: #999999;
			margin-bottom: 20upx;
			margin-left: 50upx;
		}
	}
</style>
