<template>
	<view class="withdraw">
		<mNavbar title="钱包提现" :leftClick="leftClick" />
		<view class="banner" />

		<view class="b-relative center font-m">
			<image src="/static/ms/1120.jpg" />
			<view class="title" style="position: absolute; top: 40rpx; left: 40rpx">
				<view style="line-height: 40rpx; font-size: 28rpx">账号余额</view>
				<view style="line-height: 60rpx; font-size: 40rpx">￥{{ userInfo.price }}</view>
			</view>
			
			<!-- <view class="title" style="position: absolute; top: 0; left: 0;
			width: 100%;height: 100%;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			gap: 50rpx;">
				<view style="line-height: 40rpx; font-size: 38rpx">账号余额</view>
				<view style="line-height: 60rpx; font-size: 50rpx">￥{{ userInfo.price }}</view>
			</view> -->
		</view>

		<view class="from-body">
			<view>我要提现</view>

			<view class="money">
				<van-cell-group inset>
					<van-field type="number" v-model="form.price" placeholder="请输入提现金额"
						style="background-color: #F5F5F5; margin: 10rpx 0px; border-radius: 20px;" />
					<van-field v-model="form.bank" placeholder="请输入开户行"
						style="background-color: #F5F5F5; margin: 10rpx 0px; border-radius: 20px;" />
					<van-field v-model="form.card" placeholder="请输入卡号"
						style="background-color: #F5F5F5; margin: 10rpx 0px; border-radius: 20px;" />
				</van-cell-group>
			</view>
			
			<view v-html="withdrawalStatement" class="withdrawal-statement"></view>
		</view>

		<view class="recharge">
			<view @click="withdraw" class="btn">
				立即提现
			</view>
		</view>
	</view>
</template>

<script>
	import mNavbar from '@/components/base/m-navbar.vue'
	export default {
		components: {
			mNavbar
		},
		data() {
			return {
				withdrawalStatement: '', //充值说明
				form : {
					type: 1,
					price: undefined,
					bank: '',
					card: ''
				},
				userInfo: {},
			}
		},
		onShow() {
			this.getConfig()
			this.getUserInfo()
			this.getTenRealName()
		},
		methods: {
			leftClick() { //返回分销代理
				uni.navigateTo({
					url: '/pages/mine/distribution'
				})
			}, 
			getConfig() { //获取配置信息
				this.$api('getConfig', {}, res => {
					if (res.code == 200) {
						res.result.forEach(item => {
							if (item.keyValue === 'withdraw') {
								this.withdrawalStatement = item.content
							}
						})
					}
				})
			},
			withdraw() { //立即提现
				let isOk = this.parameterVerification();
				if(isOk && !isOk.auth){
					return uni.showToast({
						title : isOk.title,
						icon : 'none'
					})
				}
				this.$api('recharge', this.form, res => {
					if (res.code == 200) {
						uni.showToast({
							title: '提现成功',
							icon: 'none'
						})
						this.getUserInfo()
					}
				})
			},
			getUserInfo() { //获取用户信息
				this.$api('getUserInfo', {}, res => {
					if (res.code == 200) {
						this.userInfo = res.result;
					}
				})
			},
			getTenRealName(){		//获取技师实名认证
				this.$api('getTenRealName', {}, res => {
					if (res.code == 200) {
						let result = res.result;
						if(result && result.bank && result.card){
							this.form.bank = result.bank
							this.form.card = result.card
						}
					}
				})
			},
			parameterVerification(){		//验证用户参数合法性
				let { price , bank , card } = this.form
				if(!price){
					return { title : '请填写提现金额' , auth : false }
				}else if(price <= 0){
					return { title : '提现金额必须大于0' , auth : false }
				}else if(price > this.userInfo.price){
					return { title : '提现金额大于余额' , auth : false }
				}else if(bank.trim() == ''){
					return { title : '请填写开户行' , auth : false }
				}else if(card.trim() == ''){
					return { title : '请填写卡号' , auth : false }
				}
				return { title : '验证通过' , auth : true }
			}
		}
	}
</script>

<style lang="scss" scoped>
	.withdraw {
		.content {
			padding-bottom: 60px;
		}

		body {
			background-color: #fff;
		}

		.banner {
			width: 100vw;
			height: 256rpx;
			background: rgba(#ecb978, 0.2);
		}

		.center {
			width: 710rpx;
			height: 316rpx;
			margin: -204rpx auto 0;
		}

		.center image {
			width: 710rpx;
			height: 316rpx;
			border-radius: 12rpx;
		}

		.font-m {
			font-family: PingFang SC, PingFang SC-Bold;
			font-weight: 700;
			text-align: left;
			color: #ffffff;
			text-shadow: 0 4rpx 6rpx 0 rgba(#ecb978, 0.81);
		}

		.item-line input {
			width: 456rpx;
			height: 60rpx;
			line-height: 60rpx;
			background: #f5f5f5;
			border-radius: 12rpx;
			font-size: 24rpx;
			font-family: PingFang SC, PingFang SC-Medium;
			font-weight: 500;
			text-align: left;
			color: #939393;
			padding: 0 20rpx;
		}



		.from-body {
			padding: 40rpx 20rpx;
			font-size: 28rpx;
			text-align: left;
			color: #333333;
		}


		.top-label {
			position: relative;
			width: 96%;
			margin-left: 2%;
			height: 200rpx;
			background-image: url(/static/ms/cz.png);
			background-repeat: no-repeat;
			background-size: 100% 100%;
			overflow: hidden;
			border-radius: 10px;
			margin-top: 20rpx;
		}


		.top-label-box {
			position: relative;
			height: 100%;
			padding-left: 35rpx;
			box-sizing: border-box;
		}

		.top-label-box .activeLabel {
			position: absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			background: url('../../static/ms/select.png');
			background-repeat: no-repeat;
			background-size: 100% 100%;
		}

		.top-label-box-one {
			display: flex;
			align-items: center;
		}

		.top-label-box-two {
			margin-left: 18rpx;
			font-size: 12px;
			padding: 6rpx 8rpx;
			background-color: #EBCB85;
			border-bottom-left-radius: 10px;
			border-top-right-radius: 10px;
		}

		.top-label-box-tag {
			position: absolute;
			border: 1px solid;
			font-size: 12px;
			padding: 6rpx 10rpx;
			color: #fff;
			background-color: #24CC80;
			top: -1px;
			right: 0px;
			border-bottom-left-radius: 10px;
		}

		.money {
			margin: 20rpx 0rpx;
		}

		.money .van-cell-group--inset {
			margin: 0;
		}

		.money .van-field {
			padding: auto 0rpx;
			margin-bottom: 30rpx !important;
		}

		.recharge {
			position: fixed;
			display: flex;
			justify-content: center;
			align-items: center;
			left: 0;
			bottom: 0;
			width: 750rpx;
			height: 100rpx;
			background: white;
		}

		.recharge .btn {
			width: 85%;
			height: 80rpx;
			border-radius: 40rpx;
			color: $uni-color;
			text-align: center;
			line-height: 80rpx;
			font-size: 28rpx;
			background: linear-gradient(178deg, #ffe6ed, #ecb978);
		}

		@media all and (min-width: 961px) {
			.recharge {
				left: 50% !important;
				transform: translateX(-50%);
			}
		}
	}
</style>